netstat/ss監聽網絡連接分析

[root@pa137 ~]# netstat   --help
usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vnNcaeol] [<Socket> ...]
       netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [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
        -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
        -T, --notrim               stop trimming long addresses
        -Z, --context              display SELinux security context for sockets


  <Iface>: Name of interface to monitor/list.
  <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
  <AF>=Use '-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) 

顯示正在監聽的tcp端口:

-l表示監聽

-t表示tcp

-p表示顯示程序名

-n表示部將ip和端口轉換成域名和服務名

-u表示udp

[root@pa137 ~]# netstat   -tlnpa
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2493/portmap        
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2776/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2808/sendmail: acce 
tcp        0      0 0.0.0.0:1020                0.0.0.0:*                   LISTEN      2534/rpc.statd      
tcp        0      0 :::3306                     :::*                        LISTEN      15681/mysqld        
tcp        0      0 :::22                       :::*                        LISTEN      2767/sshd         

第2、3列,表示收發包的數量,也反映了當前當前網絡連接的通信流量

  

[root@pa137 ~]# 

[root@pa137 ~]# netstat   -atnp 
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2493/portmap        
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2776/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2808/sendmail: acce 
tcp        0      0 0.0.0.0:1020                0.0.0.0:*                   LISTEN      2534/rpc.statd      
tcp        0      0 :::3306                     :::*                        LISTEN      15681/mysqld        
tcp        0      0 :::22                       :::*                        LISTEN      2767/sshd           
tcp        0      0 ::ffff:192.168.1.137:22     ::ffff:192.168.31.101:49223 ESTABLISHED 3110/2              
tcp        0    260 ::ffff:192.168.1.137:22     ::ffff:192.168.31.101:49712 ESTABLISHED 3438/4              
tcp        0      0 ::ffff:192.168.1.137:22     ::ffff:192.168.31.102:1039  ESTABLISHED 3151/3              
[root@pa137 ~]# netstat   -aunp 
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
udp        0      0 0.0.0.0:33716               0.0.0.0:*                               2915/avahi-daemon:  
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               2915/avahi-daemon:  
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2493/portmap        
udp        0      0 0.0.0.0:1014                0.0.0.0:*                               2534/rpc.statd      
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2776/cupsd          
udp        0      0 0.0.0.0:1017                0.0.0.0:*                               2534/rpc.statd      
udp        0      0 :::5353                     :::*                                    2915/avahi-daemon:  
udp        0      0 :::54269                    :::*                                    2915/avahi-daemon:  
[root@pa137 ~]# 

功能說明Netstat用於顯示與IP、TCP、UDP和ICMP協議相關的統計數據,一般用於檢驗本機各端口的網絡連接情況。
語  法netstat [-acCeFghilMnNoprstuvVwx][-A<網絡類型>][--ip]
補充說明:利用netstat指令可讓你得知整個Linux系統的網絡情況。
參  數
-a或–all 顯示所有連線中的Socket。
-A<網絡類型>或–<網絡類型> 列出該網絡類型連線中的相關地址。
-c或–continuous 持續列出網絡狀態。
-C或–cache 顯示路由器配置的快取信息。
-e或–extend 顯示網絡其他相關信息。
-F或–fib 顯示FIB。
-g或–groups 顯示多重廣播功能羣組組員名單。
-h或–help 在線幫助。
-i或–interfaces 顯示網絡界面信息表單。
-l或–listening 顯示監控中的服務器的Socket。
-M或–masquerade 顯示僞裝的網絡連線。
-n或–numeric 直接使用IP地址,而不通過域名服務器
-N或–netlink或–symbolic 顯示網絡硬件外圍設備的符號連接名稱。
-o或–timers 顯示計時器。
-p或–programs 顯示正在使用Socket的程序識別碼和程序名稱。
-r或–route 顯示Routing Table。
-s或–statistice 顯示網絡工作信息統計表。
-t或–tcp 顯示TCP傳輸協議的連線狀況。
-u或–udp 顯示UDP傳輸協議的連線狀況。
-v或–verbose 顯示指令執行過程。
-V或–version 顯示版本信息。
-w或–raw 顯示RAW傳輸協議的連線狀況。
-x或–unix 此參數的效果和指定”-A unix”參數相同。
–ip或–inet 此參數的效果和指定”-A inet”參數相同

netstat 的一些常用選項

·netstat –s

本選項能夠按照各個協議分別顯示其統計數據。如果我們的應用程序(如Web瀏覽器)運行速度比較慢,或者不能顯示Web頁之類的數據,那麼我們就可以用本選項來查看一下所顯示的信息。我們需要仔細查看統計數據的各行,找到出錯的關鍵字,進而確定問題所在。

·netstat –e

本選項用於顯示關於以太網的統計數據。它列出的項目包括傳送的數據報的總字節數、錯誤數、刪除數、數據報的數量和廣播的數量。這些統計數據既有發送的數據報數量,也有接收的數據報數量。這個選項可以用來統計一些基本的網絡流量)。

·netstat –r

本選項可以顯示關於路由表的信息,類似於後面所講使用route print命令時看到的 信息。除了顯示有效路由外,還顯示當前有效的連接。

·netstat –a

本選項顯示一個所有的有效連接信息列表,包括已建立的連接(ESTABLISHED),也包括監聽連接請(LISTENING)的那些連接。

·netstat –n

顯示所有已建立的有效連接。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章