Linux查看端口狀態-netstat


在 Linux 中 netstat各個參數情況如下:

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
        -a, --all                display all sockets (default: connected)
        -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
  <AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) 
    x25 (CCITT X.25) 

常用的參數有這些:

-t : 指明顯示TCP端口

  -u : 指明顯示UDP端口

  -l : 僅顯示監聽套接字(所謂套接字就是使應用程序能夠讀寫與收發通訊協議(protocol)與資料的程序)

  -p : 顯示進程標識符和程序名稱,每一個套接字 / 端口都屬於一個程序。

  -n : 不進行DNS輪詢,顯示IP(可以加速操作)

 

//查看當前所有的TCP端口

netstat -ntlp

//查看端口為 6379 的使用情況

netstat -ntulp | grep 6379

//查看端口為 6379 的使用情況

netstat -an | grep 6379

//查看一台服務器上有哪些服務及端口

netstat -lanp

//查看一個服務有哪些端口

ps -ef | grep redis-server

//查看某個端口的鏈接數量

netstat -pnt | grep :6379 | wc

//查看某一端口的連接客戶端 IP 

netstat -anp | grep 6379

//查看網絡端口

netstat -an

//查看所指定端口的運行程序

lsof -i :port

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM