linux中netstat和ss的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11763376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 13:59:58  来源:igfitidea点击:

difference between netstat and ss in linux?

linuxsocketsnetstat

提问by daehee

In linux, netstat command tells us information of active sockets in system.

在 linux 中,netstat 命令告诉我们系统中活动套接字的信息。

I understand that netstatuses /proc/net/tcpto acquire the system network information.

据我所知,netstat用于/proc/net/tcp获取系统网络信息。

Since netstatman page says that netstat is obsolete, so we should use 'ss'.

由于netstat手册页说 netstat 已过时,所以我们应该使用 'ss'。

NOTE
   This program is obsolete.  Replacement for netstat is ss.   Replacement
   for  netstat -r is ip route.  Replacement for netstat -i is ip -s link.
   Replacement for netstat -g is ip maddr.

I have discovered that ssperforms similar functionality but it does not use /proc/net/tcpto acquire system network information.

我发现它ss执行类似的功能,但它不 /proc/net/tcp用于获取系统网络信息。

Now I am curious how ssgets system network socket information?

现在我很好奇如何ss获取系统网络套接字信息?

采纳答案by ggiroux

It gets them from kernel space directly using Netlinkwhich uses the classic socketsAPI.

它使用使用经典套接字API 的Netlink直接从内核空间获取它们。

回答by Mr.Cool

ssis included in iproute2 package and is the substitute of the netstat. ssis used to dump socket statistics. It shows information similar to netstat. It can display more TCP and state information than other tools. It is a new, incredibly useful and faster (compared to netstat) tool for tracking TCP connections and sockets.

ss包含在 iproute2 包中,是netstat. ss用于转储套接字统计信息。它显示的信息类似于netstat。它可以显示比其他工具更多的 TCP 和状态信息。它是一种新的、非常有用且速度更快(与 netstat 相比)的工具,用于跟踪 TCP 连接和套接字。

回答by Mahesh Neelakanta

Check out the source for ss:

查看ss的来源:

https://github.com/shemminger/iproute2/blob/master/misc/ss.c

https://github.com/shemminger/iproute2/blob/master/misc/ss.c

Basically it directly queries the kernel and can respond much faster that netstat.

基本上它直接查询内核并且可以比netstat更快地响应。

回答by prosti

ssis a utility used to investigate sockets in Linux and Unix systems. It shows information similar to netstatand able to dump socket statistics.

ss是用于研究 Linux 和 Unix 系统中的套接字的实用程序。它显示类似于netstat并能够转储套接字统计信息的信息。

But netstatcannot be replaced full by ss. Some netstatcommands correspond better to ipcommand.

netstat不能完全替换为ss。有些netstat命令更符合ip命令。

    $ netstat -r   replaced by  $ ip route
    $ netstat -i   replaced by  $ ip -s lin
    $ netstat -g   replaced by  $ ip maddr

I would say the "older" netstatcommand can be replaced with both ssand ipcommands.

我会说“旧”netstat命令可以同时替换为ssip命令。

回答by int_ua

I've made a comparison table (in Google Docs)(light HTML link) for converting between netstatand ssarguments. It's too big to include and update it here.

我制作了一个比较表(在 Google Docs 中)轻量级 HTML 链接)用于在netstatss参数之间进行转换。它太大了,无法在此处包含和更新。

google doc screenshot

谷歌文档截图

The short version of difference between short arguments is:

短参数之间差异的简短版本是:

Arguments that require attention: r N i g M W T v C F c A U 2 f

需要注意的参数: r N i g M W T v C F c A U 2 f

Arguments that are safe to leave as is: h V l a n Z s p e o 4 6 x t u S w

可以安全离开的参数: h V l a n Z s p e o 4 6 x t u S w