为什么我无法在桥接模式下的两个兄弟 macvlan 之间 ping 通?

为什么我无法在桥接模式下的两个兄弟 macvlan 之间 ping 通?

在连接到我的家庭 LAN 的 Ubuntu 20.04 计算机中,我在以太网设备下创建了 macvlan:

$ sudo ip link add macvlan1 link enp37s0 type macvlan mode bridge
$ sudo dhclient macvlan1
$ sudo ip link add macvlan2 link enp37s0 type macvlan mode bridge
$ sudo dhclient macvlan2

一次偶然的机会,他们从 DHCP 获得了以下地址:

  • macvlan1:192.168.0.40
  • macvlan2:192.168.0.41

我可以从每个路由器上 ping 通我的路由器:

$ ping 192.168.0.1 -I macvlan1
PING 192.168.0.1 (192.168.0.1) from 192.168.0.40 macvlan1: 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.713 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=1.25 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=1.20 ms
^C
--- 192.168.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2034ms
rtt min/avg/max/mdev = 0.713/1.052/1.245/0.240 ms

$ ping 192.168.0.1 -I macvlan2
PING 192.168.0.1 (192.168.0.1) from 192.168.0.41 macvlan2: 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=1.15 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=1.13 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=1.07 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=64 time=0.548 ms
64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=0.619 ms
^C
--- 192.168.0.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4030ms
rtt min/avg/max/mdev = 0.548/0.903/1.148/0.263 ms

由于它们是在桥接模式下创建的,因此虚拟设备应该相互连接。但我无法 ping 通另一个:

$ ping 192.168.0.40 -I macvlan2
PING 192.168.0.40 (192.168.0.40) from 192.168.0.41 macvlan2: 56(84) bytes of data.
^C
--- 192.168.0.40 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4128ms

$ ping 192.168.0.41 -I macvlan1
PING 192.168.0.41 (192.168.0.41) from 192.168.0.40 macvlan1: 56(84) bytes of data.
^C
--- 192.168.0.41 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2039ms

为什么我无法 ping 通另一个?如何解决这个问题?

答案1

Linux 内核检测具有本地源地址的传入数据包,将其视为路由错误(特定计算机发出的数据包永远不会返回),并丢弃它们以防止网络泛洪。

尝试将每个 macvlan 放入不同的网络命名空间(毕竟,macvlan 被设计为从网络命名空间使用)。那么它应该可以工作。

相关内容