linux网络相关命令汇总(6)

2019-09-23 09:14:56王冬梅

其中Proto表示协议(包括TCP、UDP等);Recv-Q和Send-Q表示接收和发送队列,一般都为0,如果非0则表示本地的接收或发送缓存区有数据等待处理;Local Address和Foreign Address分别表示本地地址和远端地址;State表示连接状态,对应于TCP各种连接状态;PID/Program name表示进程号和程序名。
选项-l表示只显示状态为LISTEN的连接

[root@centos7 ~]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address   Foreign Address   State
tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN
tcp  0  0 127.0.0.1:25   0.0.0.0:*    LISTEN
tcp6  0  0 :::5000     :::*     LISTEN
tcp6  0  0 :::4243     :::*     LISTEN
tcp6  0  0 :::22     :::*     LISTEN
tcp6  0  0 ::1:25     :::*     LISTEN
[root@centos7 ~]#

选项-u表示显示UDP连接信息
选项-r表示显示路由信息

[root@centos7 ~]# netstat -r
Kernel IP routing table
Destination  Gateway   Genmask   Flags MSS Window irtt Iface
default   10.0.1.103  0.0.0.0   UG  0 0   0 ens33
10.0.1.0  0.0.0.0   255.255.255.0 U   0 0   0 ens33
172.20.71.0  0.0.0.0   255.255.255.0 U   0 0   0 ens32
192.168.78.0 10.0.1.104  255.255.255.0 UG  0 0   0 ens33

选项-i显示接口信息

[root@centos7 ~]# netstat -i
Kernel Interface table
Iface  MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
ens32  1500 13196107  0  77 0   3246  0  0  0 BMRU
ens33  1500 25312388  0  88 0  2516050  0  0  0 BMRU
lo  65536 2503589  0  0 0  2503589  0  0  0 LRU

13、tcpdump 网络抓包工具

命令tcpdump捕获某网络接口符合表达式expression的数据包,并打印出数据包内容的描述信息。
选项-i指定网卡:

[root@idc-v-71253 ~]# tcpdump -i ens33
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 65535 bytes
15:41:59.121948 IP 10.0.1.108.3693 > 239.100.1.1.websm: UDP, length 58
15:41:59.122191 IP 10.0.1.109.35673 > 239.100.1.1.websm: UDP, length 57 15:41:59.128282 IP 10.0.1.253.ssh > 192.168.78.143.51694: Flags [P.], seq 749565300:749565496, ack 3522345564, win 255, length 196 15:41:59.134127 IP 192.168.78.143.51694 > 10.0.1.253.ssh: Flags [.], ack 196, win 3977, length 0
15:41:59.140319 ARP, Request who-has 10.0.1.31 tell 10.0.1.102, length 46
15:41:59.168328 ARP, Request who-has 10.0.1.37 tell 10.0.1.102, length 46
15:41:59.262235 ARP, Request who-has 192.168.10.150 tell 192.168.10.151, length 46
15:41:59.622090 IP 10.0.1.108.3693 > 239.100.1.1.websm: UDP, length 58
15:41:59.622178 IP 10.0.1.109.35673 > 239.100.1.1.websm: UDP, length 57
....

启动命令之后显示出可以使用-v或-vv显示更详细的信息,开始从ens33捕获数据包。输出显示出各个发送或接收数据包包头信息(包括ARP、IP、TCP、UDP等等协议)。此命令并未指定expression,所以默认将捕获所有数据包。