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

来源:互联网 发布:php cli 获取服务器ip 编辑:程序博客网 时间:2024/05/16 07:50

作者:张华  发表于: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 duduopassword zebralog file /var/log/quagga/bgpd.loglog stdout!router bgp 100 no synchronization bgp router-id 10.230.56.15network 192.168.1.0/24neighbor 10.230.56.21 remote-as 200neighbor 10.230.56.21 description test-v4neighbor 2001:db8:3::2 remote-as 200neighbor 2001:db8:3::2 description test-v6no auto-summaryno neighbor 2001:db8:3::2 activate!address-family ipv6network 2001:db8:1::/48network 2001:db8:1::/56network 2001:db8:1::/64neighbor 2001:db8:3::2 activateneighbor 2001:db8:3::2 route-map IPV6-OUT outexit-address-family!ipv6 prefix-list pl-ipv6 seq 10 permit 2001:db8:1::/56 le 64route-map IPV6-OUT permit 10match ipv6 address prefix-list pl-ipv6set ipv6 next-hop global 2001:db8:3::1!line vty!debug bgp eventsdebug bgp filters!debug bgp fsm!debug bgp keepalivesdebug bgp updates

ubuntu@voltorb:~$ sudo cat /etc/quagga/bgpd.confhostname voltorbpassword zebralog file /var/log/quagga/bgpd.loglog stdout!router bgp 200no synchronizationbgp router-id 10.230.56.21network 192.168.2.0/24neighbor 10.230.56.15 remote-as 100neighbor 10.230.56.15 description test-v4neighbor 2001:db8:3::1 remote-as 100neighbor 2001:db8:3::1 description test-v6no auto-summaryno neighbor 2001:db8:3::1 activate!address-family ipv6network 2001:db8:2::/48network 2001:db8:2::/56network 2001:db8:2::/64neighbor 2001:db8:3::1 activateneighbor 2001:db8:3::1 route-map IPV6-OUT outexit-address-family!ipv6 prefix-list pl-ipv6 seq 10 permit 2001:db8:2::/56 le 64route-map IPV6-OUT permit 10match ipv6 address prefix-list pl-ipv6set ipv6 next-hop global 2001:db8:3::2!line vty!debug bgp eventsdebug bgp filters!debug bgp fsm!debug bgp keepalivesdebug 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 summaryBGP router identifier 10.230.56.15, local AS number 100RIB entries 6, using 672 bytes of memoryPeers 2, using 9120 bytes of memoryNeighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd2001: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 summaryBGP router identifier 10.230.56.21, local AS number 200RIB entries 6, using 672 bytes of memoryPeers 2, using 9120 bytes of memoryNeighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd2001: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>:1792016/07/04 09:29:46 BGP: Import timer expired.2016/07/04 09:29:49 BGP: [Event] BGP connection from host 2001:db8:3::22016/07/04 09:29:49 BGP: [Event] BGP connection IP address 2001:db8:3::2 is Idle state2016/07/04 09:29:50 BGP: 2001:db8:3::2 [Event] Connect start to 2001:db8:3::2 fd 132016/07/04 09:29:51 BGP: 2001:db8:3::2 send UPDATE 2001:db8:1::/562016/07/04 09:29:51 BGP: 2001:db8:3::2 send UPDATE 2001:db8:1::/642016/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 2002016/07/04 09:29:51 BGP: 2001:db8:3::2 rcvd 2001:db8:2::/562016/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 2002016/07/04 09:29:51 BGP: 2001:db8:3::2 rcvd 2001:db8:2::/642016/07/04 09:29:53 BGP: 10.230.56.21 [Event] Connect start to 10.230.56.21 fd 142016/07/04 09:29:54 BGP: 10.230.56.21 send UPDATE 192.168.1.0/242016/07/04 09:29:54 BGP: 10.230.56.21 rcvd UPDATE w/ attr: nexthop 10.230.56.21, origin i, metric 0, path 2002016/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 132016/07/04 09:29:11 BGP: stream_read_try: read failed on fd 13: Connection reset by peer2016/07/04 09:29:11 BGP: 2001:db8:3::1 [Error] bgp_read_packet error: Connection reset by peer2016/07/04 09:29:12 BGP: [Event] BGP connection from host 2001:db8:3::12016/07/04 09:29:12 BGP: [Event] Make dummy peer structure until read Open packet2016/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 delete2016/07/04 09:29:13 BGP: 2001:db8:3::1 send UPDATE 2001:db8:2::/562016/07/04 09:29:13 BGP: 2001:db8:3::1 send UPDATE 2001:db8:2::/642016/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 1002016/07/04 09:29:13 BGP: 2001:db8:3::1 rcvd 2001:db8:1::/562016/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 1002016/07/04 09:29:13 BGP: 2001:db8:3::1 rcvd 2001:db8:1::/642016/07/04 09:29:15 BGP: [Event] BGP connection from host 10.230.56.152016/07/04 09:29:15 BGP: [Event] Make dummy peer structure until read Open packet2016/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 delete2016/07/04 09:29:16 BGP: 10.230.56.15 send UPDATE 192.168.2.0/242016/07/04 09:29:16 BGP: 10.230.56.15 rcvd UPDATE w/ attr: nexthop 10.230.56.15, origin i, metric 0, path 1002016/07/04 09:29:16 BGP: 10.230.56.15 rcvd 192.168.1.0/24

路由变化如下:

ubuntu@duduo:~$ route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         10.230.56.1     0.0.0.0         UG    0      0        0 eth610.230.56.0     0.0.0.0         255.255.248.0   U     0      0        0 eth610.230.56.0     0.0.0.0         255.255.248.0   U     0      0        0 br-ex10.230.56.0     0.0.0.0         255.255.248.0   U     0      0        0 eth0192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br-phy192.168.2.0     10.230.56.21    255.255.255.0   UG    0      0        0 eth6192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 br-phyubuntu@duduo:~$ route -n |grep 192.168.2192.168.2.0     10.230.56.21    255.255.255.0   UG    0      0        0 eth6ubuntu@duduo:~$ ping -c 1 192.168.2.1PING 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 0msrtt min/avg/max/mdev = 0.232/0.232/0.232/0.000 msubuntu@duduo:~$ ping6 -c 1 2001:db8:2::1PING 2001:db8:2::1(2001:db8:2::1) 56 data bytes64 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 0msrtt min/avg/max/mdev = 0.287/0.287/0.287/0.000 msubuntu@duduo:~$ route -n -6 |grep 2001:db8:22001:db8:2::/64                fe80::3ea8:2aff:fe21:9908  UG   1024 1     0 eth62001:db8:2::/56                fe80::3ea8:2aff:fe21:9908  UG   1024 0     0 eth6



0 0