Linux之netstat
1.查看哪些IP连接本机
$ netstat -an
2.查看TCP连接数
1).统计80端口连接数
$ netstat -nat|grep -i "80"|wc -l
2).统计httpd协议连接数
$ ps -ef|grep httpd|wc -l
3).统计已连接上的,状态为“established”
$ netstat -na|grep ESTABLISHED|wc -l
4).查出哪个IP地址连接最多
$ netstat -na|grep ESTABLISHED|awk {print $5}|awk -F: {print $1}|sort|uniq -c|sort -r +0n
#将其查封
$ netstat -na|grep SYN|awk {print $5}|awk -F: {print $1}|sort|uniq -c|sort -r +0n
3.查看正在监听状态的端口
1).netstat -nupl
# n表示用数字形式显示端口号,u,表示UDP协议类型,p是程序PID,l表示处于监听状态的;
$ netstat -nupl
2).netstat -ntpl
# n表示用数字形式显示端口号,t,表示TCP协议类型,p是程序PID,l表示处于监听状态的;
$ netstat -ntpl
3).netstat -nuplf | grep 3306
# 这个表示查找处于监听状态的,端口号为3306的进程;
$ netstat -nuplf | grep 3306