請關注本頭條号,每天堅持更新原創幹貨技術文章。
如需學習視訊,請在微信搜尋公衆号“智傳網優”直接開始自助視訊學習
1. netstat指令簡介
Netstat 指令用于顯示各種網絡相關資訊,如網絡連接配接,路由表,接口狀态 (Interface Statistics),masquerade 連接配接,多點傳播成員 (Multicast Memberships) 等等。
netstat指令簡介
2. 檢視netstat 所有狀态
[[email protected] ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 my_public_ip:9016 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:9017 0.0.0.0:* LISTEN
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:9018 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:pptp 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:9019 0.0.0.0:* LISTEN
3. 檢視所有TCP連接配接
[[email protected] ~]# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 my_public_ip:9016 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:9017 0.0.0.0:* LISTEN
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:9018 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:pptp 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:9019 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:tambora 0.0.0.0:* LISTEN
tcp 0 0 my_public:etlservicemgr 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:dynamid 0.0.0.0:* LISTEN
tcp 0 0 my_public_ip:9003 0.0.0.0:* LISTEN
4. 禁用反向域名解析,加快查詢速度
[[email protected] ~]# netstat -ant
tcp 0 0 113.105.164.151:42342 202.46.36.30:9001 CLOSE_WAIT
tcp 0 0 113.105.164.151:49472 202.46.36.30:9001 ESTABLISHED
tcp 0 0 113.105.164.151:43470 202.46.36.30:9001 CLOSE_WAIT
tcp 0 0 113.105.164.151:43576 202.46.36.30:9001 CLOSE_WAIT
tcp 0 0 113.105.164.151:9001 120.84.140.61:6290 FIN_WAIT2
tcp 0 0 113.105.164.151:9015 183.14.29.69:6809 FIN_WAIT2
tcp 0 0 113.105.164.151:35424 202.46.36.30:9002 CLOSE_WAIT
tcp 0 0 113.105.164.151:38074 202.46.36.30:9001 CLOSE_WAIT
tcp 0 0 113.105.164.151:9001 118.112.75.246:2710 FIN_WAIT2
tcp 0 0 113.105.164.151:45124 202.46.36.30:9001 CLOSE_WAIT
tcp 0 0 113.105.164.151:37202 202.46.36.30:9001 CLOSE_WAIT
tcp 0 0 113.105.164.151:52640 202.46.36.30:9001 CLOSE_WAIT
5. 持續重新整理資訊
我們可以使用 netstat 的 -c 選項持續輸出資訊。
[[email protected] ~]# netstat -ct
6. 常見用法
6.1 檢視所有TCP監聽端口
[[email protected] ~]# netstat -lntp
linux檢視所有TCP監聽端口
6.2 檢視所有的TCP連接配接情況
[[email protected] ~]# netstat -antp
6.3 檢視所有UDP連接配接情況
[[email protected] ~]# netstat -anp |sed -n '2p;/^udp/p'
6.4 檢視所有已經建立的TCP連接配接
[[email protected] ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p'
linux檢視所有已經建立的TCP連接配接
6.5 檢視系統目前TCP連接配接數:
[[email protected] ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p' |wc -l
6.6 檢視TCP半開連接配接,正常情況下,應該看不到有資料
[[email protected] ~]# netstat -nap | grep SYN_RECV
6.7 檢視TCP半開連接配接數,正常情況下應該為0
[[email protected] ~]# netstat -nap | grep SYN_RECV |wc -l
6.8 檢視網絡統計資訊
[[email protected] ~]# netstat -s