借助Cisco Packet Tracer理解RIP路由协议

本文展示了在Cisco Packet Tracer搭建一个简单的网络PC1--R1--R2--PC2,参数的设置,包括RIP路由协议。并介绍一些命令查看路由相关信息。

1. 搭建网络

1.1 建立网络拓扑结构

首先,建立网络拓扑,如下图所示(路由器型号为4321)。

网络拓扑示意图
图1 网络拓扑示意图

PS:做实验时,建议把纸把网络拓扑图画出来,并在上面标上接口、IP地址信息。这样,不仅可以更快进行后面的参数配置,而且还不容易出错。

1.2 终端配置

终端配置如下,以PC1为例,值得注意的下,需要设置默认网关。

终端配置示意图
图2 终端配置示意图

1.3 路由器基本配置

使用命令erase startup-config清除路由器上的现有配置:

Router>enable                           # 进入特权执行模式
Router#erase startup-config             # 清除路由器上的现有配置
Router#configure terminal               # 进入全局配置模式
Router(config)#no ip domain-lookup      # 禁用DNS查找

Router(config)#hostname R1              # 修改路由器名称
R1(config)#end

在实验环境中禁用DNS查找的目的是提高操作响应时间,因为键入错误的命令,路由器会把错误命令当成域名进行查找。

使用命令copy running-config startup-config可以保存配置文件。关于配置文件保存与恢复,见另一篇博文Cisco路由器从配置文件加载及恢复出厂设置

R1#copy running-config startup-config       # 保存配置文件
Destination filename [startup-config]? 
Building configuration...

1.4 配置并激活路由器接口

使用命令show ip interface brief查看路由器上的接口IP相关信息:

R1#show ip interface brief
Interface              IP-Address      OK? Method Status              Protocol 
GigabitEthernet0/0/0   unassigned      YES unset  administratively down down 
GigabitEthernet0/0/1   unassigned      YES unset  administratively down down 
Vlan1                  unassigned      YES unset  administratively down down

可以看出该路由器有两个吉以太网口G0/0/0和G0/0/1,Vlan1实为交换机接口,用于将两层交换机连到三层路由器[1]

R1

接口g0/0/0,指定IP地址,并激活接口:

R1(config)#interface g0/0/0
R1(config-if)#ip address 192.168.1.80 255.255.255.0
R1(config-if)#no shutdown

%LINK-5-CHANGED: Interface GigabitEthernet0/0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0/0, changed state to up

接口g0/0/1:

R1(config)#interface g0/0/1
R1(config-if)#ip addr 192.168.2.79 255.255.255.0
R1(config-if)#no shutdown

%LINK-5-CHANGED: Interface GigabitEthernet0/0/1, changed state to up

使用命令show ip interface brief再次查看接口IP相关信息,确保接口配置正确。

R1#show ip interface brief
Interface              IP-Address      OK? Method Status              Protocol 
GigabitEthernet0/0/0   192.168.1.80    YES manual up                    up 
GigabitEthernet0/0/1   192.168.2.79    YES manual up                    up 

R2

Router>enable
Router#config t 
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#hostname R2

R2(config)#interface g0/0/0
R2(config-if)#ip addr 192.168.2.80 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit

R2(config)#interface g0/0/1
R2(config-if)#ip addr 192.168.3.79 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#exit

R2#sh ip int b
Interface              IP-Address      OK? Method Status              Protocol 
GigabitEthernet0/0/0   192.168.2.80    YES manual up                    up 
GigabitEthernet0/0/1   192.168.3.79    YES manual up                    up 
Vlan1                  unassigned      YES unset  administratively down down

每一列的含义如下表,官方文档在这里

Show ip interface brief Field Description.png
图3 命令show ip interface brief返回结果释义

1.5 配置路由协议

R1(config)#router rip                   # 进入路由配置模式,在路由器使用RIP
R1(config-router)#version 2             # RIP版本
R1(config-router)#network 192.168.1.0
R1(config-router)#network 192.168.2.0

R2(config)#route rip
R2(config-router)#version 2
R2(config-router)#network 192.168.2.0
R2(config-router)#network 192.168.3.0

network ip-address命令用于发布网段,其作用如下:

  • 对属于该网络的所有接口启用RIP。这些接口将开始发送和接收RIP更新
  • 在每30秒一次的RIP路由更新中向其它路由器通告该网络

Specifies a list of networks on which RIP is to be applied, using the address of the network of each directly connected network.

还有一个命令no auto-summary用于关闭路由聚合功能。

Disables automatic summarization of subnet routes into network-level routes. This allows subprefix routing information to pass across classful network boundaries.

1.6 测试连通性

在PC端PING服务端,成功表示整个网络都是连通的。

C:\>ping 192.168.3.80

Pinging 192.168.3.80 with 32 bytes of data:

Reply from 192.168.3.80: bytes=32 time<1ms TTL=126
Reply from 192.168.3.80: bytes=32 time<1ms TTL=126
Reply from 192.168.3.80: bytes=32 time<1ms TTL=126
Reply from 192.168.3.80: bytes=32 time<1ms TTL=126

Ping statistics for 192.168.3.80:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

2. 分析

2.1 查看路由表

没给路由器R1R2设置路由协议,通过命令show ip route查看到的路由表如下:

R1>show ip route
Codes: L - local, 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, 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

     192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.1.0/24 is directly connected, GigabitEthernet0/0/0
L       192.168.1.80/32 is directly connected, GigabitEthernet0/0/0
     192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.2.0/24 is directly connected, GigabitEthernet0/0/1
L       192.168.2.79/32 is directly connected, GigabitEthernet0/0/1

R1R2配置路由协议后,show ip route查看到的路由表如下:

R1#show ip route
...
Gateway of last resort is not set

     192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.1.0/24 is directly connected, GigabitEthernet0/0/0
L       192.168.1.80/32 is directly connected, GigabitEthernet0/0/0
     192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.2.0/24 is directly connected, GigabitEthernet0/0/1
L       192.168.2.79/32 is directly connected, GigabitEthernet0/0/1
R    192.168.3.0/24 [120/1] via 192.168.2.80, 00:00:04, GigabitEthernet0/0/1

R2#show ip route
...
Gateway of last resort is not set

R    192.168.1.0/24 [120/1] via 192.168.2.79, 00:00:08, GigabitEthernet0/0/0
     192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.2.0/24 is directly connected, GigabitEthernet0/0/0
L       192.168.2.80/32 is directly connected, GigabitEthernet0/0/0
     192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.3.0/24 is directly connected, GigabitEthernet0/0/1
L       192.168.3.79/32 is directly connected, GigabitEthernet0/0/1

R1R2分别有一条路由,以R1为例,R 192.168.3.0/24 [120/1] via 192.168.2.80, 00:00:04, GigabitEthernet0/0/1,各字段含义分别如下:

  • R:路由协议RIP
  • 192.168.3.0/24:目的网络
  • 120/1:120表示Administrative Distance,1表示跳数
  • via 192.168.2.80:下一跳路由器的接口
  • 00:00:04:上一次路由更新的时间(时:分:秒)
  • GigabitEthernet0/0/1:从接口G0/0/1转发

Administrative Distance用于选择最佳路径(the best path)的首要标准,值越小,表示路由协议越可靠。详情见What Is Administrative Distance? – Cisco

For example, if a router receives a route to a certain network from both Open Shortest Path First (OSPF) (default administrative distance – 110) and Interior Gateway Routing Protocol (IGRP) (default administrative distance – 100), the router chooses IGRP because IGRP is more reliable. This means the router adds the IGRP version of the route to the routing table.

2.2 查看路由协议参数及状态

没给路由器R1R2设置路由协议,通过命令show ip protocols查看路由协议参数及状态的值为空。R1R2设置路由协议后,show ip protocols返回结果如下。

R1

R2#show ip protocols
Routing Protocol is "rip"
Sending updates every 30 seconds, next due in 0 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 2, receive 2
  Interface             Send  Recv  Triggered RIP  Key-chain
  GigabitEthernet0/0/0  2     2     
  GigabitEthernet0/0/1  2     2     
Automatic network summarization is in effect
Maximum path: 4
Routing for Networks:
    192.168.2.0
    192.168.3.0
Passive Interface(s):
Routing Information Sources:
    Gateway         Distance      Last Update
    192.168.2.79         120      00:00:33
Distance: (default is 120)

R2

R2#show ip protocols
Routing Protocol is "rip"
Sending updates every 30 seconds, next due in 0 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 2, receive 2
  Interface             Send  Recv  Triggered RIP  Key-chain
  GigabitEthernet0/0/0  2     2     
  GigabitEthernet0/0/1  2     2     
Automatic network summarization is in effect
Maximum path: 4
Routing for Networks:
    192.168.2.0
    192.168.3.0
Passive Interface(s):
Routing Information Sources:
    Gateway         Distance      Last Update
    192.168.2.79         120      00:00:33
Distance: (default is 120)

2.3 显示RIP数据库

使用命令show ip rip database,显示RIP数据库。详见见Cisco IOS IP Routing: RIP Command Reference – RIP Commands [Support] – Cisco

R1#show ip rip database
192.168.1.0/24    auto-summary
192.168.1.0/24    directly connected, GigabitEthernet0/0/0
192.168.2.0/24    auto-summary
192.168.2.0/24    directly connected, GigabitEthernet0/0/1
192.168.3.0/24    auto-summary
192.168.3.0/24
    [1] via 192.168.2.80, 00:00:08, GigabitEthernet0/0/1

R2>show ip rip database
192.168.1.0/24    auto-summary
192.168.1.0/24
    [1] via 192.168.2.79, 00:00:22, GigabitEthernet0/0/0
192.168.2.0/24    auto-summary
192.168.2.0/24    directly connected, GigabitEthernet0/0/0
192.168.3.0/24    auto-summary
192.168.3.0/24    directly connected, GigabitEthernet0/0/1

2.4 调试RIP

通过命令debugundebug可以来查看发送和接收RIP报文。

R1#debug ip rip
RIP protocol debugging is on

R1#undebug all             # 停止调试输出
All possible debugging has been turned off

3. 验证坏消息传得慢

关闭(shutdown)R1接口G0/0/0,通过调试(debug ip rip)在R1查看发送和接收的RIP报文。

References:

[1] What is VLAN1 interface in routers?

[2] Cisco CPT Command Reference Guide CTC and Documentation Release 9.3 and Cisco IOS Release 15.1(01)SA – Miscellaneous Command Reference [Cisco Carrier Packet Transport (CPT) System] – Cisco

[3] Basic Router Configuration, Configuring Routing Information Protocol – Cisco

赞赏

微信赞赏支付宝赞赏

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注