ss 是 Socket Statistics 的缩写。ss 命令可以用来获取 socket 统计信息,它显示的内容和 netstat 类似。但 ss 的优势在于它能够显示更多更详细的有关 TCP 和连接状态的信息,而且比 netstat 更快。当服务器的 socket 连接数量变得非常大时,无论是使用 netstat 命令还是直接 cat /proc/net/tcp,执行速度都会很慢。ss 命令利用到了 TCP 协议栈中 tcp_diag。tcp_diag 是一个用于分析统计的模块,可以获得 Linux 内核中第一手的信息,因此 ss 命令的性能会好很多。
unix domain sockets,与 -f 选项相同-n,--numeric 不解析服务的名称,如 "22" 端口不会显示成 "ssh"-l,--listening 只显示处于监听状态的端口-p,--processes 显示监听端口的进程(Ubuntu 上需要 sudo)-a,--all 对 TCP 协议来说,既包含监听的端口,也包含建立的连接-r,--resolve 把 IP 解释为域名,把端口号解释为协议名称
如果不添加选项 ss 命令默认输出所有建立的连接(不包含监听的端口),包括 tcp,udp,and 三种类型的连接:
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L3303R0-1G52.gif)
$ ss -tnl
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L34V610-21O1.gif)
$ ss -tlr
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L3D9340-35494.gif)
$ ss -tlp
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L3WY30-46405.gif)
$ ss -tlp |
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L3b4630-51204.gif)
$ ss -tna
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L4020260-EC5.gif)
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L4221950-ND0.gif)
$ ss -s
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L4423630-WQ7.gif)
$ ss dst ...:
$ ss src ...:
注意,需要对尖括号使用转义符):
$ ss -tunl sport lt -tunl sport <
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L45960Z-b056.gif)
</tr>
<tr>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">connected</td>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">列出除了 listening 和 closing 之外的所有 TCP 状态。</td>
</tr>
<tr>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">synchronized</td>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">列出除了 syn-sent 之外的所有 TCP 状态。</td>
</tr>
<tr>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">bucket</td>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">列出 maintained 的状态,如:time-wait 和 syn-recv。</td>
</tr>
<tr>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">big</td>
<td><span style="font-family: Microsoft YaHei; font-size: 15px">列出和 bucket 相反的状态。</td>
</tr>
$ ss - state filter
$ ss - state filter
$ ss - state listening
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L4S1050-101596.gif)
$ ss -4n state listening
$ ss -4n state listening ( dport = :-4n state listening
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L4bHZ-113493.gif)
$ ss state established
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L5311D0-123N1.gif)
$ ss state all dport = :
![linux ss 命令](http://img28.aspzz.cn/uploads/allimg/c210125/161154L54152P-1345B.gif)
$ ss state fin-- dst ./
(编辑:温州站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|