netstat命令
查看系统网络连接、路由表、接口统计信息,manual中对它的解释:netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships。最常用的还是查看网络连接、路由表、接口统计
常用的参数
option | 含义 |
---|---|
-i | 接口表 |
-r | 路由表 |
-n | 不解析地址和端口号 |
-n | 不解析地址和端口号 |
-a | 列出所有端口和socket |
-t | TCP协议 |
-u | UDP协议 |
-l | listening,所有侦听状态的端口或者socket |
-s | 列出统计信息 |
-p | process,打印端口号关联的进程号和进程名称 |
查看接口统计
查看接口收发包的统计用-i参数,如下:
[root@yunwei ~]# netstat -i
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
br-0cb8bea5289e 1500 6529974 0 0 0 4677194 0 0 0 BMRU
br-c04b922d55da 1500 1170104 0 0 0 1583603 0 0 0 BMRU
docker0 1500 152288 0 0 0 156994 0 0 0 BMRU
eth0 1500 274720584 0 0 0 83340723 0 0 0 BMRU
lo 65536 116776948 0 0 0 116776948 0 0 0 LRU
查看路由表
查看路由表用-r参数,一般跟-n参数一起使用,如下:
[root@yunwei ~]# 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.255.0 U 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-c04b922d55da
172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-0cb8bea5289e
查看网络连接
查看所有的TCP连接
[root@yunwei ~]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:90 0.0.0.0:* LISTEN
查看所有的UDP连接:
[root@yunwei ~]# netstat -anu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:631 0.0.0.0:*
udp 0 0 0.0.0.0:823 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 :::823 :::*
udp 0 0 :::111 :::*
查看侦听状态的TCP端口
[root@yunwei ~]# netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 ::1:6010 :::* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
查看TCP的统计信息
[root@yunwei ~]# netstat -st
IcmpMsg:
InType0: 2
InType3: 9
OutType3: 13
OutType8: 2
Tcp:
7 active connections openings
1 passive connection openings
7 failed connection attempts
0 connection resets received
1 connections established
1132 segments received
762 segments send out
0 segments retransmited
0 bad segments received.
7 resets sent
UdpLite:
InDatagrams: 0
NoPorts: 0
InErrors: 0
OutDatagrams: 0
RcvbufErrors: 0
SndbufErrors: 0
TcpExt:
ArpFilter: 0
18 delayed acks sent
1 delayed acks further delayed because of locked socket
1 packets directly queued to recvmsg prequeue.
387 packets header predicted
TCPPureAcks: 148
TCPHPAcks: 405
TCPRenoRecovery: 0
TCPSackRecovery: 0
TCPSACKReneging: 0
TCPFACKReorder: 0
TCPSACKReorder: 0
TCPRenoReorder: 0
TCPTSReorder: 0
TCPFullUndo: 0
TCPPartialUndo: 0
TCPDSACKUndo: 0
TCPLossUndo: 0
TCPLoss: 0
TCPLostRetransmit: 0
TCPRenoFailures: 0
TCPSackFailures: 0
TCPLossFailures: 0
TCPFastRetrans: 0
TCPForwardRetrans: 0
TCPSlowStartRetrans: 0
TCPTimeouts: 0
TCPRenoRecoveryFail: 0
TCPSackRecoveryFail: 0
TCPSchedulerFailed: 0
TCPRcvCollapsed: 0
TCPDSACKOldSent: 0
TCPDSACKOfoSent: 0
TCPDSACKRecv: 0
TCPDSACKOfoRecv: 0
TCPAbortOnData: 0
TCPAbortOnClose: 0
TCPAbortOnMemory: 0
TCPAbortOnTimeout: 0
TCPAbortOnLinger: 0
TCPAbortFailed: 0
TCPMemoryPressures: 0
TCPSACKDiscard: 0
TCPDSACKIgnoredOld: 0
TCPDSACKIgnoredNoUndo: 0
TCPSpuriousRTOs: 0
TCPMD5NotFound: 0
TCPMD5Unexpected: 0
TCPSackShifted: 0
TCPSackMerged: 0
TCPSackShiftFallback: 0
TCPBacklogDrop: 0
TCPMinTTLDrop: 0
TCPDeferAcceptDrop: 0
IPReversePathFilter: 5
TCPTimeWaitOverflow: 0
TCPChallengeACK: 0
TCPSYNChallenge: 0
IpExt:
InNoRoutes: 0
InTruncatedPkts: 0
InMcastPkts: 0
OutMcastPkts: 0
InBcastPkts: 5780
OutBcastPkts: 0
InOctets: 2970950
OutOctets: 148490
InMcastOctets: 0
OutMcastOctets: 0
InBcastOctets: 2888967
OutBcastOctets: 0
查看所有的TCP端口并打印出它们的进程号和进程名
[root@yunwei ~]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 11839/1
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2768/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3215/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3229/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3334/master
tcp 0 36 192.168.101.9:22 192.168.101.8:7085 ESTABLISHED 11839/1
tcp 0 0 ::1:6010 :::* LISTEN 11839/1
tcp 0 0 :::111 :::* LISTEN 2768/rpcbind
tcp 0 0 :::22 :::* LISTEN
还有其他的查看方法,可根据需要自己组合参数即可
觉得有帮助的话请给一个赞哟~~