CCNA的RIP路由学习

时间:2023-09-12 10:08:50

rip(routing infomation protocol,路由信息协议) ,是一个纯粹的距离矢量路由选择协议,RIP每隔30s就将自己完整的路由选择表从所有激活的接口上送出。RIP只将跳计数作为判断到达远程网络最佳路径的依据,并且在默认情况下允许最大的跳计数为15.也就是说,16就被认为不可达的。

RIP版本1只使用有类的路由选择,即网络中的所有设备都必须使用相同的子网掩码。这是因为RIP版本1在发送更新数据中不携带子网掩码信息。RIP版本2提供了前缀路由选择信息,并可以在路由更新中传送子网掩码信息,这就是无类的路由选择。

避免路由环路的四种办法:

1,水平分割,只朝一个方向广播数据更新。

2,最大跳数,设置最大跳数为15,则16跳就表示为不可达。

3,路由中毒,当网络出现故障时,通告网络的跳计数为16不可达。

4,保持关闭,保持关闭就是当有接口关闭并打开的时候,路由信息立即更新,然后又关闭,路由信息又立即更新。保持关闭可以阻止太频繁的路由改变。

RIP 例子

CCNA的RIP路由学习

router0 路由器配置:

Building configuration...

Current configuration : 637 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
no ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
ip address 172.16.1.254 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.12.1 255.255.255.0
duplex auto
speed auto
!
interface Vlan1
no ip address
shutdown
!
router rip
network 172.16.0.0
network 192.168.12.0
!
ip classless
!
ip flow-export version 9
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end

router1 的配置

Building configuration...

Current configuration :  bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
no ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/
ip address 192.168.23.2 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/
ip address 192.168.12.2 255.255.255.0
duplex auto
speed auto
!
interface Vlan1
no ip address
shutdown
!
router rip
network 192.168.12.0
network 192.168.23.0
!
ip classless
!
ip flow-export version
!
!
!
!
!
!
!
line con
!
line aux
!
line vty
login
!
!
!
end

router2的配置

Building configuration...

Current configuration :  bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
no ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface Loopback1
ip address 172.16.31.1 255.255.255.0
!
interface Loopback2
ip address 172.16.32.1 255.255.255.0
!
interface Loopback3
ip address 172.16.33.1 255.255.255.0
!
interface FastEthernet0/
ip address 192.168.23.3 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/
no ip address
duplex auto
speed auto
shutdown
!
interface Vlan1
no ip address
shutdown
!
router rip
network 172.16.0.0
network 192.168.23.0
!
ip classless
!
ip flow-export version
!
!
!
!
!
!
!
line con
!
line aux
!
line vty
login
!
!
!
end

测试:在Router1上ping172.16.1.254

Router#ping 172.16.1.254

Type escape sequence to abort.
Sending , -byte ICMP Echos to 172.16.1.254, timeout is seconds:
..!U!
Success rate is percent (/), round-trip min/avg/max = // ms

Router1上的路由表为:

Router#sh ip rou
Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 R 172.16.0.0/ [/] via 192.168.12.1, ::, FastEthernet0/
[/] via 192.168.23.3, ::, FastEthernet0/
C 192.168.12.0/ is directly connected, FastEthernet0/
C 192.168.23.0/ is directly connected, FastEthernet0/

到172.16.0.0的有两个路由,可以从192.168.12.1走,也可以从192.168.23.3 走,从而ping 172.16.1.254 可以从两条路线走,从而导致时通时坏。

Router0上的路由表为:

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 172.16.0.0/ is subnetted, subnets
C 172.16.1.0 is directly connected, FastEthernet0/
C 192.168.12.0/ is directly connected, FastEthernet0/
R 192.168.23.0/ [/] via 192.168.12.2, ::, FastEthernet0/

Router0上只有到达192.168.23.0的路由,没有学习到到Router3上的172.16.31.1,172.16.32.1,172.16.33.1 的路由。

Router2上的路由表为:

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 172.16.0.0/ is subnetted, subnets
C 172.16.31.0 is directly connected, Loopback1
C 172.16.32.0 is directly connected, Loopback2
C 172.16.33.0 is directly connected, Loopback3
R 192.168.12.0/ [/] via 192.168.23.2, ::, FastEthernet0/
C 192.168.23.0/ is directly connected, FastEthernet0/

Router2 也没有学习到Router0上的172.16.1.254 的网络。

Router1 上的sh ip protocol如下

Router#sh ip protocols
Routing Protocol is "rip"
Sending updates every seconds, next due in seconds
Invalid after seconds, hold down , flushed after
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Redistributing: rip
Default version control: send version , receive any version
Interface Send Recv Triggered RIP Key-chain
FastEthernet0/
FastEthernet0/
Automatic network summarization is in effect
Maximum path:
Routing for Networks:
192.168.12.0
192.168.23.0
Passive Interface(s):
Routing Information Sources:
Gateway Distance Last Update
192.168.12.1 ::
192.168.23.3 ::
Distance: (default is )

在Router1 上的RIP通过如下:

Router#debug ip rip
RIP protocol debugging is on
Router#RIP: received v1 update from 192.168.12.1 on FastEthernet0/
172.16.0.0 in hops
RIP: received v1 update from 192.168.23.3 on FastEthernet0/
172.16.0.0 in hops
RIP: sending v1 update to 255.255.255.255 via FastEthernet0/ (192.168.12.2)
RIP: build update entries
network 192.168.23.0 metric
RIP: sending v1 update to 255.255.255.255 via FastEthernet0/ (192.168.23.2)
RIP: build update entries
network 192.168.12.0 metric

在Router1上的通过为 收到router0 的172.16.0.0 的通告,也收到Router2的172.16.0.0 的通告。

在Router0 上的RIP通告如下:

Router#debug ip rip
RIP protocol debugging is on
Router#RIP: sending v1 update to 255.255.255.255 via FastEthernet0/ (172.16.1.254)
RIP: build update entries
network 192.168.12.0 metric
network 192.168.23.0 metric
RIP: sending v1 update to 255.255.255.255 via FastEthernet0/ (192.168.12.1)
RIP: build update entries
network 172.16.0.0 metric
RIP: received v1 update from 192.168.12.2 on FastEthernet0/
192.168.23.0 in hops

Router0 上的通过是发送172.16.0.0通告给Router1 路由器。根本没有收到172.16.31.0,172.16.32.0,172.16.33.0 的通告。为什么没有收到路由通告呢?原因是由于172.16.1.254是带有子网掩码的子类,被汇总为172.16.0.0/16了,要让网络正常,只能使用RIP v2.并且必须关闭自动汇总。

自动汇总:

RIP是一个有类路由协议,会在主类网络边界产生自动汇总。

什么是边界呢?当路由器从一个接口向外发送更新包时,如果要传送的路由与路由传播接口IP地址所在网络的主网络号不同,则路由器要把传送的路由汇总成主类网络在发送出去。

在Router0上有直连网络192.168.12.0/24和172.16.1.0/24两个主类网络的边界。

RIPv2将172.16.1.0/24这个网络宣告出去时,通过Fa0/1口。而Fa0/1的IP地址所在的主网络是192.168.12.0/24。

172.16.1.0/24与192.168.12.0/24不是同一个主网络号,所以172.16.1.0/24会汇总为172.16.0.0/16发送给Router1。

Router#debug ip rip
RIP protocol debugging is on
Router#RIP: sending v1 update to 255.255.255.255 via FastEthernet0/ (172.16.1.254)
RIP: build update entries
network 192.168.12.0 metric
network 192.168.23.0 metric
RIP: sending v1 update to 255.255.255.255 via FastEthernet0/ (192.168.12.1)
RIP: build update entries
network 172.16.0.0 metric 1
RIP: received v1 update from 192.168.12.2 on FastEthernet0/

如何让该网络保持正常通信,必须在每个路由器上的rip协议下关闭自动汇总。

命令为:

Router(config)#router rip
Router(config-router)#version 2 Router(config-router)#no auto-summary
 

重新配置后的路由器的路由表为:

router0 :

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 172.16.0.0/ is subnetted, subnets
C 172.16.1.0 is directly connected, FastEthernet0/
R 172.16.31.0 [/] via 192.168.12.2, ::, FastEthernet0/
R 172.16.32.0 [/] via 192.168.12.2, ::, FastEthernet0/
R 172.16.33.0 [/] via 192.168.12.2, ::, FastEthernet0/
C 192.168.12.0/ is directly connected, FastEthernet0/
R 192.168.23.0/ [/] via 192.168.12.2, ::, FastEthernet0/

router1:

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 172.16.0.0/ is variably subnetted, subnets, masks
R 172.16.0.0/ [/] via 192.168.12.1, ::, FastEthernet0/
[/] via 192.168.23.3, ::, FastEthernet0/
R 172.16.1.0/ [/] via 192.168.12.1, ::, FastEthernet0/
R 172.16.31.0/ [/] via 192.168.23.3, ::, FastEthernet0/
R 172.16.32.0/ [/] via 192.168.23.3, ::, FastEthernet0/
R 172.16.33.0/ [/] via 192.168.23.3, ::, FastEthernet0/
C 192.168.12.0/ is directly connected, FastEthernet0/
C 192.168.23.0/ is directly connected, FastEthernet0/

router2:

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 172.16.0.0/ is subnetted, subnets
R 172.16.1.0 [/] via 192.168.23.2, ::, FastEthernet0/
C 172.16.31.0 is directly connected, Loopback1
C 172.16.32.0 is directly connected, Loopback2
C 172.16.33.0 is directly connected, Loopback3
R 192.168.12.0/ [/] via 192.168.23.2, ::, FastEthernet0/
C 192.168.23.0/ is directly connected, FastEthernet0/

此时的router1 的路由通告如下:

Router#debug ip rip
RIP protocol debugging is on
Router#RIP: received v2 update from 192.168.12.1 on FastEthernet0/
172.16.1.0/ via 0.0.0.0 in hops
RIP: received v2 update from 192.168.23.3 on FastEthernet0/
172.16.31.0/ via 0.0.0.0 in hops
172.16.32.0/ via 0.0.0.0 in hops
172.16.33.0/ via 0.0.0.0 in hops
RIP: received v2 update from 192.168.12.1 on FastEthernet0/
172.16.1.0/ via 0.0.0.0 in hops
RIP: sending v2 update to 224.0.0.9 via FastEthernet0/ (192.168.12.2)
RIP: build update entries
172.16.31.0/ via 0.0.0.0, metric , tag
172.16.32.0/ via 0.0.0.0, metric , tag
172.16.33.0/ via 0.0.0.0, metric , tag
192.168.23.0/ via 0.0.0.0, metric , tag
RIP: sending v2 update to 224.0.0.9 via FastEthernet0/ (192.168.23.2)
RIP: build update entries
172.16.1.0/ via 0.0.0.0, metric , tag
192.168.12.0/ via 0.0.0.0, metric , tag

router0 的RIP通告为

Router#debug ip rip
RIP protocol debugging is on
Router#RIP: received v2 update from 192.168.12.2 on FastEthernet0/
172.16.31.0/ via 0.0.0.0 in hops
172.16.32.0/ via 0.0.0.0 in hops
172.16.33.0/ via 0.0.0.0 in hops
192.168.23.0/ via 0.0.0.0 in hops
RIP: sending v2 update to 224.0.0.9 via FastEthernet0/ (172.16.1.254)
RIP: build update entries
172.16.31.0/ via 0.0.0.0, metric , tag
172.16.32.0/ via 0.0.0.0, metric , tag
172.16.33.0/ via 0.0.0.0, metric , tag
192.168.12.0/ via 0.0.0.0, metric , tag
192.168.23.0/ via 0.0.0.0, metric , tag
RIP: sending v2 update to 224.0.0.9 via FastEthernet0/ (192.168.12.1)
RIP: build update entries
172.16.1.0/ via 0.0.0.0, metric , tag

注:ip cef 和 no ip cef 的区别是,开启ip cef 可以直接在cef表查找是否有对应项,关闭ip cef则需要通过ARP协议查找mac地址是否对应。

什么时候需要开启自动汇总?而什么时候需要关闭自动汇总?

总结:在RIPv1有类路由的情况下开启自动汇总,RIPv1不支持VLSM,不携带子网掩码,在RIPv2中有子网存在的网络中需要关闭自动汇总,VLSM也必须关闭自动汇总,在路由的两端都出现相同网段的子网。

举个例子:R0:192.168.1.1/26, 192.168.30.1  R1:192.168.30.2/24 ,192.16.1.2/24  R2:192.16.1.3 ,192.168.1.252/26.

关闭自动汇总则能学习到完整的路由,没有关闭自动汇总则被汇总为192.168.1.0/24的网络,则中间路由学习到192.168.1.0 的路由指向为两个路由器。这样会导致路由环路,时断时好。路由表如下:

没关自动汇总路由:

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 C 192.16.10.0/ is directly connected, FastEthernet0/
R 192.168.1.0/ [/] via 192.168.30.2, ::, FastEthernet0/
[/] via 192.16.10.2, ::, FastEthernet0/
R 192.168.2.0/ [/] via 192.16.10.2, ::, FastEthernet0/
C 192.168.30.0/ is directly connected, FastEthernet0/

关闭之后的自动汇总:

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type , N2 - OSPF NSSA external type
E1 - OSPF external type , E2 - OSPF external type , E - EGP
i - IS-IS, L1 - IS-IS level-, L2 - IS-IS level-, 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 C 192.16.10.0/ is directly connected, FastEthernet0/
192.168.1.0/ is subnetted, subnets
R 192.168.1.192 [/] via 192.16.10.2, ::, FastEthernet0/
R 192.168.2.0/ [/] via 192.16.10.2, ::, FastEthernet0/
C 192.168.30.0/ is directly connected, FastEthernet0/

关闭之后网络恢复正常。

有一个问题,就是r0有192.168.1.0的网段,中间连接r1,在连接一个r2,r2上也有192.168.1.0的网段,如果在r1与192.168.1.0的网段通信则会一会掉一会好。

最后补充一下:

子网就是比如A类的10.10.10.1子网掩码是255.255.255.0.(10.10.10.0/24或者/16)

B类的172.16.110.0/24这样。

C类 192.168.1.1/26.(自动汇总为192.168.1.0/24)