为什么ss比netstat快:
netstat是遍历/proc下面每个PID目录,ss直接读/proc/net下面的统计信息。所以ss执行的时候消耗资源以及消耗的时间都比netstat少很多
1:显示socket摘要
参数介绍:
-s, --summary show socket usage summary
-
[root@s5 ~]# ss -s
-
Total: 1081 (kernel 1115)
-
TCP: 871 (estab 602, closed 256, orphaned 0, synrecv 0, timewait 256/0), ports 489
-
-
Transport Total IP IPv6
-
* 1115 - -
-
RAW 0 0 0
-
UDP 2 2 0
-
TCP 615 612 3
-
INET 617 614 3
-
FRAG 0 0 0
2:显示打开的网络端口:
参数介绍:
-l, --listening display listening sockets
-
[root@s5 ~]# ss -l
-
State Recv-Q Send-Q Local Address:Port Peer Address:Port
-
LISTEN 0 1024 127.0.0.1:11211 *:*
-
LISTEN 0 511 *:http *:*
-
LISTEN 0 32 *:ftp *:*
-
LISTEN 0 128 :::ssh :::*
-
LISTEN 0 128 *:ssh *:*
-
LISTEN 0 100 ::1:smtp :::*
-
LISTEN 0 100 127.0.0.1:smtp *:*
-
LISTEN 0 64 :::42942 :::*
-
LISTEN 0 1024 127.0.0.1:12001 *:*
-
LISTEN 0 128 *:10050 *:*
-
LISTEN 0 64 *:62023 *:*
-
LISTEN 0 128 127.0.0.1:9000 *:*
-
LISTEN 0 50 *:3306 *:*
-
[root@s5 ~]#
3:查看进程使用的socket
-p, --processes show process using socket
-
[root@haproxy2 ~]# ss -pl ##显示服务名,不显示相应的端口
-
Recv-Q Send-Q Local Address:Port Peer Address:Port
-
0 128 :::sunrpc :::* users:(("rpcbind",1158,11))
-
0 128 *:sunrpc *:* users:(("rpcbind",1158,8))
-
0 128 :::ssh :::* users:(("sshd",1268,4))
-
0 128 *:ssh *:* users:(("sshd",1268,3))
-
0 100 ::1:smtp :::* users:(("master",1344,13))
-
0 100 127.0.0.1:smtp *:* users:(("master",1344,12))
-
[root@haproxy2 ~]# ss -pl | grep 25
-
[root@haproxy2 ~]# ss -pln | grep 25 ##将服务器名替换为端口
-
0 100 ::1:25 :::* users:(("master",1344,13))
-
0 100 127.0.0.1:25 *:* users:(("master",1344,12))
-
[root@haproxy2 ~]#
5:所有的tcp socket和udp socket
-n, --numeric don't resolve service names
-t, --tcp display only TCP sockets
-u, --udp display only UDP sockets
-
[root@haproxy2 ~]# ss -a -t
-
State Recv-Q Send-Q Local Address:Port Peer Address:Port
-
LISTEN 0 128 :::sunrpc :::*
-
LISTEN 0 128 *:sunrpc *:*
-
LISTEN 0 128 :::ssh :::*
-
LISTEN 0 128 *:ssh *:*
-
LISTEN 0 100 ::1:smtp :::*
-
LISTEN 0 100 127.0.0.1:smtp *:*
-
ESTAB 0 48 192.168.2.222:ssh 192.168.2.164:55804
-
[root@haproxy2 ~]# ss -a -u
-
State Recv-Q Send-Q Local Address:Port Peer Address:Port
-
UNCONN 0 0 *:sunrpc *:*
-
UNCONN 0 0 *:syslog *:*
-
UNCONN 0 0 *:908 *:*
-
UNCONN 0 0 :::sunrpc :::*
-
UNCONN 0 0 :::syslog :::*
-
UNCONN 0 0 :::908 :::*
-
[root@haproxy2 ~]#
6:
-
显示所有已建立的SMTP连接
-
# ss -o state established '( dport = :smtp or sport = :smtp )'
-
显示所有已建立的HTTP连接
-
# ss -o state established '( dport = :http or sport = :http )'
-
7:
8:
9:
10:
阅读(974) | 评论(0) | 转发(0) |