筆記:netstat指令


顯示路由表

netstat -r

顯示網路裝置設定

netstat -i
netstat -an #
netstat -antp|wc -l #

檢測本機使用的port

netstat -an | grep LISTEN | grep ":21" # ftp
netstat -an | grep LISTEN | grep ":22" # ssh
netstat -an | grep LISTEN | grep ":25"  # smtp mail service
netstat -an | grep LISTEN | grep ":25"  # pop3 mail service

netstat -an | grep LISTEN | grep ":80" # www
netstat -an | grep LISTEN | grep ":8080"

計算每一個 ip 在主機上建立的連線數量

netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n

列出從 TCP 或 UDP 連線到主機的 ip 的數量

netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n

列出每個 ip 建立的 port 80 連線數量

netstat -plan|grep :80|awk {’print $5′}|cut -d: -f 1|sort|uniq -c|sort -nk 1

列出連線的協定及使用的應用程式

netstat -alp

列出完整的 URL 位址

netstat -tup -W

這個指令可以驗證 MySQL 是否是透過 UNIX domain socket 連線

netstat -lx | grep -i sql

參考資料
http://aries.dyu.edu.tw/~tarng/dyu_c.c/netstat.htm
https://www.phpini.com/linux/netstat-check-connections
https://gist.github.com/m41039/c054ebd18fc53242db814b87b9a1164c

留言