linux 查看tcp状态占用情况、ip端口占用情况

1、查询各个ip对应的连接数正序 

netstat -nat|grep ":8899"|awk '{print $5}' |awk -F: '{print $1}' | sort| uniq -c|sort -n
  [root@iZwz456d64eewvewbg5bi2Z ~]# netstat -nat|grep ":8899"|awk '{print $5}' |awk -F: '{print $1}' | sort| uniq -c|sort -n 
    224 14.104.202.191
    226 119.140.73.131
    252 121.32.71.137
    252 221.231.194.95
    274 118.182.18.4
    275 122.97.93.87
    286 221.213.62.3
    294 116.26.172.249
    313 221.11.91.244
    321 60.209.128.114
    339 121.22.18.50
    380 220.173.207.121
    402 112.12.35.78
    407 119.0.204.19
    542 116.26.174.124
    570 210.3.55.66
    669 113.248.136.138

2、查找请求数前10的ip

netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n10

netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n10

 

3、查询各个TCP连接状态所占用的连接数 

netstat -n | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
[root@iZ91064evebpg44565bykii2cZ ~]# netstat -n | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
LAST_ACK 1
SYN_RECV 17
ESTABLISHED 41828
FIN_WAIT1 303
FIN_WAIT2 1737
CLOSING 3
TIME_WAIT 45

4、指定ip查询连接数 

netstat -na | grep <需要查询ip> | wc -l
[root@iZwz910nd64evebpg5bi2cZ ~]# netstat -na | grep 114.105.35.50 | wc -l
8

你可能感兴趣的:(linux,linux,运维)