linux命令大全之ss命令详解(获取socket统计信息)(2)
实例3:列出所有打开的网络连接端口
命令:ss -l
输出:
[root@localhost ~]# ss -l
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 127.0.0.1:smux *:*
0 0 *:3690 *:*
0 0 *:ssh *:*
[root@localhost ~]#
实例4:查看进程使用的socket
命令:ss -pl
输出:
[root@localhost ~]# ss -pl
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 127.0.0.1:smux *:* users:(("snmpd",2716,8))
0 0 *:3690 *:* users:(("svnserve",3590,3))
0 0 *:ssh *:* users:(("sshd",2735,3))
[root@localhost ~]#
实例5:找出打开套接字/端口应用程序
命令:ss -lp | grep 3306
输出:
[root@localhost ~]# ss -lp|grep 1935
0 0 *:1935 *:* users:(("fmsedge",2913,18))
0 0 127.0.0.1:19350 *:* users:(("fmsedge",2913,17))
[root@localhost ~]# ss -lp|grep 3306
0 0 *:3306 *:* users:(("mysqld",2871,10))
[root@localhost ~]#
实例6:显示所有UDP Sockets
命令:ss -u -a
输出:
[root@localhost ~]# ss -u -a
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 127.0.0.1:syslog *:*
UNCONN 0 0 *:snmp *:*
ESTAB 0 0 192.168.120.203:39641 10.58.119.119:domain
[root@localhost ~]#
实例7:显示所有状态为established的SMTP连接
命令:ss -o state established '( dport = :smtp or sport = :smtp )'
输出:
[root@localhost ~]# ss -o state established '( dport = :smtp or sport = :smtp )'
Recv-Q Send-Q Local Address:Port Peer Address:Port
[root@localhost ~]#
实例8:显示所有状态为Established的HTTP连接
命令:ss -o state established '( dport = :http or sport = :http )'
输出:
[root@localhost ~]# ss -o state established '( dport = :http or sport = :http )'
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 75.126.153.214:2164 192.168.10.42:http
[root@localhost ~]#
实例9:列举出处于 FIN-WAIT-1状态的源端口为 80或者 443,目标网络为 193.233.7/24所有 tcp套接字
命令:ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 193.233.7/24
实例10:用TCP 状态过滤Sockets:
命令:
ss -4 state FILTER-NAME-HERE
ss -6 state FILTER-NAME-HERE
输出:
[root@localhost ~]#ss -4 state closing
Recv-Q Send-Q Local Address:Port Peer Address:Port
1 11094 75.126.153.214:http 192.168.10.42:4669
说明:
FILTER-NAME-HERE 可以代表以下任何一个:
established
syn-sent
syn-recv
fin-wait-1
fin-wait-2
time-wait
closed
close-wait
last-ack
listen
closing
all : 所有以上状态
connected : 除了listen and closed的所有状态
synchronized :所有已连接的状态除了syn-sent
bucket : 显示状态为maintained as minisockets,如:time-wait和syn-recv.
big : 和bucket相反.