1.查看指定端口/服务是否正常运行
ss -anp|grep 端口号/服务名
eg:
[root@LNP]~# ss -anp|grep 111
LISTEN 0 128 :::111 :::* users:(("rpcbind",1221,11))
LISTEN 0 128 *:111 *:* users:(("rpcbind",1221,8))
[root@LNP]~# ss -an|grep 111
LISTEN 0 128 :::111 :::*
LISTEN 0 128 *:111 *:*
[root@LNP]~# ss -anp|grep rpcbind
LISTEN 0 128 :::111 :::* users:(("rpcbind",1221,11))
LISTEN 0 128 *:111 *:* users:(("rpcbind",1221,8))
[root@LNP]~# ss -ap|grep rpcbind
LISTEN 0 128 :::sunrpc :::* users:(("rpcbind",1221,11))
LISTEN 0 128 *:sunrpc *:* users:(("rpcbind",1221,8))
加n参数,才能使用端口号进行查询,n表示不转换端口号为TCP/UDP对应的服务名
加p差数,才能使用服务名进行查询,p列出对应的应用名称和进程号
2.查看当前服务器网络连接汇总信息
ss -s
eg:
[root@LNP]~# ss -s
Total: 436 (kernel 437)
TCP: 13 (estab 1, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 8
Transport Total IP IPv6
* 437 - -
RAW 0 0 0
UDP 8 5 3
TCP 13 8 5
INET 21 13 8
FRAG 0 0 0
用做大量socket连接时宏观统计
3.查看当前服务器所有LISTEN状态socket连接
ss -l
eg:
[root@LNP]~# ss -l
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::37829 :::*
LISTEN 0 128 127.0.0.1:cslistener *:*
LISTEN 0 128 :::sunrpc :::*
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 128 *:http *:*
LISTEN 0 128 :::ssh :::*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 128 ::1:ipp :::*
LISTEN 0 100 ::1:smtp :::*
LISTEN 0 100 127.0.0.1:smtp *:*
LISTEN 0 128 *:33850 *:*
4.查看当前服务器所有的socket连接
ss -a
eg:
[root@LNP]~# ss -a
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::37829 :::*
LISTEN 0 128 127.0.0.1:cslistener *:*
LISTEN 0 128 :::sunrpc :::*
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 128 *:http *:*
LISTEN 0 128 :::ssh :::*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 128 ::1:ipp :::*
LISTEN 0 100 ::1:smtp :::*
LISTEN 0 100 127.0.0.1:smtp *:*
LISTEN 0 128 *:33850 *:*
ESTAB 0 52 192.168.217.14:ssh 192.168.217.1:59342
如果只想查看TCP、UDP、RAW、UNIX、DCCP对应的socket,分别用-ta、-ua、-wa、-xa、-da
eg:
[root@LNP]~# ss -ta
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::37829 :::*
LISTEN 0 128 127.0.0.1:cslistener *:*
LISTEN 0 128 :::sunrpc :::*
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 128 *:http *:*
LISTEN 0 128 :::ssh :::*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 128 ::1:ipp :::*
LISTEN 0 100 ::1:smtp :::*
LISTEN 0 100 127.0.0.1:smtp *:*
LISTEN 0 128 *:33850 *:*
ESTAB 0 52 192.168.217.14:ssh 192.168.217.1:59342
[root@LNP]~# ss -ua
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 127.0.0.1:1001 *:*
UNCONN 0 0 *:sunrpc *:*
UNCONN 0 0 *:ipp *:*
UNCONN 0 0 *:33471 *:*
UNCONN 0 0 *:972 *:*
UNCONN 0 0 :::sunrpc :::*
UNCONN 0 0 :::39823 :::*
UNCONN 0 0 :::972 :::*