Linux网络状态工具ss,代替netstat
Linux ss 大约 7119 字ss
是Socket Statistics的缩写,是iproute
工具集中的一员。
天下武功唯快不破。ss快的秘诀在于,它利用到了TCP协议栈中tcp_diag。tcp_diag是一个用于分析统计的模块,可以获得Linux 内核中第一手的信息,这就确保了ss的快捷高效。当然,如果你的系统中没有tcp_diag,ss也可以正常运行,只是效率会变得稍慢。(但仍然比 netstat要快。)
查看是否安装
rpm -qf /usr/sbin/ss
或:
rpm -q iproute
输出:
iproute-2.6.32-45.el6.x86_64
安装
如果无法使用ss
命令,需安装iproute
,一般现在Linux
系统默认安装了iproute
,故可以直接使用ss
。
yum install iproute iproute-doc
iproute与net-tool对比
用途 | net-tool | iproute2 |
---|---|---|
地址和链路配置 | ifconfig | ip addr, ip link |
路由表 | route | ip route |
邻居 | arp | ip neigh |
VLAN | vconfig | ip link |
隧道 | iptunnel | ip tunnel |
组播 | ipmaddr | ip maddr |
统计 | netstat | ss |
ss 命令
帮助文档
ss -h
获取 ss 版本号
ss -V
查看当前服务器的网络连接统计
ss -s
输出:
[root@root ~]$ ss -s
Total: 953 (kernel 1080)
TCP: 754 (estab 722, closed 4, orphaned 0, synrecv 0, timewait 0/0), ports 775
Transport Total IP IPv6
* 1080 - -
RAW 0 0 0
UDP 21 21 0
TCP 750 750 0
INET 771 771 0
FRAG 0 0 0
查看所有打开的网络端口
- 使用
-l
参数。
ss -l
输出:
[root@root ~]$ ss -l
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:rquotad *:*
LISTEN 0 100 *:8109 *:*
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 50 *:20880 *:*
LISTEN 0 50 *:20881 *:*
LISTEN 0 50 *:20882 *:*
LISTEN 0 50 *:20883 *:*
LISTEN 0 1 127.0.0.1:18005 *:*
LISTEN 0 50 *:20885 *:*
LISTEN 0 128 *:44565 *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 50 *:16377 *:*
LISTEN 0 500 *:8090 *:*
LISTEN 0 64 *:64156 *:*
LISTEN 0 128 *:59231 *:*
LISTEN 0 50 *:24384 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 128 *:9090 *:*
LISTEN 0 128 *:35107 *:*
LISTEN 0 1 127.0.0.1:8006 *:*
LISTEN 0 500 *:7080 *:*
LISTEN 0 100 *:8009 *:*
LISTEN 0 50 *:2346 *:*
LISTEN 0 900 *:3306 *:*
- 使用
-pl
参数,显示具体进程名称,类似:("nginx",1673,6)
ss -pl
输出:
[root@root ~]$ ss -pl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:rquotad *:*
LISTEN 0 100 *:8109 *:* users:(("java",60344,55))
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 50 *:20880 *:* users:(("java",60344,239))
LISTEN 0 50 *:20881 *:* users:(("java",15677,140))
LISTEN 0 50 *:20882 *:* users:(("java",17575,139))
LISTEN 0 50 *:20883 *:* users:(("java",28128,117))
LISTEN 0 1 127.0.0.1:18005 *:* users:(("java",60484,77))
LISTEN 0 50 *:20885 *:* users:(("java",60484,242))
LISTEN 0 128 *:44565 *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 50 *:16377 *:* users:(("java",60484,19))
LISTEN 0 500 *:8090 *:* users:(("java",60484,54))
LISTEN 0 64 *:64156 *:*
LISTEN 0 128 *:59231 *:*
LISTEN 0 50 *:24384 *:* users:(("java",60484,21))
LISTEN 0 64 *:2049 *:*
LISTEN 0 128 *:9090 *:*
LISTEN 0 128 *:35107 *:*
LISTEN 0 1 127.0.0.1:8006 *:* users:(("java",60344,74))
LISTEN 0 500 *:7080 *:* users:(("java",60344,50))
LISTEN 0 100 *:8009 *:* users:(("java",60484,58))
LISTEN 0 50 *:2346 *:* users:(("java",60484,20))
LISTEN 0 900 *:3306 *:*
LISTEN 0 128 *:https *:* users:(("nginx",1673,6),("nginx",958,6))
LISTEN 0 128 :::http :::* users:(("nginx",1673,8),("nginx",958,8))
查看服务器上所有的 socket 连接
- 查看所有
socket
连接
ss -a
输出:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 127.0.0.1:18005 *:*
LISTEN 0 50 *:20885 *:*
LISTEN 0 128 *:44565 *:*
LISTEN 0 1 127.0.0.1:8006 *:*
LISTEN 0 500 *:7080 *:*
LISTEN 0 900 *:3306 *:*
ESTAB 0 0 10.95.197.161:28892 10.95.216.9:7005
ESTAB 0 0 10.95.197.161:45596 10.95.216.116:7070
ESTAB 0 0 10.95.197.161:22437 10.95.216.10:7000
ESTAB 0 0 10.95.197.161:57115 10.95.216.9:7000
ESTAB 0 0 10.95.197.161:22185 10.95.216.10:7000
ESTAB 0 0 10.95.197.161:60830 10.95.216.10:7001
CLOSE-WAIT 61 0 10.95.197.161:12398 123.103.23.214:ftp
CLOSE-WAIT 61 0 10.95.197.161:54971 123.103.23.214:ftp
CLOSE-WAIT 61 0 10.95.197.161:56481 123.103.23.214:ftp
- 查看连接本机22端口
ss -n src :22
- 查看远程机器连接情况
ss -n dst 192.168.100.100
- 只查看TCP sockets,tcp all
ss -ta
- 只查看UDP sockets,udp all
ss -ua
- 只查看RAW sockets,raw all
ss -wa
- 只查看UNIX sockets,unix all
ss -xa
阅读 1261 · 发布于 2019-09-04
————        END        ————
扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Spring Boot设置cookie和session过期时间阅读 3549
-
Nginx配置之隐藏版本号阅读 505
-
MySQL server has gone away阅读 542
-
Android使用tools schemas预览UI阅读 505
-
软考-系统架构设计师:数据库故障与恢复阅读 378
-
VMware Workstation与Hyper-V不兼容阅读 1590
-
Linux Shell符号及变量阅读 662
-
设计模式之策略模式阅读 467
-
Git命令之查看及设置用户名邮箱阅读 1045
-
Nginx编译安装时提示the HTTP gzip module requires the zlib library阅读 2215