当前位置: 代码迷 >> 综合 >> 使用Quagga测试IPv4/IPv6 BGP双栈动态路由(by quqi99)
  详细解决方案

使用Quagga测试IPv4/IPv6 BGP双栈动态路由(by quqi99)

热度:88   发布时间:2023-12-13 09:16:24.0

作者:张华  发表于:2016-07-04
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明

( http://blog.csdn.net/quqi99 )


测试环境 

测试环境依然用上次测STT的两台物理机, 已有的网络环境如下:


node1, duduo.seg, 

  • eth0: 10.230.56.14,   1000Mb/s,  br-ex
  • eth6: 10.230.56.15,  10000Mb/s, out-off-band management
  • eth7: 192.168.122.2, 10000Mb/s, br-phy
sudo ovs-vsctl -- --may-exist add-br br-ex
sudo ovs-vsctl -- --may-exist add-port br-ex eth0
sudo ifconfig eth0 0.0.0.0 up
sudo ifconfig br-ex 10.230.56.233/21
sudo ovs-vsctl -- --may-exist add-br br-phy
sudo ovs-vsctl -- --may-exist add-port br-phy eth7
sudo ifconfig eth7 0.0.0.0 up
sudo ifconfig br-phy 192.168.122.2/24

node2, voltorb.seg,
  • eth0: 10.230.56.21,   1000Mb/s, out-off-band management
  • eth4: 192.168.122.3, 10000Mb/s, br-phy
sudo ovs-vsctl -- --may-exist add-br br-phy
sudo ovs-vsctl -- --may-exist add-port br-phy eth4
sudo ifconfig eth4 0.0.0.0 up
sudo ifconfig br-phy 192.168.122.3/24

这次BGP实验规划的新增的网络环境如下:
-------------------------------       -------------------------------
|   eth6: 10.230.56.15/21     |-------|   eth0: 10.230.56.21/21     |
|   eth6: 2001:db8:3::1/64    |       |   eth0: 2001:db8:3::2/64    |
|     AS: 100                 |       |     AS: 200                 |
| br-phy: 2001:db8:1::1/64    |-------| br-phy: 2001:db8:2::1/64    |       
| br-phy: 192.168.1.1/24      |       | br-phy: 192.168.2.1/24      |
-------------------------------       -------------------------------
sudo ip addr add 2001:db8:3::1/64 dev eth6
sudo ip addr add 2001:db8:1::1/64 dev br-phy
sudo ip addr add 192.168.1.1/24 dev br-phy

sudo ip addr add 2001:db8:3::2/64 dev eth0
sudo ip addr add 2001:db8:2::1/64 dev br-phy
sudo ip addr add 192.168.2.1/24 dev br-phy

Quagga安装及防火墙配置

sudo apt-get install quagga 
sudo chown quagga.quaggavty /etc/quagga/*.conf
sudo chmod 640 /etc/quagga/*.conf

echo "net.ipv4.conf.all.forwarding=1" | sudo tee -a /etc/sysctl.conf 
echo "net.ipv4.conf.default.forwarding=1" | sudo tee -a /etc/sysctl.conf 
sed 's/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=1/g' /etc/sysctl.conf | sudo tee /etc/sysctl.conf
echo "net.ipv6.conf.default.forwarding=1" | sudo tee -a /etc/sysctl.conf 
sudo sysctl -p
sudo ip6tables -F

# BGP sessions
sudo iptables -A INPUT -p tcp --dport 179 -j ACCEPT
sudo iptables -A INPUT -p tcp --sport 179 -j ACCEPT
# Telnet session to zebra
sudo iptables -A INPUT -p tcp --dport 2601 -j ACCEPT
# Telnet session to quagga/bgpd
sudo iptables -A INPUT -p tcp --dport 2605 -j ACCEPT

Quagga配置文件

1, 两节点上的配置文件 /etc/quagga/zebra.conf
sudo cp /usr/share/doc/quagga/examples/zebra.conf.sample /etc/quagga/zebra.conf
ubuntu@duduo:~$ sudo cat /etc/quagga/zebra.conf
hostname duduo         #另一台节点修改为voltorb
password zebra
enable password zebra
log file /var/log/quagga/zebra.log

1, 两节点上的配置文件 /etc/quagga/daemons
ubuntu@duduo:~$ sudo cat /etc/quagga/daemons 
zebra=yes
bgpd=yes

ospfd=no
ospf6d=no
ripd=no
ripngd=no
isisd=no
babeld=no

3, 两节点上的配置文件 /etc/quagga/bgpd.conf如下:
ubuntu@duduo:~$ sudo cat /etc/quagga/bgpd.conf hostname duduo password zebra log file /var/log/quagga/bgpd.log log stdout ! router bgp 100 no synchronization bgp router-id 10.230.56.15 network 192.168.1.0/24 neighbor 10.230.56.21 remote-as 200 neighbor 10.230.56.21 description test-v4 neighbor 2001:db8:3::2 remote-as 200 neighbor 2001:db8:3::2 description test-v6 no auto-summary no neighbor 2001:db8:3::2 activate ! address-family ipv6 network 2001:db8:1::/48 network 2001:db8:1::/56 network 2001:db8:1::/64 neighbor 2001:db8:3::2 activate neighbor 2001:db8:3::2 route-map IPV6-OUT out exit-address-family ! ipv6 prefix-list pl-ipv6 seq 10 permit 2001:db8:1::/56 le 64 route-map IPV6-OUT permit 10 match ipv6 address prefix-list pl-ipv6 set ipv6 next-hop global 2001:db8:3::1 ! line vty ! debug bgp events debug bgp filters !debug bgp fsm !debug bgp keepalives debug bgp updates 

ubuntu@voltorb:~$ sudo cat /etc/quagga/bgpd.conf hostname voltorb password zebra log file /var/log/quagga/bgpd.log log stdout ! router bgp 200 no synchronization bgp router-id 10.230.56.21 network 192.168.2.0/24 neighbor 10.230.56.15 remote-as 100 neighbor 10.230.56.15 description test-v4 neighbor 2001:db8:3::1 remote-as 100 neighbor 2001:db8:3::1 description test-v6 no auto-summary no neighbor 2001:db8:3::1 activate ! address-family ipv6 network 2001:db8:2::/48 network 2001:db8:2::/56 network 2001:db8:2::/64 neighbor 2001:db8:3::1 activate neighbor 2001:db8:3::1 route-map IPV6-OUT out exit-address-family ! ipv6 prefix-list pl-ipv6 seq 10 permit 2001:db8:2::/56 le 64 route-map IPV6-OUT permit 10 match ipv6 address prefix-list pl-ipv6 set ipv6 next-hop global 2001:db8:3::2 ! line vty ! debug bgp events debug bgp filters !debug bgp fsm !debug bgp keepalives debug bgp updates


验证结果

两节点上重启quagga进程(sudo service quagga restart)后观察到的邻居信息如下:

ubuntu@duduo:~$ sudo vtyshHello, this is Quagga (version 0.99.22.4). Copyright 1996-2005 Kunihiro Ishiguro, et al.duduo# show bgp summary BGP router identifier 10.230.56.15, local AS number 100 RIB entries 6, using 672 bytes of memory Peers 2, using 9120 bytes of memoryNeighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 2001:db8:3::2 4 200 10 11 0 0 0 00:06:30 2Total number of neighbors 1ubuntu@voltorb:~$ sudo vtyshHello, this is Quagga (version 0.99.22.4). Copyright 1996-2005 Kunihiro Ishiguro, et al.voltorb# show bgp summary BGP router identifier 10.230.56.21, local AS number 200 RIB entries 6, using 672 bytes of memory Peers 2, using 9120 bytes of memoryNeighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 2001:db8:3::1 4 100 11 14 0 0 0 00:08:22 2Total number of neighbors 1


两节点观察到的日志分别如下:

2016/07/04 09:29:46 BGP: BGPd 0.99.22.4 starting: vty@2605, bgp@<all>:179 2016/07/04 09:29:46 BGP: Import timer expired. 2016/07/04 09:29:49 BGP: [Event] BGP connection from host 2001:db8:3::2 2016/07/04 09:29:49 BGP: [Event] BGP connection IP address 2001:db8:3::2 is Idle state 2016/07/04 09:29:50 BGP: 2001:db8:3::2 [Event] Connect start to 2001:db8:3::2 fd 13 2016/07/04 09:29:51 BGP: 2001:db8:3::2 send UPDATE 2001:db8:1::/56 2016/07/04 09:29:51 BGP: 2001:db8:3::2 send UPDATE 2001:db8:1::/64 2016/07/04 09:29:51 BGP: 2001:db8:3::2 rcvd UPDATE w/ attr: , origin i, mp_nexthop 2001:db8:3::2(fe80::3ea8:2aff:fe21:9908), metric 0, path 200 2016/07/04 09:29:51 BGP: 2001:db8:3::2 rcvd 2001:db8:2::/56 2016/07/04 09:29:51 BGP: 2001:db8:3::2 rcvd UPDATE w/ attr: , origin i, mp_nexthop 2001:db8:3::2(fe80::3ea8:2aff:fe21:9908), metric 0, path 200 2016/07/04 09:29:51 BGP: 2001:db8:3::2 rcvd 2001:db8:2::/64 2016/07/04 09:29:53 BGP: 10.230.56.21 [Event] Connect start to 10.230.56.21 fd 14 2016/07/04 09:29:54 BGP: 10.230.56.21 send UPDATE 192.168.1.0/24 2016/07/04 09:29:54 BGP: 10.230.56.21 rcvd UPDATE w/ attr: nexthop 10.230.56.21, origin i, metric 0, path 200 2016/07/04 09:29:54 BGP: 10.230.56.21 rcvd 192.168.2.0/242016/07/04 09:29:11 BGP: 2001:db8:3::1 [Event] Connect start to 2001:db8:3::1 fd 13 2016/07/04 09:29:11 BGP: stream_read_try: read failed on fd 13: Connection reset by peer 2016/07/04 09:29:11 BGP: 2001:db8:3::1 [Error] bgp_read_packet error: Connection reset by peer 2016/07/04 09:29:12 BGP: [Event] BGP connection from host 2001:db8:3::1 2016/07/04 09:29:12 BGP: [Event] Make dummy peer structure until read Open packet 2016/07/04 09:29:12 BGP: 2001:db8:3::1 [Event] Transfer accept BGP peer to real (state Active) 2016/07/04 09:29:12 BGP: 2001:db8:3::1 [Event] Accepting BGP peer delete 2016/07/04 09:29:13 BGP: 2001:db8:3::1 send UPDATE 2001:db8:2::/56 2016/07/04 09:29:13 BGP: 2001:db8:3::1 send UPDATE 2001:db8:2::/64 2016/07/04 09:29:13 BGP: 2001:db8:3::1 rcvd UPDATE w/ attr: , origin i, mp_nexthop 2001:db8:3::1(fe80::8edc:d4ff:feb3:9c3c), metric 0, path 100 2016/07/04 09:29:13 BGP: 2001:db8:3::1 rcvd 2001:db8:1::/56 2016/07/04 09:29:13 BGP: 2001:db8:3::1 rcvd UPDATE w/ attr: , origin i, mp_nexthop 2001:db8:3::1(fe80::8edc:d4ff:feb3:9c3c), metric 0, path 100 2016/07/04 09:29:13 BGP: 2001:db8:3::1 rcvd 2001:db8:1::/64 2016/07/04 09:29:15 BGP: [Event] BGP connection from host 10.230.56.15 2016/07/04 09:29:15 BGP: [Event] Make dummy peer structure until read Open packet 2016/07/04 09:29:15 BGP: 10.230.56.15 [Event] Transfer accept BGP peer to real (state Active) 2016/07/04 09:29:15 BGP: 10.230.56.15 [Event] Accepting BGP peer delete 2016/07/04 09:29:16 BGP: 10.230.56.15 send UPDATE 192.168.2.0/24 2016/07/04 09:29:16 BGP: 10.230.56.15 rcvd UPDATE w/ attr: nexthop 10.230.56.15, origin i, metric 0, path 100 2016/07/04 09:29:16 BGP: 10.230.56.15 rcvd 192.168.1.0/24 

路由变化如下:

ubuntu@duduo:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.230.56.1 0.0.0.0 UG 0 0 0 eth6 10.230.56.0 0.0.0.0 255.255.248.0 U 0 0 0 eth6 10.230.56.0 0.0.0.0 255.255.248.0 U 0 0 0 br-ex 10.230.56.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br-phy 192.168.2.0 10.230.56.21 255.255.255.0 UG 0 0 0 eth6 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 br-phy ubuntu@duduo:~$ route -n |grep 192.168.2 192.168.2.0 10.230.56.21 255.255.255.0 UG 0 0 0 eth6 ubuntu@duduo:~$ ping -c 1 192.168.2.1 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.232 ms--- 192.168.2.1 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.232/0.232/0.232/0.000 ms ubuntu@duduo:~$ ping6 -c 1 2001:db8:2::1 PING 2001:db8:2::1(2001:db8:2::1) 56 data bytes 64 bytes from 2001:db8:2::1: icmp_seq=1 ttl=64 time=0.287 ms--- 2001:db8:2::1 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.287/0.287/0.287/0.000 msubuntu@duduo:~$ route -n -6 |grep 2001:db8:2 2001:db8:2::/64 fe80::3ea8:2aff:fe21:9908 UG 1024 1 0 eth6 2001:db8:2::/56 fe80::3ea8:2aff:fe21:9908 UG 1024 0 0 eth6