您的位置:首页 > 其它

实验设计与排错之四OSPF配置、分析与排错

2015-10-15 23:19 183 查看

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 routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGPi - 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 - ODRP - periodic downloaded static route
Gateway of last resort is not set
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masksO 10.2.0.2/32 [110/65] via 192.168.10.2, 00:04:11, Serial1/1O 10.5.0.2/32 [110/65] via 192.168.20.2, 00:02:21, Serial1/0C 10.6.0.0/16 is directly connected, Loopback0O 10.11.0.2/32 [110/65] via 192.168.50.2, 00:00:31, Serial1/3O 10.12.0.2/32 [110/65] via 192.168.40.2, 00:01:26, Serial1/2192.168.10.0/30 is subnetted, 1 subnetsC 192.168.10.0 is directly connected, Serial1/1192.168.20.0/30 is subnetted, 1 subnetsC 192.168.20.0 is directly connected, Serial1/0192.168.30.0/30 is subnetted, 1 subnetsO 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/3192.168.40.0/30 is subnetted, 1 subnetsC 192.168.40.0 is directly connected, Serial1/2192.168.50.0/30 is subnetted, 1 subnetsC 192.168.50.0 is directly connected, Serial1/3如上面红色部分,在OSPF中所有的回环接口都被自动宣告成32位的主机路由“/32”,如果想显示回环接口的实际子网掩码,可以在回环端口上使用下面的命令:Ip ospf network point-to-point我们来看看实际的结果,当在R1、R2上的loopback0端口输入此命令后如下显示:R2#show ip routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGPi - 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 - ODRP - periodic downloaded static route
Gateway of last resort is not set
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masksO 10.2.0.0/16 [110/65] via 192.168.10.2, 00:00:11, Serial1/1O 10.5.0.2/32 [110/65] via 192.168.20.2, 00:36:53, Serial1/0C 10.6.0.0/16 is directly connected, Loopback0O 10.11.0.2/32 [110/65] via 192.168.50.2, 00:35:03, Serial1/3O 10.12.0.2/32 [110/65] via 192.168.40.2, 00:35:57, Serial1/2------略-----R1#show ip routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGPi - 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 - ODRP - periodic downloaded static route
Gateway of last resort is not set
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masksC 10.2.0.0/16 is directly connected, Loopback0O 10.5.0.2/32 [110/129] via 192.168.10.1, 00:36:39, Serial0/0O 10.6.0.0/16 [110/65] via 192.168.10.1, 00:00:38, Serial0/0O 10.11.0.2/32 [110/129] via 192.168.10.1, 00:34:49, Serial0/0O 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 Interface10.5.0.2 0 FULL/ - 00:00:34 192.168.20.2 Serial1/010.2.0.2 0 FULL/ - 00:00:31 192.168.10.2 Serial1/110.12.0.2 0 FULL/ - 00:00:34 192.168.40.2 Serial1/210.11.0.2 0 FULL/ - 00:00:33 192.168.50.2 Serial1/3Neighbor 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 databaseOSPF Router with ID (10.6.0.2) (Process ID 1)
Router Link States (Area 0)
Link ID ADV Router Age Seq# Checksum Link count10.6.0.2 10.6.0.2 54 0x8000000c 0x00997e 910.5.0.2 10.5.0.2 393 0x80000005 0x00650d 310.12.0.2 10.12.0.2 299 0x80000007 0x0099d6 510.11.0.2 10.11.0.2 285 0x80000007 0x004419 510.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 nssaMaximum path: 4Routing for Networks:192.168.10.0 0.0.0.255 area 00.0.0.0 255.255.255.255 area 0Routing Information Sources: Gateway Distance Last Update 10.2.0.2 110 00:07:0710.5.0.2 110 00:13:2110.6.0.2 110 00:07:4310.11.0.2 110 00:11:3410.12.0.2 110 00:11:48Distance: (default is 110)下面我们来手工配置一下R1的Router ID:R1#conf tEnter configuration commands, one per line. End with CNTL/Z.R1(config)#route ospf 1A.B.C.D OSPF router-id in IP address formatR1(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)#endR1#%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.20Number of areas in this router is 1. 1 normal 0 stub 0 nssa-----略-----从上面的例子中,我们看到RID可以是一个并不存在的IP地址,RID仅仅作为路由的标识,不会用于寻址。另我们需要想一个问题,那就是如果取消R1的手动配置RID,并且关闭loopback0接口,这个时候最大的已激活回环接口IP应该是什么?同样我们来看看实验:R1#conf tEnter configuration commands, one per line. End with CNTL/Z.R1(config)#route ospf 1R1(config-router)#no route 20.20.20.20 R1(config-router)#int loopback0R1(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)#endR1#%SYS-5-CONFIG_I: Configured from console by console
R1#clear ip ospf processReset 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 nssaMaximum path: 4Routing for Networks:192.168.10.0 0.0.0.255 area 00.0.0.0 255.255.255.255 area 0Routing 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 ospf10.0.0.0/8 is variably subnetted, 5 subnets, 2 masksO 10.2.0.0 [110/2] via 172.16.50.1, 00:00:15, FastEthernet0/0O 10.6.0.0 [110/65] via 192.168.20.1, 00:10:00, Serial0/3O 10.11.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3O 10.12.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3192.168.10.0/30 is subnetted, 1 subnetsO 192.168.10.0 [110/65] via 172.16.50.1, 00:00:15, FastEthernet0/0192.168.30.0/30 is subnetted, 1 subnetsO 192.168.30.0 [110/192] via 192.168.20.1, 00:10:00, Serial0/3192.168.40.0/30 is subnetted, 1 subnetsO 192.168.40.0 [110/128] via 192.168.20.1, 00:10:00, Serial0/3192.168.50.0/30 is subnetted, 1 subnetsO 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/0R3(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 detachedendR3#%SYS-5-CONFIG_I: Configured from console by console
R3#show ip route ospf10.0.0.0/8 is variably subnetted, 5 subnets, 2 masksO 10.2.0.0 [110/129] via 192.168.20.1, 00:00:01, Serial0/3O 10.6.0.0 [110/65] via 192.168.20.1, 00:17:06, Serial0/3O 10.11.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3O 10.12.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3192.168.10.0/30 is subnetted, 1 subnetsO 192.168.10.0 [110/128] via 192.168.20.1, 00:00:01, Serial0/3192.168.30.0/30 is subnetted, 1 subnetsO 192.168.30.0 [110/192] via 192.168.20.1, 00:17:06, Serial0/3192.168.40.0/30 is subnetted, 1 subnetsO 192.168.40.0 [110/128] via 192.168.20.1, 00:17:06, Serial0/3192.168.50.0/30 is subnetted, 1 subnetsO 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 1R3(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)#endR3#%SYS-5-CONFIG_I: Configured from console by console当修改了所有路由器的参考带宽后,再看看R3的路由表:R3#show ip route ospf10.0.0.0/8 is variably subnetted, 5 subnets, 2 masksO 10.2.0.0 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3O 10.6.0.0 [110/6477] via 192.168.20.1, 00:02:42, Serial0/3O 10.11.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3O 10.12.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3O 172.16.0.0 [110/13052] via 192.168.20.1, 00:00:28, Serial0/3192.168.10.0/30 is subnetted, 1 subnetsO 192.168.10.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3192.168.30.0/30 is subnetted, 1 subnetsO 192.168.30.0 [110/19428] via 192.168.20.1, 00:00:18, Serial0/3192.168.40.0/30 is subnetted, 1 subnetsO 192.168.40.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3192.168.50.0/30 is subnetted, 1 subnetsO 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 upInternet address is 192.168.20.2/30, Area 0Process ID 1, Router ID 10.5.0.2, Network Type POINT-TO-POINT, Cost: 6476Transmit Delay is 1 sec, State POINT-TO-POINT, Priority 0No designated router on this networkNo backup designated router on this networkTimer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5Hello due in 00:00:01Index 2/2, flood queue length 0Next 0x0(0)/0x0(0)Last flood scan length is 1, maximum is 1Last flood scan time is 0 msec, maximum is 0 msecNeighbor Count is 1 , Adjacent neighbor count is 1Adjacent with neighbor 10.6.0.2Suppress hello for 0 neighbor(s)
本文出自 “龙的传人” 博客,请务必保留此出处http://ytlong.blog.51cto.com/154153/1703380
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: