Linux的netstat命令詳解
Linux的netstat命令
1、TCP連接狀態(tài)詳解
- LISTEN: 偵聽來自遠(yuǎn)方的TCP端口的連接請(qǐng)求
- SYN-SENT: 再發(fā)送連接請(qǐng)求后等待匹配的連接請(qǐng)求
- SYN-RECEIVED:再收到和發(fā)送一個(gè)連接請(qǐng)求后等待對(duì)方對(duì)連接請(qǐng)求的確認(rèn)
- ESTABLISHED: 代表一個(gè)打開的連接
- FIN-WAIT-1: 等待遠(yuǎn)程TCP連接中斷請(qǐng)求,或先前的連接中斷請(qǐng)求的確認(rèn)
- FIN-WAIT-2: 從遠(yuǎn)程TCP等待連接中斷請(qǐng)求
- CLOSE-WAIT: 等待從本地用戶發(fā)來的連接中斷請(qǐng)求
- CLOSING: 等待遠(yuǎn)程TCP對(duì)連接中斷的確認(rèn)
- LAST-ACK: 等待原來的發(fā)向遠(yuǎn)程TCP的連接中斷請(qǐng)求的確認(rèn)
- TIME-WAIT: 等待足夠的時(shí)間以確保遠(yuǎn)程TCP接收到連接中斷請(qǐng)求的確認(rèn)
- CLOSED: 沒有任何連接狀態(tài)
2、命令格式
netstat(選項(xiàng))
3、命令選項(xiàng)
- -a或–all:顯示所有連線中的Socket;
- -A<網(wǎng)絡(luò)類型>或–<網(wǎng)絡(luò)類型>:列出該網(wǎng)絡(luò)類型連線中的相關(guān)地址;
- -c或–continuous:持續(xù)列出網(wǎng)絡(luò)狀態(tài);
- -C或–cache:顯示路由器配置的快取信息;
- -e或–extend:顯示網(wǎng)絡(luò)其他相關(guān)信息;
- -F或–fib:顯示FIB;
- -g或–groups:顯示多重廣播功能群組組員名單;
- -h或–help:在線幫助;
- -i或–interfaces:顯示網(wǎng)絡(luò)界面信息表單;
- -l或–listening:顯示監(jiān)控中的服務(wù)器的Socket;
- -M或–masquerade:顯示偽裝的網(wǎng)絡(luò)連線;
- -n或–numeric:直接使用ip地址,而不通過域名服務(wù)器;
- -N或–netlink或–symbolic:顯示網(wǎng)絡(luò)硬件外圍設(shè)備的符號(hào)連接名稱;
- -o或–timers:顯示計(jì)時(shí)器;
- -p或–programs:顯示正在使用Socket的程序識(shí)別碼和程序名稱;
- -r或–route:顯示Routing Table;
- -s或–statistice:顯示網(wǎng)絡(luò)工作信息統(tǒng)計(jì)表;
- -t或–tcp:顯示TCP傳輸協(xié)議的連線狀況;
- -u或–udp:顯示UDP傳輸協(xié)議的連線狀況;
- -v或–verbose:顯示指令執(zhí)行過程;
- -V或–version:顯示版本信息;
- -w或–raw:顯示RAW傳輸協(xié)議的連線狀況;
- -x或–unix:此參數(shù)的效果和指定"-A unix"參數(shù)相同;
- –ip或–inet:此參數(shù)的效果和指定"-A inet"參數(shù)相同。
4、列出所有端口(包含TCP和UDP)
> netstat -a
4、列出所有TCP端口
> netstat -at
5、列出所有UDP端口
> netstat -au
6、列出所有處于監(jiān)聽狀態(tài)的 Sockets
> netstat -l
7、只列出所有監(jiān)聽tcp端口
> netstat -lt
8、只列出所有監(jiān)聽udp端口
> netstat -lu
9、只列出所有監(jiān)聽UNIX端口
> netstat -lx
10顯示所有端口的統(tǒng)計(jì)信息
> netstat -s Ip: 1007495197 total packets received 0 forwarded 582 with unknown protocol 0 incoming packets discarded 1007422115 incoming packets delivered Icmp: 66583265 ICMP messages received 63899 input ICMP message failed. InCsumErrors: 384 ICMP input histogram: destination unreachable: 115410 timeout in transit: 12840 source quenches: 11 redirects: 563 echo requests: 66453453 echo replies: 152 timestamp request: 438 address mask request: 4 66987000 ICMP messages sent 0 ICMP messages failed ICMP output histogram: destination unreachable: 533106 echo request: 4 echo replies: 66453453 timestamp replies: 437 IcmpMsg: InType0: 152 InType3: 115410 InType4: 11 InType5: 563 IpExt: InNoRoutes: 15 InMcastPkts: 1291307 InOctets: 211446050816 OutOctets: 481070069194
11、顯示TCP端口的統(tǒng)計(jì)信息
> netstat -st IcmpMsg: InType0: 152 InType3: 115410 InType4: 11 InType5: 563 InType8: 66453492 Tcp: 55437641 active connections openings 35899081 passive connection openings 552243 failed connection attempts 753118 connection resets received 7 connections established UdpLite: TcpExt: 162052 SYN cookies sent 621 SYN cookies received 4998179 invalid SYN cookies received 551915 resets received for embryonic SYN_RECV sockets IpExt: InNoRoutes: 15 InMcastPkts: 1291308 InOctets: 211446303015 OutOctets: 481070459735 InMcastOctets: 46487088
12、顯示UDP端口的統(tǒng)計(jì)信息
> netstat -su IcmpMsg: InType0: 152 InType3: 115410 InType4: 11 InType5: 563 InType8: 66453594 InType11: 12840 InType13: 438 InType17: 4 InType37: 3 InType165: 7 OutType0: 66453594 OutType3: 533106 OutType8: 4 OutType14: 437 Udp: 17941589 packets received 637146 packets to unknown port received. 1649 packet receive errors 17977050 packets sent 0 receive buffer errors 0 send buffer errors InCsumErrors: 1640 UdpLite: IpExt: InNoRoutes: 15 InMcastPkts: 1291310 InOctets: 211446802283 OutOctets: 481071405083 InMcastOctets: 46487160 InNoECTPkts: 1009629627 InECT1Pkts: 9955 InECT0Pkts: 1987096 InCEPkts: 94039
13、在netstat輸出中顯示 PID 和進(jìn)程名稱
> netstat -pt
14、在netstat輸出中不顯示主機(jī),端口和用戶名(host, port or user)
> netstat -an
15、持續(xù)輸出netstat信息
每隔一秒輸出網(wǎng)絡(luò)信息
> netstat -c
16、顯示核心路由信息
> netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default gateway 0.0.0.0 UG 0 0 0 eth0 link-local 0.0.0.0 255.255.0.0 U 0 0 0 eth0 172.16.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
17、使用netstat -rn顯示數(shù)字格式,不查詢主機(jī)名稱。
> netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 172.16.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
18、找出程序運(yùn)行的端口
> netstat -tunlp | grep ssh tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4400/sshd
19、找出運(yùn)行在指定端口的進(jìn)程
> netstat -an | grep ":80" tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 172.16.0.9:80 185.191.171.12:9380 TIME_WAIT tcp 0 0 172.16.0.9:80 185.191.171.26:52418 TIME_WAIT tcp 0 3450 172.16.0.9:80 185.191.171.37:25108 FIN_WAIT1 tcp 0 0 172.16.0.9:80 185.191.171.37:55096 TIME_WAIT tcp 0 0 172.16.0.9:80 144.76.176.171:27832 TIME_WAIT tcp 0 0 172.16.0.9:80 118.126.124.7:11127 TIME_WAIT tcp 0 0 172.16.0.9:46628 169.254.0.55:8080 TIME_WAIT tcp 0 0 172.16.0.9:80 144.76.176.171:23812 ESTABLISHED
20、通過端口找進(jìn)程ID
> netstat -tunlp | grep 80 | awk '{print $7}' | cut -d/ -f1 21323
21、顯示網(wǎng)絡(luò)接口列表
> netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg docker0 1500 0 0 0 0 0 0 0 0 BMU eth0 1450 462305568 0 0 0 276046945 0 0 0 BMRU lo 65536 7204971 0 0 0 7204971 0 0 0 LRU vpn_abi 1500 229612389 0 1023383 0 146640133 0 956 0 BMRU
22、統(tǒng)計(jì)TCP各種狀態(tài)列表
> netstat -n | awk '/^tcp/{++S[$NF]}END{for(i in S) print i,S[i]}' ESTABLISHED 7 FIN_WAIT2 13 TIME_WAIT 18
以上就是Linux的netstat命令詳解的詳細(xì)內(nèi)容,更多關(guān)于Linux netstat命令的資料請(qǐng)關(guān)注本站其它相關(guān)文章!希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。