1.实验目的
通过本实验可以掌握
① 在路由器上 OSPF路由进程;
② 启用参与路由协议的接口,并且通告网络及所在的区域;
③ 度量值 Cost的计算;
④ Hello 相关参数的配置;
⑤ 点到点链路上的 OSPF特征;
⑥ 查看和调试 OSPF路由协议相关信息。
2.实验拓扑
本实验的拓扑结构图如图6-1所示。
 

图6-1    点到点链路上的OSPF
3.实验步骤
(1)步骤1:配置路由器R1
R1(config)#int lo 0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#int s0/0
R1(config-if)#ip add 192.168.12.1 255.255.255.0
R1(config-if)#clock rate 64000
R1(config-if)#no shut
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1 
R1(config-router)#network 1.1.1.0 255.255.255.0 area 0
R1(config-router)#network 192.168.12.0 255.255.255.0 area 0
 

(2)步骤2:配置路由器R2
 R2(config)#int lo 0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#int s0/0
R2(config-if)#ip add 192.168.12.2 255.255.255.0
R2(config-if)#clock rate 64000
R2(config-if)#no shut
R2(config-if)#int s0/1
R2(config-if)#ip add 192.168.23.1 255.255.255.0
R2(config-if)#clock rate 64000
R2(config-if)#no shut
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 192.168.12.0 255.255.255.0 area 0
R2(config-router)#network 192.168.23.0 255.255.255.0 area 0
R2(config-router)#network 2.2.2.0 255.255.255.0 area 0
 

 

 

(3)
步骤3:配置路由器R3
R3(config)#int lo 0
R3(config-if)#ip add 3.3.3.3 255.255.255.0
R3(config-if)#no shut
R3(config-if)#int s0/1
R3(config-if)#ip add 192.168.23.2 255.255.255.0
R3(config-if)#clock rate 64000
R3(config-if)#no shut
R3(config-if)#int s0/2
R3(config-if)#ip add 192.168.34.1 255.255.255.0
R3(config-if)#clock rate 64000
R3(config-if)#no shut
R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 192.168.23.0 255.255.255.0 area 0
R3(config-router)#network 192.168.34.0 255.255.255.0 area 0
R3(config-router)#network 3.3.3.3 255.255.255.0 area 0
 

 
 
(4)步骤4:配置路由器R4
R4(config)#int lo 0
R4(config-if)#ip add 4.4.4.4 255.255.255.0
R4(config-if)#no shut
R4(config-if)#int s0/2
R4(config-if)#ip add 192.168.34.2 255.255.255.0
R4(config-if)#clock rate 64000
R4(config-if)#no shut
R4(config)#router ospf 1
R4(config-router)#router-id 4.4.4.4
R4(config-router)#network 4.4.4.0 0.0.0.255 area 0
R4(config-router)#network 192.168.34.0 0.0.0.255 area 0
 

 
 
 
【技术要点】
① OSPF路由进程ID 的范围必须是在 1~65535之间,而且只有本地含义,不同路由器的路由进程 ID 可以不同,如果要想启动OFPS路由进程,至少确保有一个接口是up 的;
② 区域 ID 是在0~4 294 967 295内的十进制数,也可以是 IP 地址格式A.B.C.D,当网络区域 ID 为 0或 0.0.0.0时称为
主干区域;
③ 在高版本的 IOS 中通告OFPF网络的时候,网络号的后面可以跟网络掩码,也可以跟跟反掩码;
④ 确定Router ID 遵循如下顺序:
? 最优先的是在OSPF进程中用命令”router-id”指定了路由器 ID;
? 如果没有在 OSPF进程中指定路由器 ID,那么把选择IP 地址最大的环回接口的 IP 地址为 Router ID;
? 如果没有环回接口,就选择最大活动的物理接口的 IP 地址为Router ID,建议用命令”router-id”来指定路由器ID,
这样可控性比较好。

4.实验调试

1show ip route 

R2#show 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

        ia - IS-IS inter area  * - candidate default  U - per-user sta

        o - ODR  P - periodic downloaded static route

 

Gateway of last resort is not set

 

C    192.168.12.0/24 is directly connected  Serial0/0/0

      1.0.0.0/32 is subnetted  1 subnets

O       1.1.1.1 [110/65] via 192.168.12.1  00;07;27  Serial0/0/0

      2.0.0.0/24 is subnetted  1 subnets

C       2.2.2.0 is directly connected  Loopback0

      3.0.0.0/32 is subnetted  1 subnets

O       3.3.3.3 [110/65] via 192.168.23.2  00;07;27  Serial0/0/1

      4.0.0.0/32 is subnetted  1 subnets

O       4.4.4.4 [110/129] via 192.168.23.2  00;07;27  Serial0/0/1

C    192.168.23.0/24 is directly connected  Serial0/0/1

O    192.168.34.0/24 [110/128] via 192.168.23.2  00;07;27  Serial0/0/1

 

输出结果表明同一个区域内通过OSPF路由协议学习的路由条目用代码”O”表示。

【说明】

  环回接口OSPF路由条目的掩码长度都是 32位,这是环回接口的特性,尽管通告了 24位。解决的办法是在环回接口下修改网络类型为”Point-to-Point ,操作如下:

R2(config)#interface loopback 0

R2(config-if)#ip ospf network point-to-point

这样收到的路由条目的掩码长度和通告的就一致了。