今天为了让学生更理解路由表.出了这样一个实验.两台路由器R1-------R2,用F0/0互联,然后每台路由器上都有一个loopback0,地址分别为1.1.1.1/32和2.2.2.2/32.而R1的f0/0地址为192.168.1.1/24.R2地址为172.16.1.1/24.实验要求很简单,R1 R2直连不能ping通,但是要求通过RIP协议让两台路由器学到对端的地址.
很多学生想法都是,用RIPv1,这样广播更新对端肯定能学到路由,但是经过实验以后发现其实是不能的.
现在我来解释下为什么,和如何去实现.
先看下简单的配置:
R1(config-if)#do sh cdp nei
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater
Device ID Local Intrfce Holdtme Capability Platform Port ID
R2 Fas 0/0 175 R S I 2691 Fas 0/0
R2 Fas 0/0 175 R S I 2691 Fas 0/0
R1能够看到R2的CDP信息,说明接口已经没问题了.
接下来看地址信息.
R1(config-if)#do sh run int f0/0
Building configuration...
Building configuration...
Current configuration : 96 bytes
!
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
end
R1(config-if)#do sh run int lo 0
Building configuration...
!
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
end
R1(config-if)#do sh run int lo 0
Building configuration...
Current configuration : 63 bytes
!
interface Loopback0
ip address 1.1.1.1 255.255.255.255
R1的F0/0地址为192.168.1.1/24 loopback0地址为1.1.1.1/32
!
interface Loopback0
ip address 1.1.1.1 255.255.255.255
R1的F0/0地址为192.168.1.1/24 loopback0地址为1.1.1.1/32
R2(config-if)#do sh run int f0/0
Building configuration...
Building configuration...
Current configuration : 95 bytes
!
interface FastEthernet0/0
ip address 172.16.1.1 255.255.255.0
duplex auto
speed auto
end
!
interface FastEthernet0/0
ip address 172.16.1.1 255.255.255.0
duplex auto
speed auto
end
R2(config-if)#do sh run int lo0
Building configuration...
Building configuration...
Current configuration : 63 bytes
!
interface Loopback0
ip address 2.2.2.2 255.255.255.255
end
!
interface Loopback0
ip address 2.2.2.2 255.255.255.255
end
R2的F0/0地址为172.16.1.1/24 loopback0地址为2.2.2.2/32
这里直连肯定不通,我就不去测试了.
接下来起RIP动态路由选择协议.
R1(config-if)#router rip
R1(config-router)#network 192.168.1.0
R1(config-router)#network 1.0.0.0
R1(config-router)#network 192.168.1.0
R1(config-router)#network 1.0.0.0
R2(config-if)#router rip
R2(config-router)#network 172.16.0.0
R2(config-router)#network 2.0.0.0
R2(config-router)#network 172.16.0.0
R2(config-router)#network 2.0.0.0
再去检查路由表
R1(config-router)#do sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 1.1.1.1 is directly connected, Loopback0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
这个时候发现路由表里面不存在2.0.0.0/8的路由,那么R1是否收到了路由更新呢.
R1#debug ip rip
RIP protocol debugging is on
R1#
*Mar 1 00:06:00.675: RIP: ignored v1 update from bad source 172.16.1.1 on FastEthernet0/0
RIP protocol debugging is on
R1#
*Mar 1 00:06:00.675: RIP: ignored v1 update from bad source 172.16.1.1 on FastEthernet0/0
通过debug ip rip可以看到R1的确收到了这样一条路由更新,但是由于是来自错误的源172.16.1.1,所以被忽略了.
这里有这样一个特性:路由器在收到路由更新的时候会去检查更新源,如果更新源(下一跳)不可达,那么路由器将会忽略该路由条目.
例如我们在写静态路由的时候 ip route 2.2.2.2 255.255.255.255 172.16.1.1
如果下一条地址在路由表中不可达,那么该静态路由一样不会进入我们的路由表.
现在已经知道了原因,那么如何去使R1能够学到路由呢?
其实很简单,只要让R1在收到路由更新的时候不去检查更新源就可以了.
命令如下:
R1(config)#router rip
R1(config-router)#no validate-update-source
R1(config-router)#no validate-update-source
最后我们在去看下路由表:
R1(config-router)#do sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
R 2.0.0.0/8 [120/1] via 172.16.1.1, 00:00:22
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 1.1.1.1 is directly connected, Loopback0
R 2.0.0.0/8 [120/1] via 172.16.1.1, 00:00:22
C 192.168.1.0/24 is directly connected, FastEthernet0/0
这个时候我们发现.虽然下一跳地址172.16.1.1不可达,但是只要是R1学到的路由条目,他就会放入路由表.但是R1是无法ping通2.2.2.2的.
总结:
这个实验没有任何实际性意义,但是他解释了路由其在抉择路由条目是否添加到路由表中的工作原理.
希望对大家的路由学习有帮助.







发表评论 评论 (18 个评论)