测试环境
(ens36)虚拟机A(ens33)<—(对等网络:10.10.10.0/30)—>(ens33)虚拟机B(ens36)
| |
内网 192.168.1.0/24 内网 172.17.1.0/24
安装Quagga
yum install quagga
在CentOS7,SELinux默认会阻止quagga将配置文件写到/usr/sbin/zebra,需要禁用此策略。如果使用的是CentOS 6的则跳过此步骤。
setsebool -P zebra_write_config 1
配置Zebra
首先创建Zebra配置文件,并启用Zebra守护进程
cp /usr/share/doc/quagga-0.99.22.4/zebra.conf.sample /etc/quagga/zebra.conf
service zebra start
chkconfig zebra on
进入vtysh命令行,配置日志存储文件
[root@192 ~]# vtysh
Hello, this is Quagga (version 0.99.22.4).
Copyright 1996-2005 Kunihiro Ishiguro, et al.
192.168.247.146# configure terminal
192.168.247.146(config)# log file /var/log/quagga/quagga.log
192.168.247.146(config)# exit
192.168.247.146# write
Building Configuration...
Configuration saved to /etc/quagga/zebra.conf
[OK]
配置虚拟机A接口参数
192.168.247.146# show interface
Interface ens33 is up, line protocol detection is disabled
index 2 metric 1 mtu 1500
flags: <UP,BROADCAST,RUNNING,MULTICAST>
HWaddr: 00:0c:29:c8:63:38
inet 192.168.247.144/24 broadcast 192.168.247.255
inet6 fe80::5ad4:63d3:3cf5:591a/64
inet6 fe80::7637:6430:5b9f:18db/64
Interface ens36 is up, line protocol detection is disabled
index 3 metric 1 mtu 1500
flags: <UP,BROADCAST,RUNNING,MULTICAST>
HWaddr: 00:0c:29:c8:63:42
inet 192.168.247.146/24 broadcast 192.168.247.255
inet6 fe80::d3de:98dd:9c37:c144/64
...
192.168.247.146# conf t
192.168.247.146(config)# interface ens33
192.168.247.146(config-if)# ip address 10.10.10.1/30
192.168.247.146(config-if)# description to-site-B
192.168.247.146(config-if)# no shutdown
192.168.247.146(config-if)# interface ens36
192.168.247.146(config-if)# ip address 192.168.1.1/24
192.168.247.146(config-if)# description to-site-A-LAN
192.168.247.146(config-if)# no shutdown
192.168.247.146(config-if)# do show interface
Interface ens33 is up, line protocol detection is disabled
Description: to-site-B
index 2 metric 1 mtu 1500
flags: <UP,BROADCAST,RUNNING,MULTICAST>
HWaddr: 00:0c:29:c8:63:38
inet 10.10.10.1/30 broadcast 10.10.10.3
inet 192.168.247.144/24 broadcast 192.168.247.255
inet6 fe80::5ad4:63d3:3cf5:591a/64
inet6 fe80::7637:6430:5b9f:18db/64
Interface ens36 is up, line protocol detection is disabled
Description: to-site-A-LAN
index 3 metric 1 mtu 1500
flags: <UP,BROADCAST,RUNNING,MULTICAST>
HWaddr: 00:0c:29:c8:63:42
inet 192.168.1.1/24 broadcast 192.168.1.255
inet 192.168.247.146/24 broadcast 192.168.247.255
inet6 fe80::d3de:98dd:9c37:c144/64
...
同理,虚拟机B的ens33配置ip address 10.10.10.2/30,ens36配置172.17.1.1/24
配置BGP
cp /usr/share/doc/quagga-0.99.22.4/bgpd.conf.sample /etc/quagga/bgpd.conf
service bgpd start
chkconfig bgpd on
配置邻居
在一些版本,比如当前版本,发现会有一个默认AS号为7675的BGP会话。由于我们不需要这个会话,所以先把它移除,再添加我们的。
虚拟B进入vtysh
192.168.247.147# conf t
192.168.247.147(config)# no router bgp 7675
192.168.247.147(config)# router bgp 200
192.168.247.147(config-router)# no auto-summary
192.168.247.147(config-router)# no synchronization
192.168.247.147(config-router)# neighbor 10.10.10.1 remote-as 100
192.168.247.147(config-router)# neighbor 10.10.10.1 description "provider A"
192.168.247.147(config-router)# exit
192.168.247.147(config)# exit
192.168.247.147# write
查看BGP邻居是否建立
192.168.247.147# show ip bgp summary
BGP router identifier 10.10.10.2, local AS number 200
RIB entries 0, using 0 bytes of memory
Peers 1, using 4560 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.10.10.1 4 100 2 3 0 0 0 00:00:53 0
从输出中,我们可以看到"State/PfxRcd"部分。如果对等关闭,输出将会显示"Idle"或者"Active"。"Active"意味着路由器正在积极地寻找邻居、前缀或者路由。当对等是up状态,"State/PfxRcd"下的输出状态将会从特殊邻居接收到前缀号。在这个例子的输出中,BGP对等只是在AS100和AS200之间呈up状态。因此没有前缀被更改,所以最右边列的数值是0。
配置前缀通告
虚拟机A中执行
192.168.247.146# conf terminal
192.168.247.146(config)# router bgp 100
192.168.247.146(config-router)# network 192.168.1.0/24
192.168.247.146(config-router)# exit
虚拟机B中执行
192.168.247.147# conf terminal
192.168.247.147(config)# router bgp 200
192.168.247.147(config-router)# network 172.17.1.0/24
192.168.247.147(config-router)# exit
以虚拟机B为例:
可以看到前缀数量改变
192.168.247.147# show ip bgp summary
BGP router identifier 10.10.10.2, local AS number 200
RIB entries 3, using 336 bytes of memory
Peers 1, using 4560 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.10.10.1 4 100 40 41 0 0 0 00:37:55 1
Total number of neighbors 1
回到虚拟机B,可以一下命令查看邻居收到的前缀总数
192.168.247.147# show ip bgp neighbors 10.10.10.1 advertised-routes
BGP table version is 0, local router ID is 10.10.10.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 172.17.1.0/24 10.10.10.2 0 32768 i
Total number of prefixes 1
查看哪些前缀是从邻居10.10.10.1收到的
192.168.247.147# show ip bgp neighbors 10.10.10.1 routes
BGP table version is 0, local router ID is 10.10.10.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 192.168.1.0 10.10.10.1 0 0 100 i
Total number of prefixes 1
查看所有的BGP路由器
192.168.247.147# show ip bgp
BGP table version is 0, local router ID is 10.10.10.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 172.17.1.0/24 0.0.0.0 0 32768 i
*> 192.168.1.0 10.10.10.1 0 0 100 i
Total number of prefixes 2
其他命令如查看所有路由、只看BGP路由等
192.168.247.147# show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, A - Babel,
> - selected route, * - FIB route
K>* 0.0.0.0/0 via 192.168.247.2, ens33
C>* 10.10.10.0/30 is directly connected, ens33
C>* 127.0.0.0/8 is directly connected, lo
C>* 172.17.1.0/24 is directly connected, ens36
B>* 192.168.1.0/24 [20/0] via 10.10.10.1, ens33, 00:05:29
C>* 192.168.122.0/24 is directly connected, virbr0
C * 192.168.247.0/24 is directly connected, ens36
C>* 192.168.247.0/24 is directly connected, ens33
192.168.247.147# show ip route bgp
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, A - Babel,
> - selected route, * - FIB route
B>* 192.168.1.0/24 [20/0] via 10.10.10.1, ens33, 00:05:33