BGP/Quagga/Docker 实验室中的连接故障排除

网络工程 BGP 斑驴
2022-02-17 22:18:48

我创建了一个虚拟网络实验室来测试 BGP 路由。该实验室由两个用作最终用户的 Debian Docker 镜像和两个运行 Alpine Linux 和 Quagga 的镜像组成,用作路由器。该实验室具有以下架构:

在此处输入图像描述

容器具有以下网络配置(不包括环回):

PC1# ip addr && ip route 显示

57: eth0@if58: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:13:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.19.0.3/16 brd 172.19.255.255 scope global eth0
       valid_lft forever preferred_lft forever
default via 172.19.0.2 dev eth0 
172.19.0.0/16 dev eth0 proto kernel scope link src 172.19.0.3 

PC2# ip addr && ip route 显示

62: eth0@if63: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:14:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.20.0.3/16 brd 172.20.255.255 scope global eth0
       valid_lft forever preferred_lft forever
default via 172.20.0.2 dev eth0 
172.20.0.0/16 dev eth0 proto kernel scope link src 172.20.0.3

R1# ip addr && ip route 显示

17: eth0@if18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.2/16 brd 172.18.255.255 scope global eth0
       valid_lft forever preferred_lft forever
49: eth3@if50: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:13:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.19.0.2/16 brd 172.19.255.255 scope global eth3
       valid_lft forever preferred_lft forever
default via 172.18.0.1 dev eth0 
172.18.0.0/16 dev eth0  proto kernel  scope link  src 172.18.0.2 
172.19.0.0/16 dev eth3  proto kernel  scope link  src 172.19.0.2 

R2# ip addr && ip route 显示

43: eth0@if44: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:12:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.3/16 brd 172.18.255.255 scope global eth0
       valid_lft forever preferred_lft forever
60: eth1@if61: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:14:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.20.0.2/16 brd 172.20.255.255 scope global eth1
       valid_lft forever preferred_lft forever
default via 172.18.0.1 dev eth0 
172.18.0.0/16 dev eth0  proto kernel  scope link  src 172.18.0.3 
172.20.0.0/16 dev eth1  proto kernel  scope link  src 172.20.0.2 

R1# 显示运行配置

Current configuration:
!
hostname R1
password xxx
!
router bgp 65530
 bgp router-id 172.19.0.2
 network 172.19.0.0/16
 neighbor 172.18.0.3 remote-as 65531
!
line vty
!
end

R2# 显示运行配置

Current configuration:
!
hostname R2
password xxx
!
router bgp 65531
 bgp router-id 172.20.0.2
 network 172.20.0.0/16
 neighbor 172.18.0.2 remote-as 65530
!
line vty
!

R1> 显示 ip bgp

BGP table version is 0, local router ID is 172.19.0.2
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
              i internal, r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 172.19.0.0       0.0.0.0                  0         32768 i
*> 172.20.0.0       172.18.0.3               0             0 65531 i

Total number of prefixes 2

R2> 显示 ip bgp

BGP table version is 0, local router ID is 172.20.0.2
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
              i internal, r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 172.19.0.0       172.18.0.2               0             0 65530 i
*> 172.20.0.0       0.0.0.0                  0         32768 i

Total number of prefixes 2

问题是 PC1 与 R2 或 PC2 没有连接(无法 ping),反之亦然。注意:

  • R1_container 可以 ping 172.18.0.3。
  • PC1可以ping通172.18.0.2。
  • PC1 无法 ping 172.18.0.3。
  • PC1 无法 ping 172.20.0.3。

必须做出哪些改变?

2个回答

在 Zebra 和 BGPD 中启用日志记录并发出 BGP 重置提供了有关我的问题的重要信息:

2019/10/08 09:42:00 ZEBRA: netlink-cmd error: Operation not permitted, type=RTM_NEWROUTE(24), seq=7, pid=0 2019/10/08 09:43:07 ZEBRA: netlink-cmd error: Operation not permitted, type=RTM_NEWROUTE(24), seq=8, pid=0

我相信发生的事情是 Quagga 没有权限将从 BGP 学到的路由添加到其容器的路由表中。为了解决这个问题,使用交换机重新制作了容器--cap-add NET_ADMIN,现在它们可以将路由添加到路由表中。成功的证据:

PC1# ip 路由显示

default via 172.18.0.1 dev eth0 
172.18.0.0/16 dev eth0  proto kernel  scope link  src 172.18.0.2 
172.19.0.0/16 dev eth1  proto kernel  scope link  src 172.19.0.2 
172.20.0.0/16 via 172.18.0.3 dev eth0  proto zebra 

sudo docker run --privileged --cap-add NET_ADMIN --cap-add NET_BROADCAST -d -ti --name Q1 ubuntu:16.04

使用此选项--privileged

因为需要修改为vim /etc/sysctl.conf, net.ipv4.ip_forward=1

修改后执行sysctl -p

使用此选项--cap-add NET_ADMIN--cap-add NET_BROADCAST​​。

因为 Quagga 需要有修改 Routing 表的权限。

希望这对您有所帮助。