Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

CentOS 7 使用 Quagga 搭建 OSPF 動態路由器:雙站點互聯實戰

編輯:關於 Linux

Quagga 是成熟的開源路由軟體套件,支援 RIP、OSPF、BGP、IS-IS 等協定,可將 Linux 伺服器轉型為功能完整的路由器。本文以 CentOS 7 為例,示範兩站點 (Site-A、Site-B) 透過專線互聯,啟用 OSPF 實現動態路由交換的完整配置流程。

網路拓撲與 IP 規劃

站點LAN 網段WAN 互聯 IP主機名
Site-A192.168.1.0/2410.10.10.1/30site-A-RTR
Site-B172.16.1.0/2410.10.10.2/30site-B-RTR

安裝 Quagga 並處理 SELinux

yum install -y quagga
# CentOS 7 預設 SELinux 阻擋 zebra 寫入配置,啟用布林值
setsebool -P zebra_write_config 1
# 或暫時設定 permissive (不建議生產環境)
# setenforce 0
systemctl enable --now zebra ospfd

Zebra 核心配置 (兩台同步執行)

vtysh
configure terminal
log file /var/log/quagga/quagga.log
service password-encryption
!
interface eth0
 description to-WAN
 ip address 10.10.10.1/30   # Site-B 改為 10.10.10.2/30
 no shutdown
!
interface eth1
 description to-LAN
 ip address 192.168.1.1/24  # Site-B 改為 172.16.1.1/24
 no shutdown
!
write
exit

OSPF 協定配置

vtysh
configure terminal
router ospf
 ospf router-id 1.1.1.1      # Site-B 用 2.2.2.2,建議用 Loopback IP
 network 10.10.10.0/30 area 0.0.0.0
 network 192.168.1.0/24 area 0.0.0.0   # Site-B 對應 172.16.1.0/24
 passive-interface eth1      # LAN 介面不發送 Hello,僅宣告網段
!
write
exit

驗證鄰居與路由表

# 檢查 OSPF 鄰居狀態 (應為 Full/DR 或 Full/BDR)
show ip ospf neighbor

# 檢查路由表包含對端 LAN 網段
show ip route ospf
# 輸出應含 O  172.16.1.0/24 [110/20] via 10.10.10.2, eth0

常見問題排查

鄰居卡在 Init/2-Way
檢查 MTU 不匹配、Hello/Dead 間隔、ACL 阻擋 UDP 89、區域 ID 不一致。
路由不收斂
確認 passive-interface 僅用於 LAN,WAN 介面必須主動發送 Hello。
SELinux 仍報錯
查看 ausearch -m avc -ts recent,必要時建立自訂模組或設定 permissive。

生產環境建議

  • 啟用 MD5 鑑別:area 0.0.0.0 authentication message-digest + ip ospf message-digest-key 1 md5 。
  • 調整 Hello/Dead 間隔適應專線延遲:ip ospf hello-interval 10 ip ospf dead-interval 40。
  • 配置 BFD (Bidirectional Forwarding Detection) 實現毫秒級故障偵測。
  • 將配置納入版本控制 (Git),變更走 Code Review 流程。

完成上述步驟,你已擁有一對高可用、動態路由的 Linux 路由器,可替代中小型專用設備。

Copyright © Windows教程網 All Rights Reserved