步骤:
(1)步骤1:配置路由器R1
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1 .1
R1(config-router)#network 1.1.1 .1 0.0.0.255 area 0
R1(config-router)#network 192.168.1.0 0.0.0 .255 area 0
(2)步骤2:配置路由器R2
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2 .2
R2(config-router)#network 2.2.2 .2 0.0.0.255 area 0
R2(config-router)#network 192.168.1.0 0.0.0 .255 area 0
(3)步骤3:配置路由器R3
R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3 .3
R3(config-router)#network 3.3.3 .3 0.0.0.255 area 0
R3(config-router)#network 192.168.1.0 0.0.0 .255 area 0
(4)步骤4:配置路由器R4
R4(config)#router ospf 1
R4(config-router)#router-id 4.4.4 .4
R4(config-router)#network 4.4.4 .4 0.0.0.255 area 0
R4(config-router)#network 192.168.1.0 0.0.0 .255 area 0
(2)show ip ospf neighbor:查看ospf邻居关系
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2 .2 1 FULL/BDR 00:00:36 192.168.1.2 Ethernet0/0
3.3.3 .3 1 FULL/DROTHER 00:00:39 192.168.1.3 Ethernet0/0
4.4.4 .4 1 FULL/DROTHER 00:00:39 192.168.1.4 Ethernet0/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”命令。
(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
*Mar 1 00:18:23.543: OSPF: Interface Ethernet0/0 going Down
*Mar 1 00:18:23.543: OSPF: 2.2.2 .2 address 192.168.1.2 on Ethernet0/0 is dead,
state DOWN
*Mar 1 00:18:23.543: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:23.543: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.547: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:23.547: OSPF: Elect DR 1.1.1 .1
*Mar 1 00:18:23.547: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:23.547: OSPF: Elect DR 1.1.1 .1
*Mar 1 00:18:23.547: DR: 1.1.1 .1 (Id) BDR: 4.4.4.4 (Id)
*Mar 1 00:18:23.551: OSPF: Reset adjacency with 3.3.3 .3 on Ethernet0/0, state 2
WAY
*Mar 1 00:18:23.551: OSPF: 1.1.1 .1 address 192.168.1.1 on Ethernet0/0 is dead,
state DOWN
*Mar 1 00:18:23.551: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1 .1 on Ethernet0/0 from
FULL to DOWN, Neighbor Down: Interface down or detached
*Mar 1 00:18:23.555: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:23.555: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.555: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:28.803: OSPF: Rcv LS UPD from 1.1.1 .1 on Ethernet0/0 length 76 LSA
count 100:18:23.555: DR: 4.4.4 .4 (Id) BDR: 4.4.4.4 (Id)
*Mar 1 00:18:29.127: OSPF: Rcv LS UPD from 1.1.1 .1 on Ethernet0/0 length 76 LSA
count 100:18:23.559: OSPF: 3.3.3 .3 address 192.168.1.3 on Ethernet0/0 is dead,
*Mar 1 00:18:29.179: OSPF: Rcv LS UPD from 4.4.4 .4 on Ethernet0/0 length 76 LSA
count 100:18:23.559: %OSPF-5-ADJCHG: Process 1, Nbr 3.3.3 .3 on Ethernet0/0 from
*Mar 1 00:18:29.571: OSPF: Build router LSA for area 0, router ID 2.2.2 .2, seq
0x80000004:18:23.559: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:29.611: OSPF: Rcv LS UPD from 1.1.1 .1 on Ethernet0/0 length 76 LSA
count 100:18:23.563: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:31.475: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on Ethe
rnet0/0 (not full duplex), with Router FastEthernet0/2 (full duplex).
*Mar 1 00:18:23.563: OSPF: 4.4.4 .4 address 192.168.1.4 on Ethernet0/0 is dead,
state DOWN
*Mar 1 00:18:23.567: %OSPF-5-ADJCHG: Process 1, Nbr 4.4.4 .4 on Ethernet0/0 from
FULL to DOWN, Neighbor Down: Interface down or detached
*Mar 1 00:18:23.567: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:23.567: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.571: OSPF: Elect BDR 0.0.0 .0
*Mar 1 00:18:23.571: OSPF: Elect DR 0.0.0 .0
*Mar 1 00:18:23.571: DR: none BDR: none
*Mar 1 00:18:23.571: OSPF: Remember old DR 4.4.4 .4 (id)
*Mar 1 00:18:23.571: OSPF: Interface Loopback0 going Down
*Mar 1 00:18:23.575: OSPF: 2.2.2 .2 address 2.2.2.2 on Loopback0 is dead, state
DOWN
*Mar 1 00:18:23.655: OSPF: Interface Ethernet0/0 going Up
*Mar 1 00:18:23.655: OSPF: Interface Loopback0 going Up
*Mar 1 00:18:23.675: OSPF: 2 Way Communication to 4.4.4 .4 on Ethernet0/0, state
2WAY
*Mar 1 00:18:23.679: OSPF: Backup seen Event before WAIT timer on Ethernet0/0
*Mar 1 00:18:23.679: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.679: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:23.679: OSPF: Elect DR 4.4.4 .4
*Mar 1 00:18:23.679: DR: 4.4.4 .4 (Id) BDR: 4.4.4.4 (Id)
*Mar 1 00:18:23.683: OSPF: Send DBD to 4.4.4 .4 on Ethernet0/0 seq 0xE02 opt 0x5
2 flag 0x7 len 32
*Mar 1 00:18:23.683: OSPF: 2 Way Communication to 1.1.1 .1 on Ethernet0/0, state
2WAY
*Mar 1 00:18:23.687: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:23.687: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.687: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:23.687: OSPF: Elect DR 1.1.1 .1
*Mar 1 00:18:23.687: DR: 1.1.1 .1 (Id) BDR: 4.4.4.4 (Id)
*Mar 1 00:18:23.691: OSPF: Send DBD to 1.1.1 .1 on Ethernet0/0 seq 0x 224A opt 0x
52 flag 0x7 len 32
*Mar 1 00:18:23.691: OSPF: Remember old DR 4.4.4 .4 (id)
*Mar 1 00:18:23.691: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:23.691: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.695: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:23.695: OSPF: Elect DR 1.1.1 .1
*Mar 1 00:18:23.695: DR: 1.1.1 .1 (Id) BDR: 4.4.4.4 (Id)
*Mar 1 00:18:23.695: OSPF: 2 Way Communication to 3.3.3 .3 on Ethernet0/0, state
2WAY
*Mar 1 00:18:23.699: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:23.699: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.699: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:23.699: OSPF: Elect DR 1.1.1 .1
*Mar 1 00:18:23.699: DR: 1.1.1 .1 (Id) BDR: 4.4.4.4 (Id)
*Mar 1 00:18:23.703: OSPF: Neighbor change Event on interface Ethernet0/0
*Mar 1 00:18:23.703: OSPF: DR/BDR election on Ethernet0/0
*Mar 1 00:18:23.703: OSPF: Elect BDR 4.4.4 .4
*Mar 1 00:18:23.703: OSPF: Elect DR 1.1.1 .1
*Mar 1 00:18:23.703: DR: 1.1.1 .1 (Id) BDR: 4.4.4.4 (Id)
*Mar 1 00:18:23.719: OSPF: Rcv DBD from 4.4.4 .4 on Ethernet0/0 seq 0xD85 opt 0x
以上的输出表明:
① DR 重新选举的过程和结果,新的DR 是R1,BDR 是R4;
② 在OSPF 邻接关系建立的过程中,接口的状态的变化包括DOWN、2 Way、EXSTART、
EXCHANGE、Loading 和FULL。