[Linux] netstat 檢查主機連線 – 計算統計連線量

指令

基本查看 All+Numeric:

netstat -antp

過濾出80 Port

netstat -an | grep :80

計算80 Port總連線數

netstat -na | grep 80 | wc -l

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

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

列出每個 ip 建立的 ESTABLISHED 連線數量:

netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

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

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

參數表

-r, --route              display routing table
-i, --interfaces         display interface table
-g, --groups             display multicast group memberships
-s, --statistics         display networking statistics (like SNMP)
-M, --masquerade         display masqueraded connections

-v, --verbose            be verbose
-W, --wide               don't truncate IP addresses
-n, --numeric            don't resolve names
--numeric-hosts          don't resolve host names
--numeric-ports          don't resolve port names
--numeric-users          don't resolve user names
-N, --symbolic           resolve hardware names
-e, --extend             display other/more information
-p, --programs           display PID/Program name for sockets
-c, --continuous         continuous listing

-l, --listening          display listening server sockets
-a, --all, --listening   display all sockets (default: connected)
-o, --timers             display timers
-F, --fib                display Forwarding Information Base (default)
-C, --cache              display routing cache instead of FIB   

<Socket>={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
<AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet


Reference: https://www.phpini.com/linux/netstat-check-connections

Leave a Reply

Your email address will not be published. Required fields are marked *