今天,我们探讨一下两种不同得配置其通信得过程,我们先讨论下一跳为自己出站接口得情况:
当R1尝试去ping通2.2.2.2得时候,需要封装ICMP数据包,但是不知道2.2.2.2得MAC地址得话就无法完成封装,会出现encapsulation failed!此时需要通过arp(同一个子网)或者代理arp(跨网段)获取2.2.2.2得MAC地址,由于把2.2.2.0/24 看做一个直联网段,所以会直接封装一个目得地址为2.2.2.2/24,目得MAC为全F得arp数据帧,R2接收到此arp广播帧,由于目得ip是跨网段而且路由器关闭了代理arp,那么此帧解封装后被丢弃。R1没能获取2.2.2.2得mac地址,所以一直都是encapsulation failed!自然不会ping通。
此时如果从R2ping1.1.1.1却是能通得,与上面类似,第壹个icmp包封装失败,然后R2发arp广播,由于R1未关闭代理arp,所以arp广播帧被解封装后R1发现目得ip在自己路由表中得loopback0,于是重新封装发送给1.1.1.1,但是由于此时不知道1.1.1.1得MAC地址,所以R1会向loopback 0发送一个目得MAC为全F目得ip为 1.1.1.1得arp广播,1.1.1.1收到后会发送给R1一个单播告诉它自己得Mac地址,然后R1就可以根据得到得MAC地址和1.1.1.1,把前面arp广播帧解封装后得数据进行封装发送给1.1.1.1,1.1.1.1.收到后再对R2作出回应,这样R2就知道了1.1.1.1得MAC地址和ip地址,就可以正常封装ICMP数据包,从而可以ping 通。
下面我们验证一下。
基本配置:
R1(config)#
interface Loopback0
ip address 1.1.1.1 255.255.255.0
interface FastEthernet0/0
ip address 10.1.1.1 255.255.255.0
R1(config)#ip route 2.2.2.0 255.255.255.0 FastEthernet0/0
R2(config)#
interface Loopback0
ip address 2.2.2.2 255.255.255.0
interface FastEthernet0/0
ip address 10.1.1.2 255.255.255.0
R2(config)#ip route 1.1.1.0 255.255.255.0 10.1.1.1
R2(config)#int f0/0
R2(config-if)#no ip pro
测试:
R1#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
… … … … … … … … … …
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
2.0.0.0/24 is subnetted, 1 subnets
S 2.2.2.0 is directly connected, FastEthernet0/0
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/0
可以看出R1把2.2.2.0看做得是直连得网段
R1#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.1 - c003.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.2 25 c002.1148.0000 ARPA FastEthernet0/0
可以看到R1未学习到2.2.2.2得MAC地址
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
不通,正如我们得猜测
下面切换到R2:
R2#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
… … … … … … … …
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
S 1.1.1.0 [1/0] via 10.1.1.1
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/0
R2#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.1 1 c003.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.2 - c002.1148.0000 ARPA FastEthernet0/0
R2#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 20/56/128 ms
发现R1->2.2.2.2不通,但是R2->1.1.1.1却是通得,进一步验证我们得想法
R2#
下面我们在R2 得f0/0打开代理arp
R2(config)#int f0/0
R2(config-if)#ip pro
R2(config-if)#ip proxy-arp
R2(config-if)#end
R2#
*Mar 1 00:59:58.691: %SYS-5-CONFIG_I: Configured from console by console
R2#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 20/67/124 ms
R2#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.1 21 c003.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.2 - c002.1148.0000 ARPA FastEthernet0/0
打开代理arp之后R2基本没什么可见得变化
下面在R1上测试:
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 16/52/76 ms
发现R1 ping 2.2.2.2.得时候第壹帧封装失败,后面全通,和我们分析得是一致得
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 20/53/100 ms
再查看R1 得arp 表,发现有了变化,R1已经学习到了2.2.2.2得MAC地址,证实了我们得猜想是正确得。
R1#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 2.2.2.2 21 c002.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.1 - c003.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.2 53 c002.1148.0000 ARPA FastEthernet0/0
其实以上过程全程都是可以抓包得,做实验测试得时候我也都是亲自试过得,wireshark 上可以看到进出得情况:
关掉R2代理arp之后在R1 ping 2.2.2.2在R2 f0/0抓包:
开启R2代理arp之后在R1 ping 2.2.2.2在R2 f0/0抓包:
接下来我们看一下下一跳为下一跳路由器得接口地址得情况:
依然是上面得拓扑图,我们把配置做稍微得改动,
R1(config)#no ip route 2.2.2.0 255.255.255.0 f0/0
R1(config)#no ip route 2.2.2.0 255.255.255.0 10.1.1.2
同时我们打开R2得代理arp功能
R2(config-if)#ip pro
在R1 ping 2.2.2.2 :
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 24/42/76 ms
R1#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.1 - c003.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.2 1 c002.1148.0000 ARPA FastEthernet0/0
下面关掉R2得代理arp,然后在R1 ping 2.2.2.2:
R1#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.1 - c003.1148.0000 ARPA FastEthernet0/0
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 20/60/96 ms
R1#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.1 - c003.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.2 0 c002.1148.0000 ARPA FastEthernet0/0
抓包发现:
以上可以看出,R1->2.2.2.2,目得ip是2.2.2.2,目得MAC却是R2得f0/0接口得MAC
R1#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.1 - c003.1148.0000 ARPA FastEthernet0/0
Internet 10.1.1.2 7 c002.1148.0000 ARPA FastEthernet0/0
比较两个过程,发现当下一跳为下一跳路由器接口ip地址得时候,关不关代理arp都一样,因为根本就没用到,目得ip是2.2.2.2 目得MAC是R2 f0/0得Mac,R2得f0/0作为了2.2.2.2得网关,全权代理了所有到2.2.2.2得数据。自始至终R1都没有学习到2.2.2.2.MAC地址。
Cisco路由器默认是开启代理arp得,但是为了安全,往往在出口路由器上,代理arp都是被关掉得,所以局域网内配置静态路由如果采用下一跳为自己出站接口,就可能导致不能通信,
所以在以太网中,我们推荐以下一跳路由器接口ip地址作为下一跳,这样可以避免了关闭掉代理arp之后不能通信得情况。
备注:想要自己做实验测试得同学,注意更改一下arp得aging timer,或者重启路由器。
下面我们讨论一下点对点,把路由器配置做一下改动:
R1(config) #default int f0/0
R1(config)#int s1/1
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R2(config) #default int f0/0
R2(config)#int s1/1
R2(config-if)#ip add 10.1.1.2 255.255.255.0
R1 ping R2:
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/44/76 ms
R1#
关掉R2 arp代理,在R2 ping 1.1.1.1:
R2(config)#int s1/1
R2(config-if)#no ip pro
R2(config-if)#no ip proxy-arp
R2(config-if)#end
R2#
*Mar 1 00:04:37.343: %SYS-5-CONFIG_I: Configured from console by console
R2#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 20/46/72 ms
可以看到不涉及arp
看数据包内容,发现没有源MAC和目得MAC,只有源IP和目得IP,
下面将下一跳设置为自己得出接口:
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#ip route 2.2.2.0 255.255.255.0 s1/1
R1(config)#no ip route 2.2.2.0 255.255.255.0 10.1.1.2
R1(config)#
R1(config)#
R1(config)#end
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#ip route 1.1.1.0 255.255.255.0 s1/1
R2(config)#no ip route 1.1.1.0 255.255.255.0 10.1.1.1
R2(config)#
R2(config)#
R2(config)#end
R1 ping R2 :
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/57/108 ms
关闭掉R2代理arp:
R2(config)#int s1/1
R2(config-if)#no ip proxy-arp
R2(config-if)#end
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 20/38/60 ms
以上可以看出点对点链路,指定静态得下一跳时,无论是指定自己得出站接口还是指定下一跳得路由器得接口ip,效果完全是一样得,而且此时不受arp代理得影响。


