此快速参考备忘单提供了各种使用 netstat 命令的方法
端口 80 上的所有连接
$ netstat -anp | grep :80
网络统计帮助
$ netstat -h
netstat -ltunp
netstat -ltn
netstat -lun
netstat -lx
netstat -lt
netstat -lu
netstat -l
netstat -a
netstat -at
netstat -au
netstat -ant
netstat
netstat -tnl
netstat -unl
netstat -i
netstat -ie
netstat -n
netstat -F
netstat -r
netstat -rn
netstat -s
netstat -st
netstat -su
netstat -ltpe
netstat -tp
sudo netstat -nlpt
netstat -nlptue
netstat -M
$ netstat --tcp --numeric
$ netstat -atnp | grep ESTA
$ watch -d -n0 "netstat -atnp | grep ESTA"
$ netstat -anp | grep":"
插入端口号(上图)代替冒号 :
端口
:
$ sudo netstat -aple | grep ntp
你可以用http、smtp代替ntp
http
smtp
ntp
$ netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
$ netstat -tn 2>/dev/null | grep ':80 ' | awk '{print $5}' |sed -e 's/::ffff://' | cut -f1 -d: | sort | uniq -c | sort -rn | head
$ netstat -an |grep :80 |wc -l
$ netstat -antu | grep :80 | grep -v LISTEN | awk '{print $5}'
以下命令将输出服务器上正在发生和正在发生的活动 SYNC_REC 数量。数量应该很低(小于 5)。如果该数字为两位数,则您可能正在遭受 DoS 攻击或被邮件轰炸。
SYNC_REC
5
DoS
$ netstat -n -p|grep SYN_REC | wc -l
$ netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'
与上面的命令一样,该命令也列出了发送 SYN_REC 连接状态的节点的所有唯一 IP 地址
SYN_REC
IP
$ netstat -antu | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
或者
$ netstat -antu | awk '$5 ~ /[0-9]:/{split($5, a, ":"); ips[a[1]]++} END {for (ip in ips) print ips[ip], ip | "sort -k1 -nr"}'
$ netstat -plntu
$ netstat -plnt
$ netstat -an | grep 80 | wc -l
$ netstat -pnut -w | column -t -s $'\t'