Quagga是一個開源路由軟件套件,可以將Linux變成支持如RIP、OSPF、BGP和IS-IS等主要路由協議的路由器。它具有對IPv4和IPv6的完整支持,並支持路由/前綴過濾。Quagga可以是你生命中的救星,以防你的生產路由器一旦宕機,而你沒有備用的設備而只能等待更換。通過適當的配置,Quagga甚至可以作為生產路由器。 |
本教程中,我們將連接假設之間具有專線連接的兩個分支機構網絡(例如,192.168.1.0/24和172.17.1.0/24)。
我們的CentOS位於所述專用鏈路的兩端。兩台主機名分別設置為“site-A-RTR”和“site-B-RTR'。下面是IP地址的詳細信息。
•Site-A: 192.168.1.0/24
•Site-B: 172.16.1.0/24
•兩個 Linux 路由器之間的對等網絡: 10.10.10.0/30
Quagga包括了幾個協同工作的守護進程。在本教程中,我們將重點建立以下守護進程。
1.Zebra: 核心守護進程,負責內核接口和靜態路由。
2.Ospfd: IPv4 OSPF 守護進程。
我們使用yum安裝Quagga。
# yum install quagga
在CentOS7,SELinux默認會阻止quagga將配置文件寫到/usr/sbin/zebra。這個SELinux策略會干擾我們接下來要介紹的安裝過程,所以我們要禁用此策略。對於這一點,無論是關閉SELinux(這里不推薦),還是如下啟用“zebrawriteconfig”都可以。如果你使用的是CentOS 6的請跳過此步驟。
# setsebool -P zebra_write_config 1
如果沒有做這個修改,在我們嘗試在Quagga命令行中保存配置的時候看到如下錯誤。
Can't open configuration file /etc/quagga/zebra.conf.OS1Uu5.
安裝完Quagga后,我們要配置必要的對等IP地址,並更新OSPF設置。Quagga自帶了一個命令行稱為vtysh。vtysh里面用到的Quagga命令與主要的路由器廠商如思科和Juniper是相似的。
我們首先創建Zebra配置文件,並啟用Zebra守護進程。
# cp /usr/share/doc/quagga-XXXXX/zebra.conf.sample /etc/quagga/zebra.conf # service zebra start # chkconfig zebra on
啟動vtysh命令行:
#vtysh
首先,我們為Zebra配置日志文件。輸入下面的命令進入vtysh的全局配置模式:
site-A-RTR# configure terminal
指定日志文件位置,接着退出模式:
site-A-RTR(config)# log file /var/log/quagga/quagga.log site-A-RTR(config)# exit
永久保存配置:
site-A-RTR# write
接下來,我們要確定可用的接口並按需配置它們的IP地址。
site-A-RTR# show interface
Interface eth0 is up, line protocol detection is disabled . . . . . Interface eth1 is up, line protocol detection is disabled . . . . .
配置eth0參數:
site-A-RTR# configure terminal site-A-RTR(config)# interface eth0 site-A-RTR(config-if)# ip address 10.10.10.1/30 site-A-RTR(config-if)# description to-site-B site-A-RTR(config-if)# no shutdown
繼續配置eth1參數:
site-A-RTR(config)# interface eth1 site-A-RTR(config-if)# ip address 192.168.1.1/24 site-A-RTR(config-if)# description to-site-A-LAN site-A-RTR(config-if)# no shutdown
現在驗證配置:
site-A-RTR(config-if)# do show interface
Interface eth0 is up, line protocol detection is disabled . . . . . inet 10.10.10.1/30 broadcast 10.10.10.3 . . . . . Interface eth1 is up, line protocol detection is disabled . . . . . inet 192.168.1.1/24 broadcast 192.168.1.255 . . . . .
site-A-RTR(config-if)# do show interface description
Interface Status Protocol Description eth0 up unknown to-site-B eth1 up unknown to-site-A-LAN
永久保存配置:
site-A-RTR(config-if)# do write
在site-B上重復上面配置IP地址的步驟。
如果一切順利,你應該可以在site-A的服務器上ping通site-B上的對等IP地址10.10.10.2了。
注意:一旦Zebra的守護進程啟動了,在vtysh命令行中的任何改變都會立即生效。因此沒有必要在更改配置后重啟Zebra守護進程。
我們首先創建OSPF配置文件,並啟動OSPF守護進程:
# cp /usr/share/doc/quagga-XXXXX/ospfd.conf.sample /etc/quagga/ospfd.conf # service ospfd start # chkconfig ospfd on
現在啟動vtysh命令行來繼續OSPF配置:
# vtysh
輸入路由配置模式:
site-A-RTR# configure terminal site-A-RTR(config)# router ospf
可選配置路由id:
site-A-RTR(config-router)# router-id 10.10.10.1
添加在OSPF中的網絡:
site-A-RTR(config-router)# network 10.10.10.0/30 area 0 site-A-RTR(config-router)# network 192.168.1.0/24 area 0
永久保存配置:
site-A-RTR(config-router)# do write
在site-B上重復和上面相似的OSPF配置:
site-B-RTR(config-router)# network 10.10.10.0/30 area 0 site-B-RTR(config-router)# network 172.16.1.0/24 area 0 site-B-RTR(config-router)# do write
OSPF的鄰居現在應該啟動了。只要ospfd在運行,通過vtysh的任何OSPF相關配置的改變都會立即生效而不必重啟ospfd。
1. 通過ping測試
首先你應該可以從site-A ping同site-B的LAN子網。確保你的防火牆沒有阻止ping的流量。
[root@site-A-RTR ~]# ping 172.16.1.1 -c 2
2. 檢查路由表
必要的路由應該同時出現在內核與Quagga理由表中。
[root@site-A-RTR ~]# ip route
10.10.10.0/30 dev eth0 proto kernel scope link src 10.10.10.1 172.16.1.0/30 via 10.10.10.2 dev eth0 proto zebra metric 20 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.1
[root@site-A-RTR ~]# vtysh site-A-RTR# show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - ISIS, B - BGP, > - selected route, * - FIB route O>* 10.10.10.0/30 [110/10] is directly connected, eth0, 00:14:29 C>* 10.10.10.0/30 is directly connected, eth0 C>* 127.0.0.0/8 is directly connected, lo O>* 172.16.1.0/30 [110/20] via 10.10.10.2, eth0, 00:14:14 C>* 192.168.1.0/24 is directly connected, eth1
3. 驗證OSPF鄰居和路由
在vtysh命令行中,你可以檢查必要的鄰居是否在線與是否已經學習了合適的路由。
[root@site-A-RTR ~]# vtysh site-A-RTR# show ip ospf neighbor
本教程中,我們將重點放在使用Quagga配置基本的OSPF。在一般情況下,Quagga能讓我們能夠輕松在一台普通的Linux機器上配置動態路由協議,如OSPF、RIP或BGP。啟用了Quagga的機器可以與你網絡中的其他路由器進行通信和交換路由信息。由於它支持主要的開放標准的路由協議,它或許是許多情況下的首選。更重要的是,Quagga的命令行界面與主要路由器廠商如思科和Juniper幾乎是相同的,這使得部署和維護Quagga機器變得非常容易。