ubuntu netstat 查看端口占用情況


netstat

用於顯示各種網絡相關信息,如網絡連接,路由表,接口狀態 (Interface Statistics)masquerade 連接,多播成員 (Multicast Memberships) 等等

 

grid_hd@hadoop1:~$ netstat -h

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

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

netstat { [-vWeenNac] -i | [-cWnNe] -M | -s }

 

-r, --route display routing table ##顯示路由表

 

-i, --interfaces display interface table

 

-g, --groups display multicast group memberships

 

-s, --statistics display networking statistics (like SNMP) 顯示網絡統計信息

 

 

 

-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

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)

 

 

參考文章 http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316661.html

常見參數

-a (all)    顯示所有選項,默認不顯示LISTEN相關
-t (tcp)    
僅顯示tcp相關選項
-u (udp)    
僅顯示udp相關選項
-n         
拒絕顯示別名,能顯示數字的全部轉化成數字。
-l         
僅列出有在 Listen (監聽) 的服務狀態

-p         顯示建立相關鏈接的程序名
-r         
顯示路由信息,路由表
-e         
顯示擴展信息,例如uid
-s         
按各個協議進行統計
-c         
每隔一個固定時間,執行該netstat命令。

提示:LISTENLISTENING的狀態只有用-a或者-l才能看到

 

列出所有tcp端口sudo netstat -at (以root用戶運行)

轉化成數字形式顯示sudo netstat -natp (以root用戶運行)

 

顯示53端口的占用情況(在tcp, udp中找 -l 顯示正在監聽的sockets)

 

 

顯示53端口的占用情況(顯示所有的連接)

 

 

 

列出所有連接情況(並顯示進程名)

從整體上看,netstat的輸出結果可以分為兩個部分:

一個是Active Internet connections,稱為有源TCPUDP連接,其中"Recv-Q""Send-Q"%0A的是接收隊列和發送隊列。

這些數字一般都應該是0。如果不是則表示軟件包正在隊列中堆積。這種情況只能在非常少的情況見到。

 

另一個是Active UNIX domain sockets,稱為有源Unix域套接口(和網絡套接字一樣,但是只能用於本機通信,性能可以提高一倍)
Proto    
顯示連接使用的協議

RefCnt    表示連接到本套接口上的進程號

Types    顯示套接口的類型

State    顯示套接口當前的狀態

Path    表示連接到套接口的其它進程使用的路徑名


免責聲明!

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



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