ss命令
ss命令:
another utility to investigate sockets
ss [options] [ FILTER ]
选项:
-t:查看tcp协议相关的链接;
-u:查看udp相关的链接;
-w:查看raw socket相关的链接;
-l:查看监听状态的链接;
-a:查看所有状态的链接;
-n:以数字格式显示;
-p:查看相关的进程及其PID;
-e:查看扩展格式信息;
-m:查看内存用量;
-o:查看计时器信息;
FILTER := [ state TCP-STATE ] [ EXPRESSION ]
TCP状态过滤功能,讲完后的的内容才会理解此处命令;
TCP的常见状态:
LISTEN:监听;
ESTABLISHED:建立的连接;
FIN_WAIT_1:发送断开后等待断开确认;
FIN_WAIT_2:收到断开后确认断开;
SYN_SENT:确认收到断开信号;
SYN_RECV:确认
CLOSED:
EXPRESSION:
dport:目标端口;
sport:源端口;
例如:'(dport=:22 or sport=:22'
]# ss -tan state ESTABLISHED:查看tcp连接状态为ESTABLISHED的信息;
]# ss -tan '( dport = :22 or sport = :22 )':查看tcp连接中源端口为22或目标端口为22的信息;
]# ss -tan state ESTABLISHED:仅查看tcp连接中ESTABLISHED状态的信息;