将 networkd 与 linux 命名空间一起使用

时间:2021-08-01 13:11:47

标签: ubuntu network-programming systemd linux-namespaces

我目前正在尝试在 Linux 下使用网络命名空间模拟网络。我已经设置了节点并将它们连接起来,它们可以一次 ping 一跳。但我真的很难启用 IP 转发。

我使用的是 Ubuntu Server 21.04,我系统上的网络由 systemd-networkd 控制。 systemd 的版本是 247.3-3ubuntu3.4net.ipv6.conf.all.forwardingnet.ipv4.ip_forward 已启用。 由于使用了 networkd,因此必须另外在配置文件中启用转发。 对于我的命名空间之一,如下所示:

/etc/systemd/network/router1i.network:

[Match]
Name=router1i

[Network]
IPForward=yes

和 /etc/systemd/network/router1i2.network:

[Match]
Name=router1i2

[Network]
IPForward=yes

那些(router1irouter1i2)都是 veth 接口,也是命名空间中仅有的两个接口。

如果我在命名空间中使用命令 ip -6 route get to fe80::1:0:200 iif router1i2,我会得到正确的答案 fe80::1:0:200 from :: dev router1i2 proto kernel metric 256 iif router1i2 pref medium,因为该路由不涉及转发。如果我使用从另一个界面启动的类似命令ip -6 route get to fe80::1:0:200 iif router1i,答案突然是RNETLINK answers: Network is unreachable。很明显,转发没有启用。

我已经尝试通过使用命名空间内的 networkctl reconfigure router1i 来更新网络,但它显示为 Failed to reconfigure network interface router1i: No such device or address。这很奇怪,因为当我使用 networkctl status router1i 时,它正确地列出了所有信息。也已经尝试过使用 networkctl reload 进行完全重新加载,但没有任何改变。

老实说,我的智商已经快不行了。我什至不一定需要让它与 networkd 一起工作。任何想法或解决方法将不胜感激。

0 个答案:

没有答案