添加第二个接口后 Linux 桥停止工作

添加第二个接口后 Linux 桥停止工作

我试图在 Mac 上的 Linux VM 中桥接两个接口,但将第二个接口添加到桥中会破坏一切。我希望就我做错的事情得到一些指导。

设置:

  • 网络 ------ MacOS / eth0:VirtualBoxLinux:eth1 ---- 树莓派
  • Linux VM 是在 MacOS 10.14.3 上的 VirtualBox 6.0 中全新安装的基于 debian-9 的发行版。
  • MacOS 通过 Wifi 连接到网络
  • VirtualBox 将桥接网络接口暴露给 VM 作为 eth0
  • Apple USB 以太网适配器已插入虚拟机,公开为 eth1
  • 将树莓派插入 USB 适配器以进行测试。

目标是通过桥接 eth0 和 eth1 让树莓派直接位于主网络上。

如果我启动 eth0 并从虚拟机内给它一个 IP,Linux 虚拟机就可以愉快地与网络通信。

如果我创建一个仅包含 eth0 的网桥并为该网桥指定一个 IP,Linux 虚拟机仍然可以与网络通信。

如果我随后将 eth1 添加到网桥,Linux 虚拟机将无法再与网络通信。此时,树莓派可以通过 DHCP 获取 IP,但似乎也无法与网络通信。

如果我从网桥中删除 eth1,Linux 虚拟机的网络连接就会恢复。

编辑:尽管我在网桥上禁用了 STP,但在设置 br0 后我还是等了一段时间,看看事情是否会更好。事实上,“brctl showstp”显示了 eth0 和 eth1 上的转发,并且树莓派能够以某种方式通过 DHCP 获取 IP,这意味着至少有或多或少的事情正在发生。

细节:

启动配置:接口已启动,未分配 IP:

root@cbpp:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:06:fd:0a  txqueuelen 1000  (Ethernet)
        RX packets 6325015  bytes 7231844627 (6.7 GiB)
        RX errors 0  dropped 75  overruns 0  frame 0
        TX packets 1129  bytes 84075 (82.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 04:69:f8:eb:c8:1a  txqueuelen 1000  (Ethernet)
        RX packets 100  bytes 9369 (9.1 KiB)
        RX errors 1  dropped 0  overruns 0  frame 0
        TX packets 39002  bytes 5454636 (5.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

创建网桥,添加 eth0,通过 DHCP 获取 IP,ping 主机:

root@cbpp:~# brctl addbr br0
root@cbpp:~# brctl addif br0 eth0
root@cbpp:~# brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.08002706fd0a   no      eth0
root@cbpp:~# ifconfig br0 up
root@cbpp:~# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:06:fd:0a  txqueuelen 1000  (Ethernet)
        RX packets 161  bytes 16286 (15.9 KiB)
        RX errors 0  dropped 4  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:06:fd:0a  txqueuelen 1000  (Ethernet)
        RX packets 6352292  bytes 7256149955 (6.7 GiB)
        RX errors 0  dropped 76  overruns 0  frame 0
        TX packets 1129  bytes 84075 (82.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 04:69:f8:eb:c8:1a  txqueuelen 1000  (Ethernet)
        RX packets 106  bytes 9645 (9.4 KiB)
        RX errors 1  dropped 0  overruns 0  frame 0
        TX packets 39002  bytes 5454636 (5.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@cbpp:~# dhclient br0 -v
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/br0/08:00:27:06:fd:0a
Sending on   LPF/br0/08:00:27:06:fd:0a
Sending on   Socket/fallback
DHCPREQUEST of 192.168.28.236 on br0 to 255.255.255.255 port 67
DHCPACK of 192.168.28.236 from 192.168.28.1
bound to 192.168.28.236 -- renewal in 3046 seconds.

root@cbpp:~# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.28.236  netmask 255.255.255.0  broadcast 192.168.28.255
        ether 08:00:27:06:fd:0a  txqueuelen 1000  (Ethernet)
        RX packets 869  bytes 100262 (97.9 KiB)
        RX errors 0  dropped 11  overruns 0  frame 0
        TX packets 45  bytes 4656 (4.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:06:fd:0a  txqueuelen 1000  (Ethernet)
        RX packets 6400166  bytes 7294827072 (6.7 GiB)
        RX errors 0  dropped 77  overruns 0  frame 0
        TX packets 1174  bytes 88761 (86.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 04:69:f8:eb:c8:1a  txqueuelen 1000  (Ethernet)
        RX packets 112  bytes 9921 (9.6 KiB)
        RX errors 1  dropped 0  overruns 0  frame 0
        TX packets 39002  bytes 5454636 (5.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


root@cbpp:~# ping -c 1 192.168.28.1
PING 192.168.28.1 (192.168.28.1) 56(84) bytes of data.
64 bytes from 192.168.28.1: icmp_seq=1 ttl=64 time=1.21 ms

--- 192.168.28.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.213/1.213/1.213/0.000 ms

将 eth1 添加到网桥,看到连接失败。注意:此时,树莓派能够通过 DHCP 在其 eth0 上获取 IP,但似乎也没有经过该点。

root@cbpp:~# brctl addif br0 eth1
root@cbpp:~# ping -c 1 192.168.28.1
PING 192.168.28.1 (192.168.28.1) 56(84) bytes of data.
From 192.168.28.236 icmp_seq=1 Destination Host Unreachable

--- 192.168.28.1 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

此时的配置详细信息(使用 eth0/eth1 设置网桥但不工作):

root@cbpp:~# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.28.236  netmask 255.255.255.0  broadcast 192.168.28.255
        ether 04:69:f8:eb:c8:1a  txqueuelen 1000  (Ethernet)
        RX packets 5755  bytes 668798 (653.1 KiB)
        RX errors 0  dropped 11  overruns 0  frame 0
        TX packets 82  bytes 9698 (9.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:06:fd:0a  txqueuelen 1000  (Ethernet)
        RX packets 6590263  bytes 7428675506 (6.9 GiB)
        RX errors 0  dropped 83  overruns 0  frame 0
        TX packets 1217  bytes 94469 (92.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 04:69:f8:eb:c8:1a  txqueuelen 1000  (Ethernet)
        RX packets 148  bytes 11577 (11.3 KiB)
        RX errors 1  dropped 0  overruns 0  frame 0
        TX packets 40112  bytes 5608073 (5.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@cbpp:~# brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.0469f8ebc81a   no      eth0
                            eth1

root@cbpp:~# brctl showstp br0
br0
 bridge id      8000.0469f8ebc81a
 designated root    8000.0469f8ebc81a
 root port         0            path cost          0
 max age          20.00         bridge max age        20.00
 hello time        2.00         bridge hello time      2.00
 forward delay        15.00         bridge forward delay      15.00
 ageing time         300.00
 hello timer           0.00         tcn timer          0.00
 topology change timer     0.00         gc timer          73.23
 flags


eth0 (1)
 port id        8001            state            forwarding
 designated root    8000.0469f8ebc81a   path cost          4
 designated bridge  8000.0469f8ebc81a   message age timer      0.00
 designated port    8001            forward delay timer    0.00
 designated cost       0            hold timer         0.00
 flags

eth1 (2)
 port id        8002            state            forwarding
 designated root    8000.0469f8ebc81a   path cost         19
 designated bridge  8000.0469f8ebc81a   message age timer      0.00
 designated port    8002            forward delay timer    0.00
 designated cost       0            hold timer         0.00
 flags

root@cbpp:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

root@cbpp:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.28.1    0.0.0.0         UG    0      0        0 br0
192.168.28.0    0.0.0.0         255.255.255.0   U     0      0        0 br0

从网桥中删除 eth1,连接恢复:

root@cbpp:~# brctl delif br0 eth1
root@cbpp:~# ping -c 1 192.168.28.1
PING 192.168.28.1 (192.168.28.1) 56(84) bytes of data.
64 bytes from 192.168.28.1: icmp_seq=1 ttl=64 time=2.50 ms

--- 192.168.28.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 2.504/2.504/2.504/0.000 ms
root@cbpp:~#

谢谢!

相关内容