ss 命令学习
1、统计服务器并发连接数(ss性能 > netstat) time netstat -ant |grep EST|wc -l time ss -o state established | wc -l 为什么ss比netstat快: netstat是遍历/proc下面每个PID目录,ss直接读/proc/net下面的统计信息。所以ss执行的时候消耗资源以及消耗的时间都比netstat少很多 2、 显示本地打开的所有端口 ss -l 3、显示每个进程具体打开的socket ss -pl 看当前机器的11001端口被谁占用了 ss -lp src :11001 4、显示所有tcp socket ss -t -a 5、显示所有的UDP Socekt ss -u -a 6、显示所有已建立的SMTP连接 ss -o state established `( dport = :smtp or sport = :smtp )` 7、显示所有已建立的HTTP连接(包含对外提供的80,以及访问外部的80) ss -o state established `( dport = :http or sport = :http )` 8、显示处在FIN-WAIT-1状态的http、https连接 ss -o state fin-wait-1 '( sport = :http or sport = :https )'
ss常用的state状态: established syn-sent syn-recv fin-wait-1 fin-wait-2 time-wait closed close-wait last-ack listen closing all : All of the above states connected : All the states except for listen and closed synchronized : All the connected states except for syn-sent bucket : Show states, which are maintained as minisockets, i.e. time-wait and syn-recv. big : Opposite to bucket state. established syn-sent syn-recv fin-wait-1 fin-wait-2 time-wait closed close-wait last-ack listen closing all : All of the above states connected : All the states except for listen and closed synchronized : All the connected states except for syn-sent bucket : Show states, which are maintained as minisockets, i.e. time-wait and syn-recv. big : Opposite to bucket state.
9、 找出所有连接X服务器的进程 ss -x src /tmp/.X11-unix/* 10、列出当前socket详细信息: ss -s 11、列出本地哪个进程连接到x server ss -x src /tmp/ X11-unix/* 12、列出来至120.33.31.1,80端口的连接 ss src 120.33.31.1:http ss src 120.33.31.1:80