天天看點

Linux netstat檢視端口占用情況

一、使用netstat指令可檢視端口使用情況

(1)  檢視服務端口是否啟用。常用于檢視伺服器程序端口是否啟動

[[email protected] ~]# netstat -nlp |grep 21050

tcp6       0      0 :::21050                :::*                    LISTEN      10859/impalad 

(2) 檢視端口連接配接情況

[[email protected] ~]# netstat -nat|grep -i "21050"    不帶程序号

tcp6       0      0 :::21050                :::*                    LISTEN     

tcp6       0      0 192.168.11.124:21050    192.168.11.126:32474    ESTABLISHED

tcp6       0      0 192.168.11.124:21050    192.168.11.126:64128    ESTABLISHED

[[email protected] ~]#  netstat -natp|grep -i "21050"   帶程序号

tcp6       0      0 :::21050                :::*                    LISTEN      6334/impalad        

tcp6       0      0 192.168.11.126:14792    192.168.11.124:21050    ESTABLISHED 24236/java          

tcp6       0      0 192.168.11.126:32566    192.168.11.124:21050    ESTABLISHED 15111/java 

(3) 統計端口的連接配接數

[[email protected] ~]# netstat -nat|grep -i "21050" |wc -l

63

二、netstat指令help

[[email protected] ~]# netstat --help   檢視指令幫助

usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}

       netstat [-vWnNcaeol] [<Socket> ...]

       netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]

        -r, --route              display routing table

        -I, --interfaces=<Iface> display interface table for <Iface>

        -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    顯示程序号

        -o, --timers             display timers

        -c, --continuous         continuous listing

        -l, --listening          display listening server sockets   服務端listen

        -a, --all                display all sockets (default: connected)   顯示所有sockets

        -F, --fib                display Forwarding Information Base (default)

        -C, --cache              display routing cache instead of FIB

        -Z, --context            display SELinux security context for sockets

  <Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}

           {-x|--unix} --ax25 --ipx --netrom

繼續閱讀