ss
网络
用法
ss -tulpn在 Linux 上列出已打开套接字的现代做法,是 netstat 的接班人,在连接很多的机器上快得多;注意 `-p` 只有以 root 运行时才显示占用进程。
常用选项
| 选项 | 含义 |
|---|---|
| -t / -u | TCP / UDP sockets. |
| -l | Listening sockets only. |
| -n | Numeric ports, no /etc/services lookup. |
| -p | Show the owning process. Needs root to see processes that are not yours. |
| -a | Every socket, listening or not. |
| state established | Filter by state, written after the flags. |
| -s | A summary count of sockets per protocol. |
示例
ss -tulpnEvery listening TCP and UDP port with the process behind it.
ss -tn state establishedOnly the connections that are actually carrying traffic.
ss -tn "( dport = :443 )"Outgoing HTTPS connections only.
连不上的时候,这些能把范围缩小——是名字解析不了、没有路由,还是端口被挡。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. ss 是做什么的?
在 Linux 上列出已打开套接字的现代做法,是 netstat 的接班人,在连接很多的机器上快得多;注意 `-p` 只有以 root 运行时才显示占用进程。
Q. 怎么写?
ss -tulpn —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 7 个,完整列表在 man ss。这条命令属于网络。
相关命令
man 手册: man ss