LINUX不可不知的網絡命令-netstat

LINUX不可不知的網絡命令-netstat

LINUX不可不知的網絡命令-netstat


資料來源:https://mp.weixin.qq.com/s?__biz=MzI4MDEwNzAzNg==&mid=2649445744&idx=1&sn=49a251190849832508d157d6c297652a&scene=21#wechat_redirect

顯示TCP 和 UDP 所有連線 

$ netstat –a

查看某個端口是否被佔用

$ netstat -a|grep 6379
tcp        0      0 *:6379                  *:*                     LISTEN     
tcp6       0      0 [::]:6379               [::]:*                  LISTEN 

查找佔用端口的進程

$ netstat -ap|grep 6379
tcp        0      0 *:6379                  *:*                     LISTEN      10011/redis-server 
tcp6       0      0 [::]:6379               [::]:*                  LISTEN      10011/redis-server


查看指定協議的連接

$ netstat -at   #-t,查看tcp连接
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 192.168.0.103:42468     113.96.233.139:https    ESTABLISHED
tcp        0      0 192.168.0.103:59326     123.58.182.252:https    TIME_WAIT  
tcp        0      0 192.168.0.103:59328     123.58.182.252:https    TIME_WAIT

$ netstat -au
udp        0      0 *:36305                 *:*                                
udp        0      0 127.0.1.1:domain        *:*                                
udp        0      0 *:bootpc                *:*                                
udp        0      0 *:ipp                   *:* 

 

查看處於監聽狀態的連接

$ netstat -l
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.1.1:domain        *:*                     LISTEN     
tcp        0      0 localhost:5941          *:*                     LISTEN     
tcp        0      0 localhost:ipp           *:*                     LISTEN     
tcp        0      0 localhost:socks         *:*                     LISTEN     
tcp        0      0 *:6379                  *:*                     LISTEN

查看數據包統計信息

$ netstat -s
(仅显示了TCP协议的结果)
Tcp:
    3067 active connections openings
    1 passive connection openings
    173 failed connection attempts
    587 connection resets received
    10 connections established
    657576 segments received
    456349 segments send out
    2700 segments retransmited
    16 bad segments received.
    1321 resets sent


查看路由信息

$ netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         192.168.0.1     0.0.0.0         UG        0 0          0 wlp3s0
link-local      *               255.255.0.0     U         0 0          0 wlp3s0
192.168.0.0     *               255.255.255.0   U         0 0          0 wlp3s0 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *