加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (https://www.0577zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

Linux 运维:使用 ss 命令代替 netstat

发布时间:2019-07-12 14:53:25 所属栏目:Windows 来源:佚名
导读:副标题#e# 在运维和管理 Linux 服务器的时候,我们最常用的一个命令就是 netstat,我常用这个命令来查看当前服务器上有哪些进程正在侦听端口,主要用来诊断网络服务的工作状态。 不过,最近有一次安装好一个 Ubuntu 发型版,发现默认没有安装 netstat,觉得

当然,也有一种理由是老外提出来的,说 ss 这个命令的名字不好,其实 ss 可能是 socket statistics 的意思,缩写以后,竟然只有两个字母,不太好联想,不像 netstat 那么直观。当然这是我的解释,不是老外抱怨的理由,他们抱怨的是,每每提及 ss,他们会联想起希特勒!是不是匪夷所思,我是 80 后,我这个年代的人,对这个都没有什么印象,关键我们用中文为主,估计大家看到 ss 最多联想到梯子,怎么都不会想到希特勒。这个大纳粹有一个武装部队,以前叫党卫队特别机动部队,后来改名叫武装党卫队。它的德语简称正是SS。

不说闲话了,说说几个参数,a 参数是显示所有的意思,t 参数意思是显示 TCP 协议的,l 代表正在 LISTENING 状态的,p 代表进程信息。从上面的表里,我们看到 p 参数打印的信息,组织得不如 netstat 精炼。但是更为完善一点,显示了进程名字和 PID 以及 FD。但是因为用了两重小括号,key/value 的格式,再加引号,看起来脏乱差。当然,我们可以用一些命令去格式化它,不过还是太麻烦了。

更换的原因是什么?

这可能是我最为好奇的事情。不过网上我搜索了不少的资料,基本都语焉不详。这也有点让我有点无奈。

大体上,我们能看出来,主要是 net-tools 这个包,将要被 iproute 这个包给替换。理由大概是,1,这个包太老了,2,这个包不支持很多内核新的特性(但是没有说是哪些特性),界面不够优化使用困难(对命令行不友好),3,net-tools 里面的 ifconfig 确实缺点多多,4,未来不再想维护 net-tools 了。

Luk Claes and me, as the current maintainers of net-tools, we’ve been thinking about it’s future. Net-tools has been a core part of Debian and any other linux based distro for many years, but it’s showing its age.

It doesnt support many of the modern features of the linux kernel, the interface is far from optimal and difficult to use in automatisation, and also, it hasn’t got much love in the last years.

On the other side, the iproute suite, introduced around the 2.2 kernel line, has both a much better and consistent interface, is more powerful, and is almost ten years old, so nobody would say it’s untested.

Hence, our plans are to replace net-tools completely with iproute, maybe leading the route for other distributions to follow. Of course, most people and tools use and remember the venerable old interface, so the first step would be to write wrappers, trying to be compatible with net-tools.

At the same time, we believe that most packages using net-tools should be patched to use iproute instead, while others can continue using the wrappers for some time. The ifupdown package is obviously the first candidate, but it seems that a version using iproute has been available in experimental since 2007.

也有从 原理层面 分析的:现在的 netstat 和 ifconfig 命令,都是通过读写 /proc 目录下的虚拟文件来完成任务的,这个东西在小型业务系统上,是没问题的,但是在大规模系统里,可能会伤害系统的性能之类的。相比之下,ss 和 ip 两个命令,使用的是 Linux 内核的 netlink sockets 特性。有着根本上的不同。虽然,老命令也可以用新原理重写,但是其实并没有人那么做,主要因为不同程序员团体的一些 political issues ,大家意见不合……

当然,深层次的还有,我们使用这样的调试命令,本质上还是希望获知内核的状态的,其实,内核已经改变了 networking 模块的整个原理,另一方面我还要求命令像从前那样去展示信息,展示层面的格式和真实原理已经背离,所以,从长远看,替代这两个命令才是必然。

结论

咱们这些做技术的,也还是要与时俱进比较好,虽然,以前的那些命令熟悉,好用,手到擒来,甚至无法忘记,但是新的还是要保持学习。很多发型版已经默认不带有 net-tools 包了,虽然仍然可以手动安装回来,但是,这背后的态度已经很明确了。另一方面,我们做技术,也要谨防自己的大脑僵化,还是要保持对新事物的好奇心和热情。

【编辑推荐】

  1. 算法巨大突破!AI神经网络模拟量子系统
  2. 从Windows到鸿蒙——操作系统的前世与今生
  3. 鸿蒙OS内测系统体验曝光:界面与EMUI明显不同、简洁流畅
  4. 华为鸿蒙系统进入“冲刺”阶段:建立生态体系将是最大难点
  5. 微软专利:新一代Windows系统曝光,兼容安卓!
【责任编辑:张燕妮 TEL:(010)68476606】
点赞 0

(编辑:温州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读