Linux 監控tcp連接數及狀態
查看tcp連接數狀態
root@pc:~# netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"\t",state[key]}'
SYN_RECV 5
CLOSE_WAIT 1
ESTABLISHED 1013
FIN_WAIT1 19
SYN_SENT 3
TIME_WAIT 131348
統計80端口上有多少個TCP連接
netstat -ant | grep 80 | wc -l
TCP連接中有多少個連接狀態是ESTABLISHED
netstat -ant | grep 80 | grep ESTABLISHED| wc -l
TCP連接中有多少個連接狀態是TIME_WAIT
netstat -ant | grep 80| grep TIME_WAIT| wc -l
TCP連接中有多少個連接狀態是TIME_WAIT (同时列出 IP)
netstat -nat | grep TIME_WAIT | grep ':80' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr