bogon:~ fenggu$ ping -c 1 192.168.33.11 PING 192.168.33.11 (192.168.33.11): 56 data bytes 64 bytes from 192.168.33.11: icmp_seq=0 ttl=64 time=0.563 ms
--- 192.168.33.11 ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.563/0.563/0.563/0.000 ms
抓包结果:
1 2 3 4 5 6 7 8 9 10 11
sh-3.2# tcpdump -ivboxnet0 -nn arp or icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on vboxnet0, link-type EN10MB (Ethernet), capture size 262144 bytes 15:21:20.981561 ARP, Request who-has 192.168.33.11 tell 192.168.33.1, length 28 15:21:20.981890 ARP, Reply 192.168.33.11 is-at 08:00:27:e6:6a:de, length 46 15:21:20.981922 IP 192.168.33.1 > 192.168.33.11: ICMP echo request, id 42280, seq 0, length 64 15:21:20.982032 IP 192.168.33.11 > 192.168.33.1: ICMP echo reply, id 42280, seq 0, length 64 ^C 4 packets captured 10 packets received by filter 0 packets dropped by kernel
抓包显示只收到了一个ARP响应。
虚拟机上查看网络地址:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@centos1 vagrant]# ip a ... 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:e6:6a:de brd ff:ff:ff:ff:ff:ff inet 192.168.33.10/24 scope global enp0s8 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fee6:6ade/64 scope link valid_lft forever preferred_lft forever 4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:3c:1e:5b brd ff:ff:ff:ff:ff:ff inet 192.168.33.11/24 scope global enp0s9 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe3c:1e5b/64 scope link valid_lft forever preferred_lft forever
响应的MAC地址08:00:27:e6:6a:de为网卡enp0s8的地址。
哪个设备来响应ARP请求如何决定呢?此时,我们来看路由信息:
1 2 3 4 5 6
[root@centos1 vagrant]# ip route default via 10.0.2.2 dev enp0s3 proto static metric 100 10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100 192.168.33.0/24 dev enp0s8 proto kernel scope link src 192.168.33.10 192.168.33.0/24 dev enp0s9 proto kernel scope link src 192.168.33.11
此时enp0s8的路由条目优先级高。我们重启enp0s8设备,调整两条路由条目的顺序:
1 2 3 4 5 6 7 8
[root@centos1 vagrant]# ip link set down enp0s8 [root@centos1 vagrant]# ip link set up enp0s8 [root@centos1 vagrant]# ip route default via 10.0.2.2 dev enp0s3 proto static metric 100 10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100 192.168.33.0/24 dev enp0s9 proto kernel scope link src 192.168.33.11 192.168.33.0/24 dev enp0s8 proto kernel scope link src 192.168.33.10
此时在宿主机上,清空ARP缓存再次访问192.168.33.11,抓包结果为:
1 2 3 4 5 6 7 8 9 10 11
sh-3.2# tcpdump -ivboxnet0 -nn arp or icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on vboxnet0, link-type EN10MB (Ethernet), capture size 262144 bytes 15:30:57.113221 ARP, Request who-has 192.168.33.11 tell 192.168.33.1, length 28 15:30:57.113542 ARP, Reply 192.168.33.11 is-at 08:00:27:3c:1e:5b, length 46 15:30:57.113574 IP 192.168.33.1 > 192.168.33.11: ICMP echo request, id 4137, seq 0, length 64 15:30:57.113636 IP 192.168.33.11 > 192.168.33.1: ICMP echo reply, id 4137, seq 0, length 64 ^C 4 packets captured 5 packets received by filter 0 packets dropped by kernel
[root@centos1 vagrant]# ip link set enp0s9 down [root@centos1 vagrant]# ip link set enp0s9 up [root@centos1 vagrant]# ip route default via 10.0.2.2 dev enp0s3 proto static metric 100 10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100 192.168.33.0/24 dev enp0s8 proto kernel scope link src 192.168.33.10 192.168.33.0/24 dev enp0s9 proto kernel scope link src 192.168.33.11
再次实验抓包结果如下:
1 2 3 4 5 6 7 8 9 10 11
sh-3.2# tcpdump -ivboxnet0 -nn arp or icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on vboxnet0, link-type EN10MB (Ethernet), capture size 262144 bytes 16:12:30.150463 ARP, Request who-has 192.168.33.11 tell 192.168.33.1, length 28 16:12:30.150775 ARP, Reply 192.168.33.11 is-at 08:00:27:e6:6a:de, length 46 16:12:30.150800 IP 192.168.33.1 > 192.168.33.11: ICMP echo request, id 52010, seq 0, length 64 16:12:30.150988 IP 192.168.33.11 > 192.168.33.1: ICMP echo reply, id 52010, seq 0, length 64 ^C 4 packets captured 5 packets received by filter 0 packets dropped by kernel