数码产品

CCNA的RIP路由学习

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

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

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

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

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

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

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

 

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 : 639 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 192.168.23.2 255.255.255.0
 duplex auto
 speed auto
!
interface FastEthernet0/1
 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 9
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
 login
!
!
!
end
View Code

router2的配置

Building configuration...

Current configuration : 803 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/0
 ip address 192.168.23.3 255.255.255.0
 duplex auto
 speed auto
!
interface FastEthernet0/1
 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 9
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
 login
!
!
!
end
View Code

 

测试:在Router1上ping172.16.1.254 

Router#ping 172.16.1.254

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.254, timeout is 2 seconds:
..!U!
Success rate is 40 percent (2/5), round-trip min/avg/max = 2/3/2 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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

R    172.16.0.0/16 [120/1] via 192.168.12.1, 00:00:22, FastEthernet0/1
                   [120/1] via 192.168.23.3, 00:00:27, FastEthernet0/0
C    192.168.12.0/24 is directly connected, FastEthernet0/1
C    192.168.23.0/24 is directly connected, FastEthernet0/0

到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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

     172.16.0.0/24 is subnetted, 1 subnets
C       172.16.1.0 is directly connected, FastEthernet0/0
C    192.168.12.0/24 is directly connected, FastEthernet0/1
R    192.168.23.0/24 [120/1] via 192.168.12.2, 00:00:07, FastEthernet0/1

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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

     172.16.0.0/24 is subnetted, 3 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/24 [120/1] via 192.168.23.2, 00:00:07, FastEthernet0/0
C    192.168.23.0/24 is directly connected, FastEthernet0/0

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

 

Router1 上的sh ip protocol如下

Router#sh ip protocols 
Routing Protocol is "rip"
Sending updates every 30 seconds, next due in 2 seconds
Invalid after 180 seconds, hold down 180, flushed after 240
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 1, receive any version
  Interface             Send  Recv  Triggered RIP  Key-chain
  FastEthernet0/1       1     2 1   
  FastEthernet0/0       1     2 1   
Automatic network summarization is in effect
Maximum path: 4
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         120      00:00:22
    192.168.23.3         120      00:00:27
Distance: (default is 120)

在Router1 上的RIP通过如下:

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

在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/0 (172.16.1.254)
RIP: build update entries
      network 192.168.12.0 metric 1
      network 192.168.23.0 metric 2
RIP: sending  v1 update to 255.255.255.255 via FastEthernet0/1 (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/1
      192.168.23.0 in 1 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/0 (172.16.1.254)
RIP: build update entries
      network 192.168.12.0 metric 1
      network 192.168.23.0 metric 2
RIP: sending  v1 update to 255.255.255.255 via FastEthernet0/1 (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/1

如何让该网络保持正常通信,必须在每个路由器上的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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

     172.16.0.0/24 is subnetted, 4 subnets
C       172.16.1.0 is directly connected, FastEthernet0/0
R       172.16.31.0 [120/2] via 192.168.12.2, 00:00:23, FastEthernet0/1
R       172.16.32.0 [120/2] via 192.168.12.2, 00:00:23, FastEthernet0/1
R       172.16.33.0 [120/2] via 192.168.12.2, 00:00:23, FastEthernet0/1
C    192.168.12.0/24 is directly connected, FastEthernet0/1
R    192.168.23.0/24 [120/1] via 192.168.12.2, 00:00:23, FastEthernet0/1

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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

     172.16.0.0/16 is variably subnetted, 5 subnets, 2 masks
R       172.16.0.0/16 [120/1] via 192.168.12.1, 00:02:04, FastEthernet0/1
                      [120/1] via 192.168.23.3, 00:01:48, FastEthernet0/0
R       172.16.1.0/24 [120/1] via 192.168.12.1, 00:00:14, FastEthernet0/1
R       172.16.31.0/24 [120/1] via 192.168.23.3, 00:00:23, FastEthernet0/0
R       172.16.32.0/24 [120/1] via 192.168.23.3, 00:00:23, FastEthernet0/0
R       172.16.33.0/24 [120/1] via 192.168.23.3, 00:00:23, FastEthernet0/0
C    192.168.12.0/24 is directly connected, FastEthernet0/1
C    192.168.23.0/24 is directly connected, FastEthernet0/0

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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

     172.16.0.0/24 is subnetted, 4 subnets
R       172.16.1.0 [120/2] via 192.168.23.2, 00:00:20, FastEthernet0/0
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/24 [120/1] via 192.168.23.2, 00:00:20, FastEthernet0/0
C    192.168.23.0/24 is directly connected, FastEthernet0/0

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

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

router0 的RIP通告为

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

注: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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

C    192.16.10.0/24 is directly connected, FastEthernet0/1
R    192.168.1.0/24 [120/1] via 192.168.30.2, 00:00:23, FastEthernet0/0
                    [120/1] via 192.16.10.2, 00:00:08, FastEthernet0/1
R    192.168.2.0/24 [120/1] via 192.16.10.2, 00:00:08, FastEthernet0/1
C    192.168.30.0/24 is directly connected, FastEthernet0/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 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, 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

C    192.16.10.0/24 is directly connected, FastEthernet0/1
     192.168.1.0/26 is subnetted, 1 subnets
R       192.168.1.192 [120/1] via 192.16.10.2, 00:00:10, FastEthernet0/1
R    192.168.2.0/24 [120/1] via 192.16.10.2, 00:00:10, FastEthernet0/1
C    192.168.30.0/24 is directly connected, FastEthernet0/0

关闭之后网络恢复正常。

 

有一个问题,就是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)

 

posted @ 2016-08-03 22:02  Hackerman  阅读(1719)  评论(0编辑  收藏  举报
数码产品