实验拓扑图:
路由器R1f0/0连接路由器R2f0/0接口。
具体的配置:
R1:
interface loopback 0
ip add 1.1.1.1 255.0.0.0
interface f0/0
ip add 10.0.0.1 255.0.0.0
no sh
router ospf 1
net 0.0.0.0 0.0.0.0 a 0
R2:
interface loopback 0
ip add 2.2.2.2 255.0.0.0
interface f0/0
ip add 10.0.0.2 255.0.0.0
no sh
router ospf 1
net 0.0.0.0 0.0.0.0 a 0
最基本的配置就完成了,为了观察OSPF邻接状态建立的过程,在路由器R2上执行
debug ip ospf adj
回显如下:
*Jul 31 13:59:17.919: OSPF: Cannot see ourself in hello from 1.1.1.1 on FastEthernet0/0, state INIT
*Jul 31 13:59:17.923: OSPF: Neighbor change Event on interface FastEthernet0/0
*Jul 31 13:59:17.923: OSPF: DR/BDR election on FastEthernet0/0
*Jul 31 13:59:17.927: OSPF: Elect BDR 0.0.0.0
*Jul 31 13:59:17.927: OSPF: Elect DR 2.2.2.2
*Jul 31 13:59:17.927:        DR: 2.2.2.2 (Id)   BDR: none
*Jul 31 13:59:18.423: OSPF: Build router LSA for area 0, router ID 2.2.2.2, seq 0x8000000B
*Jul 31 13:59:18.423: OSPF: No full nbrs to build Net Lsa for interface FastEthernet0/0
*Jul 31 13:59:18.427: OSPF: Build network LSA for FastEthernet0/0, router ID 2.2.2.2
*Jul 31 13:59:18.427: OSPF: Build network LSA for FastEthernet0/0, router ID 2.2.2.2
*Jul 31 13:59:20.307: OSPF: Rcv DBD from 1.1.1.1 on FastEthernet0/0 seq 0x1D2F opt 0x52 flag 0x7 len 32  mtu 1500 state INIT
*Jul 31 13:59:20.311: OSPF: 2 Way Communication to 1.1.1.1 on FastEthernet0/0, state 2WAY
*Jul 31 13:59:20.311: OSPF: Neighbor change Event on interface FastEthernet0/0
*Jul 31 13:59:20.315: OSPF: DR/BDR election on FastEthernet0/0
*Jul 31 13:59:20.315: OSPF: Elect BDR 1.1.1.1
*Jul 31 13:59:20.315: OSPF: Elect DR 2.2.2.2
*Jul 31 13:59:20.319:        DR: 2.2.2.2 (Id)   BDR: 1.1.1.1 (Id)
*Jul 31 13:59:20.319: OSPF: Send DBD to 1.1.1.1 on FastEthernet0/0 seq 0xCEF opt 0x52 flag 0x7 len 32
*Jul 31 13:59:20.323: OSPF: First DBD and we are not SLAVE
*Jul 31 13:59:20.375: OSPF: Rcv DBD from 1.1.1.1 on FastEthernet0/0 seq 0xCEF opt 0x52 flag 0x2 len 52  mtu 1500 state EXSTART
*Jul 31 13:59:20.379: OSPF: NBR Negotiation Done. We are the MASTER
*Jul 31 13:59:20.379: OSPF: Send DBD to 1.1.1.1 on FastEthernet0/0 seq 0xCF0 opt 0x52 flag 0x3 len 52
*Jul 31 13:59:20.423: OSPF: Rcv DBD from 1.1.1.1 on FastEthernet0/0 seq 0xCF0 opt 0x52 flag 0x0 len 32  mtu 1500 state EXCHANGE
*Jul 31 13:59:20.427: OSPF: Send DBD to 1.1.1.1 on FastEthernet0/0 seq 0xCF1 opt 0x52 flag 0x1 len 32
*Jul 31 13:59:20.463: OSPF: Rcv DBD from 1.1.1.1 on FastEthernet0/0 seq 0xCF1 opt 0x52 flag 0x0 len 32  mtu 1500 state EXCHANGE
*Jul 31 13:59:20.467: OSPF: Exchange Done with 1.1.1.1 on FastEthernet0/0
*Jul 31 13:59:20.467: OSPF: Synchronized with 1.1.1.1 on FastEthernet0/0, state FULL
*Jul 31 13:59:20.471: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.1 on FastEthernet0/0 from LOADING to FULL, Loading Done
 
OSPF建立邻接关系需要经过DOWNINITTWO-WAYEXSTARTEXCHANGEFULLLOAD DONE这几个过程。如果一切正常是这样的。
如果把R1f0/0接口的MTU改为1000,默认为1500,邻接关系在卡在EXSTART状态。
OSPF邻居在建立邻接关系的过程中,在EXSTART这个阶段发送DBD包,对MTU的大小有一定的限制,可以在接口模式下配置: ip ospf mtu-ignore,忽略MTU对发送DBD包的影响。
R1show ip ospf nei
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   EXSTART/DR      00:00:38    10.0.0.2        FastEthernet0/0
 
debug ip ospf adj
*Jul 31 14:16:10.343: OSPF: Send DBD to 2.2.2.2 on FastEthernet0/0 seq 0x2648 opt 0x52 flag 0x7 len 32
*Jul 31 14:16:10.343: OSPF: Retransmitting DBD to 2.2.2.2 on FastEthernet0/0 [8]
*Jul 31 14:16:10.395: OSPF: Rcv DBD from 2.2.2.2 on FastEthernet0/0 seq 0x25C3 opt 0x52 flag 0x7 len 32  mtu 1500 state EXSTART
*Jul 31 14:16:10.395: OSPF: Nbr 2.2.2.2 has larger interface MTU
R2:show ip ospf neigh
Neighbor ID     Pri   State           Dead Time   Address         Interface
1.1.1.1           1   EXSTART/BDR     00:00:37    10.0.0.1        FastEthernet0/0
  debug ip ospf adj
 Jul 31 14:19:50.351: OSPF: Send DBD to 1.1.1.1 on FastEthernet0/0 seq 0x23A4 opt 0x52 flag 0x7 len 32
*Jul 31 14:19:50.355: OSPF: Retransmitting DBD to 1.1.1.1 on FastEthernet0/0 [12]
*Jul 31 14:19:55.323: OSPF: Rcv DBD from 1.1.1.1 on FastEthernet0/0 seq 0xCF opt 0x52 flag 0x7 len 32  mtu 1000 state EXSTART
*Jul 31 14:19:55.327: OSPF: First DBD and we are not SLAVE
 
如果把R1R2的优先级都改为0ip ospf priority 0)的话,邻接状态就停在了TWO-WAY状态了。
R1:
   interface f0/0
   ip ospf priority 0
R2:
   interface f0/0
   ip ospf priority 0
R1:  show ip ospf neigh
 
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           0   2WAY/DROTHER    00:00:36    10.0.0.2        FastEthernet0/
 
debug ip ospf adj
*Jul 31 14:25:30.319: OSPF: 2 Way Communication to 2.2.2.2 on FastEthernet0/0, state 2WAY
*Jul 31 14:25:30.323: OSPF: Neighbor change Event on interface FastEthernet0/0
*Jul 31 14:25:30.323: OSPF: DR/BDR election on FastEthernet0/0
*Jul 31 14:25:30.327: OSPF: Elect BDR 0.0.0.0
*Jul 31 14:25:30.327: OSPF: Elect DR 0.0.0.0
*Jul 31 14:25:30.327:        DR: none    BDR: none
因为选举DRBDR在广播网络中是必须的,且在TWO-WAY状态时就必须选举DR,没有确定的DR就不能进行DBD的发送,进而交换LSA更是不可能的。
同时如果两个路由器的接口不在同一区域,或是HELLODEAD时间间隔不一致,或是没有相同的末节区域标记,相同的认证密钥(如果有认证的话)都不能建立正常的邻接关系。