一、实战目的
(1)在路由器上启动 OSPF 路由进程
(2)启用参与路由协议的接口,并且通告网络及所在的区域
(3)修改参考带宽
(4)DR 选举的控制
(5)广播多路访问链路上的 OSPF 的特征
二.拓扑

三、步骤
(1)步骤 1:配置路由器 R1
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.1.0 255.255.255.0 area 0
R1(config-router)# auto-cost reference-bandwidth 1000
(2)步骤 2:配置路由器 R2
R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 2.2.2.0 255.255.255.0 area 0
R2(config-router)# network 192.168.1.0 255.255.255.0 area 0
R2(config-router)# auto-cost reference-bandwidth 1000
(3)步骤 3:配置路由器 R3
R3(config)# router ospf 1
R3(config-router)# router-id 3.3.3.3
R3(config-router)# network 3.3.3.0 255.255.255.0 area 0
R3(config-router)# network 192.168.1.0 255.255.255.0 area 0
R3(config-router)# auto-cost reference-bandwidth 1000
(4)步骤 4:配置路由器 R4
R4(config)# router ospf 1
R4(config-router)# router-id 4.4.4.4
R4(config-router)# network 4.4.4.0 255.255.255.0 area 0
R4(config-router)# network 192.168.1.0 255.255.255.0 area 0
R4(config-router)# auto-cost reference-bandwidth 1000
【说明 】
“ auto-cost reference-bandwidth”命令是修改参考带宽的,因为本实验中的以太口
的带宽为千兆,如果采用默认的百兆参考带宽,计算出来的 cost 是 0.1,这显然是不合理
的。修改参考带宽要在所有的 OSPF 路由器上配置,目的是确保参考标准是相同的。另外,
当执行命令“ auto-cost reference-bandwidth”的时候,系统也会提示如下信息:
% OSPF: Reference bandwidth is changed.
Please ensure reference bandwidth is consistent across all routers.
四.实验调试
(1) show ip ospf neighbor
R1# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/BDR 00:00:37 192.168.1.2 GigabitEthernet0/0
3.3.3.3 1 FULL/DROTHER 00:00:37 192.168.1.3 GigabitEthernet0/0
4.4.4.4 1 FULL/DROTHER 00:00:34 192.168.1.4 GigabitEthernet0/0
以上输出表明在该广播多路访问网络中,R1 是 DR,R2 是 BDR,R3 和 R4 为 DROTHER。
【技术要点 】
(1)为了避免路由器之间建立完全邻接关系而引起的大量开销,OSPF 要求在多路访问
的网络中选举一个 DR,每个路由器都与之建立邻接关系。选举 DR 的同时也选举出一个 BDR,在 DR 失效的时候,BDR 担负起 DR 的职责,而且所有其它路由器只与 DR 和 BDR 建立邻接关系;
(2)DR 和 BDR 有它们自己的组播地址 224.0.0.6;
(3)DR 和 BDR 的选举是以各个网络为基础的,也就是说 DR 和 BDR 选举是一个路由器
的接口特性,而不是整个路由器的特性;
(4)DR 选举的原则:
① 首要因素是时间,最先启动的路由器被选举成 DR;
② 如果同时启动,或者重新选举,则看接口优先级(范围为 0-255),优先级最高的被
选举成 DR,默认情况下,多路访问网络的接口优先级为 1,点到点网络接口优先级为 0,修
改接口优先级的命令是“ ip ospf priority” ”,如果接口的优先级被设置为 0,那么该接口将
不参与 DR 选举;
③ 如果前两者相同,最后看路由器 ID,路由器 ID 最高的被选举成 DR;
(5)DR 选举是非抢占的,除非人为地重新选举。重新选举 DR 的方法有两种,一是路
由器重新启动,二是执行“ clear ip ospf process”命令。
(2) show ip ospf interface
分别在路由器 R1 和 R4 上执行该命令:
R1# show ip ospf interface g0/0
GigabitEthernet0/0 is up, line protocol is up
Internet Address 192.168.1.1/24, Area 0
Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 10
Transmit Delay is 1 sec, State DR, Priority 1
//自己 state 是 DR
Designated Router (ID) 1.1.1.1, Interface address 192.168.1.1
//DR 的路由器 ID 以及接口地址
Backup Designated router (ID) 2.2.2.2, Interface address 192.168.1.2
//BDR 的路由器 ID 以及接口地址
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:09
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
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 4 msec
Neighbor Count is 3, Adjacent neighbor count is 3
//R1 是 DR,有 3 个邻居,并且全部形成邻接关系
Adjacent with neighbor 2.2.2.2 ( Backup Designated Router) //R2 是 BDR
Adjacent with neighbor 3.3.3.3
Adjacent with neighbor 4.4.4.4
Suppress hello for 0 neighbor(s)
R4# show ip ospf interface g0/0
GigabitEthernet0/0 is up, line protocol is up
Internet Address 192.168.1.4/24, Area 0
Process ID 1, Router ID 4.4.4.4, Network Type BROADCAST, Cost: 10
//网络类型为 BROADCAST
Transmit Delay is 1 sec, State DROTHER, Priority 1
//自己的 state 是 DROTHER
Designated Router (ID) 1.1.1.1, Interface address 192.168.1.1
//DR 的路由器 ID 和接口地址
Backup Designated router (ID) 2.2.2.2, Interface address 192.168.1.2
//BDR 的路由器 ID 和接口地址
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:06
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
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 3, Adjacent neighbor count is 2
//有 3 个邻居,只与 R1 和 R2 形成邻接关系,与 R3 只是邻居关系
Adjacent with neighbor 1.1.1.1 (Designated Router)
Adjacent with neighbor 2.2.2.2 (Backup Designated Router)
//上面两行表示与 DR 和 BDR 形成邻接关系
Suppress hello for 0 neighbor(s)
从上面的路由器 R1 和 R4 的输出得知,邻居关系和邻接关系是不能混为一谈的,邻居关
系是指达到 2WAY 状态的两台路由器,而邻接关系是指达到 FULL 状态的两台路由器。
(3) debug ip ospf adj
该命令显示 OSPF 邻接关系创建或中断的过程。
R2# debug ip ospf adj
OSPF adjacency events debugging is on
R2# clear ip ospf process
Reset ALL OSPF processes? [no]: y
*Feb 10 10:37:33.447: OSPF: Interface GigabitEthernet0/0 going Down
*Feb 10 10:37:33.447: OSPF: 2.2.2.2 address 192.168.1.2 on GigabitEthernet0/0 is dead, state
DOWN
DOWN
*Feb 10 10:37:33.447: OSPF: Neighbor change Event on interface GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: DR/BDR election on GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: Elect BDR 4.4.4.4
*Feb 10 10:37:33.447: OSPF: Elect DR 1.1.1.1
*Feb 10 10:37:33.447: OSPF: Elect BDR 4.4.4.4
*Feb 10 10:37:33.447: OSPF: Elect DR 1.1.1.1
*Feb 10 10:37:33.447: DR: 1.1.1.1 (Id) BDR: 4.4.4.4 (Id)
*Feb 10 10:37:33.447: OSPF: Reset adjacency with 3.3.3.3 on GigabitEthernet0/0, state 2WAY
*Feb 10 10:37:33.447: OSPF: 1.1.1.1 address 192.168.1.1 on GigabitEthernet0/0 is dead, state
DOWN
*Feb 10 10:37:33.447: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.1 on GigabitEthernet0/0 from FULL
to DOWN, Neighbor Down: Interface down or detached
*Feb 10 10:37:33.447: OSPF: Neighbor change Event on interface GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: DR/BDR election on GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: Elect BDR 4.4.4.4
*Feb 10 10:37:33.447: OSPF: Elect DR 4.4.4.4
*Feb 10 10:37:33.447: DR: 4.4.4.4 (Id) BDR: 4.4.4.4 (Id)
*Feb 10 10:37:33.447: OSPF: Remember old DR 1.1.1.1 (id)
*Feb 10 10:37:33.447: OSPF: 3.3.3.3 address 192.168.1.3 on GigabitEthernet0/0 is dead, state
DOWN
*Feb 10 10:37:33.447: %OSPF-5-ADJCHG: Process 1, Nbr 3.3.3.3 on GigabitEthernet0/0 from 2WAY
to DOWN, Neighbor Down: Interface down or detached
*Feb 10 10:37:33.447: OSPF: Neighbor change Event on interface GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: DR/BDR election on GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: Elect BDR 4.4.4.4
*Feb 10 10:37:33.447: OSPF: Elect DR 4.4.4.4
*Feb 10 10:37:33.447: DR: 4.4.4.4 (Id) BDR: 4.4.4.4 (Id)
*Feb 10 10:37:33.447: OSPF: 4.4.4.4 address 192.168.1.4 on GigabitEthernet0/0 is dead, state
DOWN
*Feb 10 10:37:33.447: %OSPF-5-ADJCHG: Process 1, Nbr 4.4.4.4 on GigabitEthernet0/0 from FULL
to DOWN, Neighbor Down: Interface down or detached
*Feb 10 10:37:33.447: OSPF: Neighbor change Event on interface GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: DR/BDR election on GigabitEthernet0/0
*Feb 10 10:37:33.447: OSPF: Elect BDR 0.0.0.0
*Feb 10 10:37:33.447: OSPF: Elect DR 0.0.0.0
*Feb 10 10:37:33.447: DR: none BDR: none
*Feb 10 10:37:33.447: OSPF: Remember old DR 4.4.4.4 (id)
*Feb 10 10:37:33.447: OSPF: Interface Loopback0 going Down
*Feb 10 10:37:33.447: OSPF: 2.2.2.2 address 2.2.2.2 on Loopback0 is dead, state DOWN
*Feb 10 10:37:33.459: OSPF: Interface GigabitEthernet0/0 going Up
*Feb 10 10:37:33.459: OSPF: Interface Loopback0 going Up
*Feb 10 10:37:33.459: OSPF: 2 Way Communication to 1.1.1.1 on GigabitEthernet0/0, state 2WAY
*Feb 10 10:37:33.459: OSPF: 2 Way Communication to 3.3.3.3 on GigabitEthernet0/0, state 2WAY
*Feb 10 10:37:33.459: OSPF: 2 Way Communication to 4.4.4.4 on GigabitEthernet0/0, state 2WAY
*Feb 10 10:37:33.459: OSPF: Backup seen Event before WAIT timer on GigabitEthernet0/0
*Feb 10 10:37:33.459: OSPF: DR/BDR election on GigabitEthernet0/0
*Feb 10 10:37:33.459: OSPF: Elect BDR 4.4.4.4
*Feb 10 10:37:33.459: OSPF: Elect DR 1.1.1.1
*Feb 10 10:37:33.459: DR: 1.1.1.1 (Id) BDR: 4.4.4.4 (Id)
*Feb 10 10:37:33.459: OSPF: Send DBD to 1.1.1.1 on GigabitEthernet0/0 seq 0xC87 opt 0x52 flag
0x7 len 32
*Feb 10 10:37:33.459: OSPF: Send DBD to 4.4.4.4 on GigabitEthernet0/0 seq 0x1B1C opt 0x52
flag 0x7 len 32
*Feb 10 10:37:33.463: OSPF: Rcv DBD from 1.1.1.1 on GigabitEthernet0/0 seq 0x1A0 opt 0x52
flag 0x7 len 32 mtu 1500 state EXSTART
*Feb 10 10:37:33.463: OSPF: First DBD and we are not SLAVE
*Feb 10 10:37:33.463: OSPF: Rcv DBD from 1.1.1.1 on GigabitEthernet0/0 seq 0xC87 opt 0x52
flag 0x2 len 112 mtu 1500 state EXSTART
*Feb 10 10:37:33.463: OSPF: NBR Negotiation Done. We are the MASTER
*Feb 10 10:37:33.463: OSPF: Send DBD to 1.1.1.1 on GigabitEthernet0/0 seq 0xC88 opt 0x52 flag
0x1 len 32
*Feb 10 10:37:33.463: OSPF: Rcv DBD from 4.4.4.4 on GigabitEthernet0/0 seq 0x13C0 opt 0x52
flag 0x7 len 32 mtu 1500 state EXSTART
*Feb 10 10:37:33.463: OSPF: NBR Negotiation Done. We are the SLAVE
*Feb 10 10:37:33.463: OSPF: Send DBD to 4.4.4.4 on GigabitEthernet0/0 seq 0x13C0 opt 0x52
flag 0x0 len 32
*Feb 10 10:37:33.463: OSPF: Rcv DBD from 1.1.1.1 on GigabitEthernet0/0 seq 0xC88 opt 0x52
flag 0x0 len 32 mtu 1500 state EXCHANGE
*Feb 10 10:37:33.463: OSPF: Exchange Done with 1.1.1.1 on GigabitEthernet0/0
*Feb 10 10:37:33.463: OSPF: Send LS REQ to 1.1.1.1 length 48 LSA count 4
*Feb 10 10:37:33.463: OSPF: Rcv DBD from 4.4.4.4 on GigabitEthernet0/0 seq 0x13C1 opt 0x52
flag 0x3 len 112 mtu 1500 state EXCHANGE
*Feb 10 10:37:33.463: OSPF: Send DBD to 4.4.4.4 on GigabitEthernet0/0 seq 0x13C1 opt 0x52
flag 0x0 len 32
*Feb 10 10:37:33.463: OSPF: Rcv LS UPD from 1.1.1.1 on GigabitEthernet0/0 length 212 LSA count
4
*Feb 10 10:37:33.467: OSPF: Synchronized with 1.1.1.1 on GigabitEthernet0/0, state FULL
*Feb 10 10:37:33.467: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.1 on GigabitEthernet0/0 from
LOADING to FULL, Loading Done
*Feb 10 10:37:33.467: OSPF: Rcv DBD from 4.4.4.4 on GigabitEthernet0/0 seq 0x13C2 opt 0x52
flag 0x1 len 32 mtu 1500 state EXCHANGE
*Feb 10 10:37:33.467: OSPF: Exchange Done with 4.4.4.4 on GigabitEthernet0/0
*Feb 10 10:37:33.467: OSPF: Synchronized with 4.4.4.4 on GigabitEthernet0/0, state FULL
*Feb 10 10:37:33.467: %OSPF-5-ADJCHG: Process 1, Nbr 4.4.4.4 on GigabitEthernet0/0 from
LOADING to FULL, Loading Done
*Feb 10 10:37:33.467: OSPF: Send DBD to 4.4.4.4 on GigabitEthernet0/0 seq 0x13C2 opt 0x52
flag 0x0 len 32
*Feb 10 10:37:33.947: OSPF: Build router LSA for area 0, router ID 2.2.2.2, seq 0x80000001,
process 1
*Feb 10 10:37:38.155: OSPF: Rcv LS UPD from 4.4.4.4 on GigabitEthernet0/0 length 76 LSA count
1
*Feb 10 10:37:38.443: OSPF: Rcv LS UPD from 1.1.1.1 on GigabitEthernet0/0 length 76 LSA count
1
*Feb 10 10:37:38.595: OSPF: Rcv LS UPD from 4.4.4.4 on GigabitEthernet0/0 length 76 LSA count
1
*Feb 10 10:37:38.635: OSPF: Rcv LS UPD from 1.1.1.1 on GigabitEthernet0/0 length 76 LSA count
1
*Feb 10 10:37:43.155: OSPF: Build router LSA for area 0, router ID 2.2.2.2, seq 0x80000005,
process 1
*Feb 10 10:37:43.155: OSPF: Rcv LS UPD from 1.1.1.1 on GigabitEthernet0/0 length 76 LSA count
1
以上的输出表明:
① DR 重新选举的过程和结果,新的 DR 是 R1,BDR 是 R4;
② 在 OSPF 邻接关系建立的过程中,接口的状态的变化包括 DOWN、2 Way、EXSTART、
EXCHANGE、Loading 和 FULL。
以下是更多华为数通路由交换方向相关技术分享,欢迎对华为网络技术感兴趣的盆友订阅。
华为新版HCIP数通路由交换
华为新版HCIE数通路由交换