我們可以使用man netstat檢視該命令的使用手冊。
這個程式已經過時了。netstat的替換為ss。netstat-r的替換是ip路由。netstat-i的替換是ip-s連結。netstat-g的替換是ip maddr
該命令用於輸出網路狀態
不帶任何引數,其中輸出包括兩部分:Active Internet connections (w/o servers)和Active UNIX domain sockets (w/o servers)。Active Internet connections (w/o servers)為socket連線。Active UNIX domain sockets (w/o servers)為UNIX域套接字連線,不透過網路層傳輸資料,而是核心級別的程序之間通訊。
Recv-Q和Send-Q分別表示接收佇列和傳送佇列位元組數,也就是在途中的資料
Local Address為本地地址和埠,Foreign Address為客戶端地址和埠
Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 wh2-login-2-1.wh.:46534 wh2-login-2-1.wh.:mysql ESTABLISHED tcp 0 0 wh2-login-2-1.wh.:mysql wh2-login-2-1.wh.:45998 ESTABLISHED tcp 0 0 wh2-login-2-1.wh.:mysql wh2-login-2-1.wh.:46562 ESTABLISHED tcp 0 0 wh2-login-2-1.wh.h:exp1 10.26.1.26:988 ESTABLISHED udp 0 0 wh2-login-2-1.wh.:58302 wh2-login-2-2.wh.h:8650 ESTABLISHED udp 0 0 wh2-login-2-1.wh.:46570 wh2-login-2-1.wh.h:8650 ESTABLISHED Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 3 [ ] DGRAM 9613 /run/systemd/notify unix 2 [ ] DGRAM 9615 /run/systemd/cgroups-agent unix 5 [ ] DGRAM 9626 /run/systemd/journal/socket unix 24 [ ] DGRAM 9628 /dev/log
netstat --route或netstat -r
路由表資訊
$ netstat --route Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default 192.168.160.254 0.0.0.0 UG 0 0 0 em2 //發往任何一個地址都經過192.168.160.254閘道器 10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 em1 //發往10.0.0.0網段是直接可達的,不需要經過閘道器 10.49.32.209 192.168.160.254 255.255.255.255 UGH 0 0 0 em2 // 224.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 em1 // 255.255.255.255 0.0.0.0 255.255.255.255 UH 0 0 0 em1 //廣播地址不需要經過閘道器
netstat --interfaces
網路卡資訊
$ netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg em1 1500 929030804 0 15441 0 861262213 0 0 0 BMRU em2 1500 274694218 4 0 0 265690135 0 0 0 BMRU lo 65536 685245949 0 0 0 685245949 0 0 0 LRU
比較重要的引數
--numeric/-n,直接顯示ip地址,而不是預設輸出域名格式
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 10.25.2.101:32950 10.176.41.12:8080 TIME_WAIT
tcp 0 0 192.168.160.7:3306 192.168.160.7:50428 ESTABLISHED
tcp 0 0 10.25.2.101:1021 10.26.1.26:988 ESTABLISHED
--program/-p
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 wh2-login-2-1.wh.:mysql wh2-login-2-1.wh.:50428 ESTABLISHED -
tcp 0 0 localhost.localdo:58568 localhost.localdom:8093 ESTABLISHED 2601/java
tcp 0 0 wh2-login-2-1.wh.h:exp2 10.176.48.3:988 ESTABLISHED -
tcp 0 0 wh2-login-2-1.wh.bl:ssh 172.19.4.84:64207 ESTABLISHED -
tcp 0 0 wh2-login-2-1.wh.h:exp2 10.176.48.7:988 ESTABLISHED -
tcp 0 0 wh2-login-2-1.wh.h:1023 10.176.48.8:988 ESTABLISHED -
tcp 0 0 wh2-login-2-1.wh.:50750 wh2-login-2-1.wh.:mysql ESTABLISHED 17154/java
--listen/-l
$ netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost.localdom:smux 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:cslistener 0.0.0.0:* LISTEN
tcp 0 0 wh2-login-2-1.wh.h:7946 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8650 0.0.0.0:* LISTEN
--all/-a
顯示listening和非listening的連線
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8650 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8093 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8098 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
tcp 0 0 wh2-login-2-1.wh.:mysql wh2-login-2-1.wh.:50428 ESTABLISHED
tcp 0 0 wh2-login-2-1.wh.h:exp1 10.26.1.26:988 ESTABLISHED
tcp 0 0 wh2-login-2-1.wh.h:exp1 10.176.48.10:988 ESTABLISHED
tcp 0 0 wh2-login-2-1.wh.:mysql wh2-login-2-1.wh.:50956 ESTABLISHED