动态路由协议
动态路由协议
动态路由协议包括距离向量路由协议和链路状态路由协议。,本实 验文档主要介绍 RIP 和 OSPF 两类动态路由协议。
RIP 概述
RIP 是由 Xerox 在 70 年代开发的,最初定义在 RFC1058 中。RIP 用两种数据包传输更新:更新和请求,每个有 RIP 功能的 路由器默认情况下每隔 30 秒,利用 UDP 520 端口向与它直连的 网络邻居广播(RIP v1)或组播(RIP v2)路由更新。因此路由
器不知道网络的全局情况,如果路由更新在网络上传播慢,将会导致 网络收敛较慢,造成路由环路。为了避免路由环路,RIP 采用水平 分割、毒性逆转、定义最大跳数、触发更新、抑制计时 5 个机制来
避免路由环路。
RIP 协议分为版本 1 和版本 2。不论是版本 1 或版本 2,都具备 下面的特征:
-
是距离向量路由协议;
-
使用跳数(Hop Count)作为度量值;
3.默认路由更新周期为 30 秒; -
管理距离(AD)为 120;
-
支持触发更新;
-
最大跳数为 15 跳;
-
支持等价路径,默认 4 条,最大 6 条;
-
使用 UDP520 端口进行路由更新。
-
实验拓扑:
RIP 拓扑图
(1)首先基本的接口 IP 地址配置,以及测试直连连通性。
(2)如同静态路由实验的情况一样,PC0 要 ping 通 PC1,则数据 包去到路由器上时会查看路由表,在没配静态路由的情况下,路由器
上是没有目的网段的路由,数据包会在路由器上丢包,为解决这一问 题,可以用动态路由协议 RIP。
下面以 R1 的配置为例子来说明:
R1(config)#router rip
R1(config-router)#version 1(也可以是 version 2,两者区别在于是 否携带子网掩码)
R1(config-router)#network 10.0.0.0 (network 时用主类网段,
即 A/B/C 类网段)
R1(config-router)#network 192.168.12.0
查看: 版本 1
R1#show ip protocols Routing Protocol is “rip”
Sending updates every 30 seconds, next due in 17 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 1 Interface Send Recv Triggered RIP Key-chain FastEthernet0/1 1 1
FastEthernet0/0 1 1
Automatic network summarization is in effect Maximum path: 4
Routing for Networks: 10.0.0.0
192.168.12.0
Passive Interface(s): Routing Information Sources:
Gateway Distance Last Update Distance: (default is 120)
R1#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
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/1
R 20.0.0.0/8 [120/2] via 192.168.12.2, 00:00:10,
FastEthernet0/0
R 172.16.0.0/16 [120/1] via 192.168.12.2, 00:00:10,
FastEthernet0/0
C 192.168.12.0/24 is directly connected, FastEthernet0/0
可以发现路由器上已经学习到目标网段的路由。如果一开始的时 候没有出现两条R的记录,也是正常,因为你没有执行过Ping的 操作,路由器是不会自动添加的。当你完成了ping的操作以后, 就会动态的添加对应的路由表信息。这就是所谓的动态路由。
然后按照同样的方法配置 R2 和 R3,发现同样的情况也会在 R2
和 R3 出现。
版本 2
R1#show ip protocols
Routing Protocol is “rip”
Sending updates every 30 seconds, next due in 12 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 FastEthernet0/1 2 2
FastEthernet0/0 2 2
Automatic network summarization is in effect Maximum path: 4
Routing for Networks: 10.0.0.0
192.168.12.0
Passive Interface(s): Routing Information Sources:
Gateway Distance Last Update Distance: (default is 120)
路由表也版本 1 一样
可以通过查看 R1、R2、R3 上的路由表是否都有目标网段的地址,如 果都有则实验成功,成功后:
注意:配置完动态路由协议后,第一次Ping的时候可能会出现 “Request timed out”的情况,是属于正常的,因为,路由器 “学习”需要一定的时间。
OSPF 概述
OSPF 作 为 一 种 内 部 网 关 协 议 ( Interior Gateway Protocol,IGP),用于在同一个自治 系统(AS)中的路由器之间交换路由信息。OSPF 的特性如下:
-
可适应大规模网络;
-
收敛速度快;
-
无路由环路;
-
支持 VLSM 和 CIDR; 5. 支持等价路由;
-
支持区域划分, 构成结构化的网络;
-
提供路由分级管理;
-
支持简单口令和 MD5 认证;
-
以组播方式传送协议报文;
-
OSPF 路由协议的管理距离是 110;
-
OSPF 路由协议采用 cost 作为度量标准;
-
OSPF 维护邻居表、拓扑表和路由表。
-
实验拓扑:
OSPF 拓扑图
实验与 RIP 基本一致,不同在于使用的路由协议不一样而已
R1(config)#router ospf 1 (OSPF 进程号一定要有)
R1(config-router)#router-id 1.1.1.1 (给该进程一个 RID,自己取 一个 IPV4 的地址,每台路由器要不一样的 RID)
R1(config-router)#network 10.1.1.0 0.0.0.255 area 0 (宣告
网段,路由表上是多少位子网,宣告时就要宣告多少位,如 10.1.1.0 网段是 24 位, network 宣告就是 10.1.1.0;而后面是反掩码,简单理解就是掩码反过来,即 24 位掩 码是 255.255.255.0,反过来就是 0.0.0.255;再后面是区域号,因为 OSPF 是分区域 的,所以一定要有区域号,一般简单实验只需用一个区域 0 即可)
R1(config-router)#network 192.168.12.0 0.0.0.255 area 0
OSPF 邻居建立起来时会看到:
00:46:45: %OSPF-5-ADJCHG: Process 1, Nbr 2.2.2.2 on
FastEthernet0/0 from LOADING to FULL, Loading Done
可通过查看命令:
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/BDR 00:00:33 192.168.12.2 FastEthernet0/0
Full 即 OSPF 建立起来
查看路由表:
R1#show 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
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/1 20.0.0.0/24 is subnetted, 1 subnets
O 20.1.1.0 [110/3] via 192.168.12.2, 00:02:00,
FastEthernet0/0
172.16.0.0/24 is subnetted, 1 subnets
O 172.16.23.0 [110/2] via 192.168.12.2, 00:03:08,
FastEthernet0/0
C 192.168.12.0/24 is directly connected, FastEthernet0/0
- candidate default, U - per-user static route, o -
查看路由表发现目标网段路由已经在路由表上,按照要求配置 R2
和 R3,发现同样情况也会发生在 R2 和 R3 上,则实验成功,成功后: