实验设计与排错之四OSPF配置、分析与排错
1、OSPF协议简述
OSPF(开放最短路径优先)是一种内部网关协议。不同于IGRP,OSPF是一种无类链路状态路由选择协议,而不是一种分类距离矢量协议。OSPF被标准化,广泛用于公共和私有网络中。下面简单介绍一下链路状态路由协议工作过程,如下:
目前创新互联已为上千多家的企业提供了网站建设、域名、虚拟主机、网站改版维护、企业网站设计、乐都网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
每台路由器学习激活的直接相连的网络。
每台路由器和直接相连的路由器互交,发送Hello报文,建立邻居关系。
每台路由器构建包含直接相连的链路状态的LSA(Link-State Advertisement,链路状态通告)。链路状态通告(LSA)中记录了所有相关的路由器,包括邻路由器的标识、链路类型、带宽等。
每台路由器泛洪链路状态通告(LSA)给所有的邻路由器,并且自己也在本地储存邻路由发过来的LSA,然后再将收到的LSA泛洪给自己的所有邻居,直到在同一区域中的所有路由器收到了所有的LSA。每台路由器在本地数据库中保存所有收到的LSA副本,这个数据库被称作“链路状态数据库(LSDB,Link-State Database)”
每台路由器基于本地的“链路状态数据库(LSDB)”然后执行“最短路径优先(SPF)”算法,并以本路由器为根,生成一个SPF树,基于这个SPF树计算去往每个网络的最短路径,也就得到了最终的路由表。
2、实验目的
简单理解OSPF以下二个基础知识点。
理解邻居表、拓扑表以及路由表;
OSPF如何选举RID?
OSPF度量值的计算方法;
3、实验拓扑
说明:默认没有R1到R3的快速以太网链路,此链路将在后面实验OPSF度量值的计算方法上使用)
(1)、路由表
R2#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/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.2/32 [110/65] via 192.168.10.2, 00:04:11, Serial1/1
O 10.5.0.2/32[110/65] via 192.168.20.2, 00:02:21, Serial1/0
C 10.6.0.0/16 is directly connected, Loopback0
O 10.11.0.2/32 [110/65] via 192.168.50.2, 00:00:31, Serial1/3
O 10.12.0.2/32 [110/65] via 192.168.40.2, 00:01:26, Serial1/2
192.168.10.0/30 is subnetted, 1 subnets
C 192.168.10.0 is directly connected, Serial1/1
192.168.20.0/30 is subnetted, 1 subnets
C 192.168.20.0 is directly connected, Serial1/0
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/128] via 192.168.40.2, 00:00:31, Serial1/2
[110/128] via 192.168.50.2, 00:00:31, Serial1/3
192.168.40.0/30 is subnetted, 1 subnets
C 192.168.40.0 is directly connected, Serial1/2
192.168.50.0/30 is subnetted, 1 subnets
C 192.168.50.0 is directly connected, Serial1/3
如上面红色部分,在OSPF中所有的回环接口都被自动宣告成32位的主机路由“/32”,如果想显示回环接口的实际子网掩码,可以在回环端口上使用下面的命令:
Ip ospf network point-to-point
我们来看看实际的结果,当在R1、R2上的loopback0端口输入此命令后如下显示:
R2#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/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0/16 [110/65] via 192.168.10.2, 00:00:11, Serial1/1
O 10.5.0.2/32 [110/65] via 192.168.20.2, 00:36:53, Serial1/0
C 10.6.0.0/16is directly connected, Loopback0
O 10.11.0.2/32 [110/65] via 192.168.50.2, 00:35:03, Serial1/3
O 10.12.0.2/32 [110/65] via 192.168.40.2, 00:35:57, Serial1/2
------略-----
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/8 is variably subnetted, 5 subnets, 2 masks
C 10.2.0.0/16is directly connected, Loopback0
O 10.5.0.2/32 [110/129] via 192.168.10.1, 00:36:39, Serial0/0
O 10.6.0.0/16 [110/65] via 192.168.10.1, 00:00:38, Serial0/0
O 10.11.0.2/32 [110/129] via 192.168.10.1, 00:34:49, Serial0/0
O 10.12.0.2/32 [110/129] via 192.168.10.1, 00:35:48, Serial0/0
------略-----
(2)、邻居表
R2#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
10.5.0.2 0 FULL/ - 00:00:34 192.168.20.2 Serial1/0
10.2.0.2 0 FULL/ - 00:00:31 192.168.10.2 Serial1/1
10.12.0.2 0 FULL/ - 00:00:34 192.168.40.2 Serial1/2
10.11.0.2 0 FULL/ - 00:00:33 192.168.50.2 Serial1/3
Neighbor ID:邻居的RID,通过上面的输出可以看到R3的RID是10.5.0.2,R1的RID是10.2.0.2,R5的RID是10.12.0.2和R4的RID是10.11.0.2,分别从不同的接口建立了邻居关系。
Pir: OSPF邻居接口的优先级,接口优先级用于DR和BDR的选举,以太网接口的默认优先级是1,串行线路不需要选举DR和BDR,所以串行线路的优先级是0,即0代表不参与选举。
State:邻居路由器的状态,FULL代表已经建立邻接关系,“/”后面是选举的DR或BDR标识,因为串行线路不需要选举,所以是“-”。
Dead time:默认的死亡时间是hello时间的4倍,即40秒。死亡时间是一个倒计时,计时器为0时,该邻居被删除。
Address:邻居直连接口的IP地址。
Interface:本路由的输出接口。
(3)、拓扑表
R2#show ip ospf database
OSPF Router with ID (10.6.0.2) (Process ID 1)
Router Link States (Area 0)
Link ID ADV Router Age Seq# Checksum Link count
10.6.0.2 10.6.0.2 54 0x8000000c 0x00997e 9
10.5.0.2 10.5.0.2 393 0x80000005 0x00650d 3
10.12.0.2 10.12.0.2 299 0x80000007 0x0099d6 5
10.11.0.2 10.11.0.2 285 0x80000007 0x004419 5
10.2.0.2 10.2.0.2 19 0x80000006 0x00a5ea 3
(4)、OSPF如何选举Router ID?
Router ID简称RID,用来唯一标示OSPF网络中的每一台路由器。如果两条OSPF路由器的RID一样,彼此间无法建立邻接关系。RID是以IP地址的形式出现的,那么RID的选举顺序是什么?我们先来看看R1的RID:
R1#show ip protocols
Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 10.2.0.2
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.10.0 0.0.0.255 area 0
0.0.0.0 255.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
10.2.0.2 110 00:07:07
10.5.0.2 110 00:13:21
10.6.0.2 110 00:07:43
10.11.0.2 110 00:11:34
10.12.0.2 110 00:11:48
Distance: (default is 110)
下面我们来手工配置一下R1的Router ID:
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#route ospf 1
A.B.C.D OSPF router-id in IP address format
R1(config-router)#route 20.20.20.20
R1(config-router)#Reload or use "clear ip ospf process" command, for this to take effect
R1(config-router)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#clear ip ospf process
Reset ALL OSPF processes? [no]: y
R1#
01:24:01: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset
01:24:01: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
01:24:05: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from LOADING to FULL, Loading Done
我们再来查看一下Route ID是什么情况:
R1#show ip protocols
Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 20.20.20.20
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
-----略-----
从上面的例子中,我们看到RID可以是一个并不存在的IP地址,RID仅仅作为路由的标识,不会用于寻址。
另我们需要想一个问题,那就是如果取消R1的手动配置RID,并且关闭loopback0接口,这个时候最大的已激活回环接口IP应该是什么?同样我们来看看实验:
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#route ospf 1
R1(config-router)#no route 20.20.20.20
R1(config-router)#int loopback0
R1(config-if)#shutdown
R1(config-if)#
%LINK-5-CHANGED: Interface Loopback0, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to down
R1(config-if)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#clear ip ospf process
Reset ALL OSPF processes? [no]: y
R1#
01:36:48: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset
01:36:48: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
R1#show ip protocols
Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 192.168.10.2
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.10.0 0.0.0.255 area 0
0.0.0.0 255.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
Distance: (default is 110)
R1#
01:36:56: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from LOADING to FULL, Loading Done
如上实例说明一个问题,若没有手动指定RID,路由器默认使用最大已激活的回环接口IP作为RID,但这里要注意的是最大并不是接口号最大,而是IP地址最大。还有一个问题就是如果路由器没有激活的回环接口,路由器默认会选择最大激活的物理接口的IP地址作为RID,如上则选择的是物理接口192.168.10.2。
(5)、OSPF度量值如何计算?
OSPF中使用的度量值是“花费(Cost)”,默认OSPF使用100Mb/s作为参考带宽,使用100Mb/s除以实际链路带宽,得出的值取整(对于小于0的结果,取1),就是花费。
比如串行线路的带宽是1.544M,快速以太网的带宽是100M,即如下:
串行线路的花费=100M/1.544≈64(取整,且不四舍五入)
快速以太网线路花费=100M/100M=1
继续上面的实验,同时我们在R1和R3中新增一条快速以太网链路,然后做相应的配置,再看看其R3的验证:
R3#show ip route ospf
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0 [110/2] via 172.16.50.1, 00:00:15, FastEthernet0/0
O 10.6.0.0 [110/65] via 192.168.20.1, 00:10:00, Serial0/3
O 10.11.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3
O 10.12.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3
192.168.10.0/30 is subnetted, 1 subnets
O 192.168.10.0 [110/65] via 172.16.50.1, 00:00:15, FastEthernet0/0
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/192] via 192.168.20.1, 00:10:00, Serial0/3
192.168.40.0/30 is subnetted, 1 subnets
O 192.168.40.0 [110/128] via 192.168.20.1, 00:10:00, Serial0/3
192.168.50.0/30 is subnetted, 1 subnets
O 192.168.50.0 [110/128] via 192.168.20.1, 00:10:00, Serial0/3
我们可以看到[110/2],110是OSPF的默认管理距离,2是花费,去往10.2.0.0/16的花费是2,就是快速以太网的花费加上回环接口的花费,因为回环接口的带宽非常高,用100M去除会小于0,所以取1。另外192.168.10.0 [110/65]的65是通过串行线路花费64,加上以太网花费1得到的。
现在我们关闭R3的快速以及网接口,再看看R3的路由表:
R3(config)#int fa0/0
R3(config-if)#shutdown
R3(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
00:17:25: %OSPF-5-ADJCHG: Process 1, Nbr 10.2.0.2 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
end
R3#
%SYS-5-CONFIG_I: Configured from console by console
R3#show ip route ospf
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0 [110/129] via 192.168.20.1, 00:00:01, Serial0/3
O 10.6.0.0 [110/65] via 192.168.20.1, 00:17:06, Serial0/3
O 10.11.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3
O 10.12.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3
192.168.10.0/30 is subnetted, 1 subnets
O 192.168.10.0 [110/128] via 192.168.20.1, 00:00:01, Serial0/3
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/192] via 192.168.20.1, 00:17:06, Serial0/3
192.168.40.0/30 is subnetted, 1 subnets
O 192.168.40.0 [110/128] via 192.168.20.1, 00:17:06, Serial0/3
192.168.50.0/30 is subnetted, 1 subnets
O 192.168.50.0 [110/128] via 192.168.20.1, 00:17:06, Serial0/3
此时会发现数据都要经过串行线路,并且花费变成了129。而192.168.10.0 [110/128]也变成了128。其实可以通过下面的方法修改计算花费的参考带宽:
R3(config)#route ospf 1
R3(config-router)#auto-cost
R3(config-router)#auto-cost reference-bandwidth 10000
% OSPF: Reference bandwidth is changed.
Please ensure reference bandwidth is consistent across all routers.
R3(config-router)#end
R3#
%SYS-5-CONFIG_I: Configured from console by console
当修改了所有路由器的参考带宽后,再看看R3的路由表:
R3#show ip route ospf
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.2.0.0 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3
O 10.6.0.0 [110/6477] via 192.168.20.1, 00:02:42, Serial0/3
O 10.11.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3
O 10.12.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3
O 172.16.0.0 [110/13052] via 192.168.20.1, 00:00:28, Serial0/3
192.168.10.0/30 is subnetted, 1 subnets
O 192.168.10.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3
192.168.30.0/30 is subnetted, 1 subnets
O 192.168.30.0 [110/19428] via 192.168.20.1, 00:00:18, Serial0/3
192.168.40.0/30 is subnetted, 1 subnets
O 192.168.40.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3
192.168.50.0/30 is subnetted, 1 subnets
O 192.168.50.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3
同样用去往10.2.0.0/16网络的12953举例计算花费如下:
R3和R2相连的串行链路花费=10000M/1.544M≈6476
R2和R1相连的串行链路花费=10000M/1.544M≈6476
R1上的loopback0接口的花费=10000M/8000M≈1
三条线路花费综合即为12953,另其它端口花费同样计算。
最后可以通过下面方法查看某接口的OSPF信息:
R3#show ip ospf int se0/3
Serial0/3 is up, line protocol is up
Internet address is 192.168.20.2/30, Area 0
Process ID 1, Router ID 10.5.0.2, Network Type POINT-TO-POINT, Cost: 6476
Transmit Delay is 1 sec, State POINT-TO-POINT, Priority 0
No designated router on this network
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:01
Index 2/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 1 , Adjacent neighbor count is 1
Adjacent with neighbor 10.6.0.2
Suppress hello for 0 neighbor(s)
本文标题:实验设计与排错之四OSPF配置、分析与排错
文章分享:http://azwzsj.com/article/jigihg.html