在ARP协议学习中有ARP、代理ARP、逆向ARP、免费ARP和翻转ARP五中情况,那么免费ARP在网络中有什么作用呢?当IP地址进行修改或者DHCP刚刚获取地址的时候,一般需要发送一个免费ARP来查询网段中有没有和本地址冲突的主机。
一、IP地址修改出发免费ARP实验环境搭建
先配置R2:
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#interface f0/0
R2(config-if)#ip address 10.1.1.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#end
*Mar 1 00:01:28.147: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 00:01:29.147: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R2#
*Mar 1 00:01:29.675: %SYS-5-CONFIG_I: Configured from console by console
R2#write memory
Building configuration...
[OK]
R2配置好之后先不要着急配置R1,因为这种免费ARP是在R1 设置IP的一瞬间就会发出去,所以先把Wireshark打开准备抓包,然后再配置R1.
R1配置:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#interface f0/0
R1(config-if)#ip address 10.1.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#
*Mar 1 00:05:05.631: %IP-4-DUPADDR: Duplicate address 10.1.1.1 on FastEthernet0/0, sourced by cc02.173c.0000
R1(config-if)#
*Mar 1 00:05:07.559: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 00:05:08.559: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
从上面的配置结果可以看出来,R1一直在返回一些数据,通过Wireshark可以看出来,一直有回复包在刷屏,而且全部是广播包,同时能看出来两个路由一直在抢夺IP地址。
通过这样的免费ARP就能在修改IP地址或者在新设备上设定地址的时候检测出局域网内此IP地址是不是已经存在了。
二、DHCP获取地址出发免费ARP实验环境
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#interface f0/0
R1(config-if)#no ip address
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#interface f0/0
R2(config-if)#no ip address
然后给R2配置一个动态路由(DHCP):
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#ip dhc
R2(config)#ip dhcp pool wireshark
R2(dhcp-config)#network 10.1.1.0 255.255.255.0
R2(dhcp-config)#default-router 10.1.1.1
R2(dhcp-config)#dns-server 8.8.8.8
R2(dhcp-config)#lease 7
再给R1配置动态路由之前同样也是先使用Wireshark抓包:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#interface f0/0
R1(config-if)#ip address dhcp
R1(config-if)#no shutdown
从这里可以看到DHCP的四个过程。