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) 
html

    x25 (CCITT X.25) mysql

顯示正在監聽的tcp端口:linux

-l表示監聽sql

-t表示tcp瀏覽器

-p表示顯示程序名服務器

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

-u表示udpssh

[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         socket

第二、3列,表示收發包的數量,也反映了當前當前網絡鏈接的通訊流量tcp

  

[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

顯示全部已創建的有效鏈接。

相關文章
相關標籤/搜索