OSPF 鄰接關係建立是鏈路狀態協議收斂的基石。只有達到 **Full 狀態**,區域內所有路由器的 LSDB (Link State Database) 才完全同步。本文逐幀解析 7 階段狀態機、Hello/DBD/LSR/LSU/LSAck 五種報文交互、DR/BDR 選舉、主從協商、序列號判新舊、同步完成標誌,並附帶除錯指令與常見卡住原因。
Down
│ Hello (Dst 224.0.0.5)
▼
Init ←──────────────────────┐
│ Hello (含對方 Router ID) │
▼ │
2-Way (雙向) ────────────────┘
│
├─► DR/BDR 選舉 (廣播/非廣播多存取網絡)
│ └─ 僅與 DR/BDR 形成鄰接,DROTHER 停在 2-Way
│
▼
ExStart (主從協商)
│ DBD (Seq Num, M-bit, MS-bit)
▼
Exchange (交換 DBD 摘要)
│ DBD (LSA Header: Type, LSID, Adv Router, Seq, Age, Checksum)
▼
Loading (請求缺失 LSA)
│ LSR (請求特定 LSA)
│ LSU (發送完整 LSA)
│ LSAck (確認)
▼
Full (完全同步) ◄──────────── 所有 LSDB 相同
hello-interval (預設 10s 廣播網, 30s 非廣播) 發送 Hello 至 224.0.0.5 (AllSPFRouters)。0x80000001 ~ 0x7FFFFFFF。0x80000001 最舊,0x7FFFFFFF 最新。| 卡住狀態 | 典型原因 | 排查指令 |
|---|---|---|
| Init | 單向通信 (ACL 阻擋 Hello、MTU 不匹配、Auth 失敗) | debug ip ospf hello, show ip ospf interface |
| 2-Way | 非 DR/BDR 網絡類型正常;若為點對點卻停此 → Network Type 錯誤 | show ip ospf interface 確認 Network Type |
| ExStart | MTU 不匹配 (DBD 含 MTU 選項)、Authentication 不一致、Router ID 衝突 | debug ip ospf adj, show ip ospf interface MTU |
| Exchange | DBD 交換超時 (RxmtInterval)、LSA 校驗和錯誤 | debug ip ospf flood |
| Loading | LSR/LSU 丟失、重傳超時、資源不足 | show ip ospf database 對比、show memory |
debug ip ospf adj ! 狀態機轉移、主從協商、DBD/LSR/LSU/LSAck
debug ip ospf hello ! Hello 收發、參數不匹配
debug ip ospf flood ! LSA 泛洪
debug ip ospf spf ! SPF 計算觸發
! 生產環境極度謹慎,建議配合 access-class 限制 debug 輸出條件
ip ospf mtu-ignore 僅作臨時繞過。ip ospf authentication message-digest + ip ospf message-digest-key 1 md5 Key。router-id 1.1.1.1 避免介面 IP 變更導致 RID 變更引發全網重收斂。passive-interface default + no passive-interface core-link,減少 Hello 開銷與攻擊面。