我的 netplan 文件如下所示:
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 169.254.1.1/24
mtu: 9000
启动后,eth0
接口采用配置的地址,但 MTU 是默认值 1500。
如果我sudo netplan apply
在启动后手动运行,那么 MTU 会按预期增加到 9000。
启动后,生成的文件systemd-networkd
如下所示。这些文件不是第二次手动应用后发生变化。
$ cat /run/systemd/network/10-netplan-eth0.link
[Match]
OriginalName=eth0
[Link]
WakeOnLan=off
MTUBytes=9000
$ cat /run/systemd/network/10-netplan-eth0.network
[Match]
Name=eth0
[Network]
Address=169.254.1.1/24
systemd-networkd
除了顺序不同之外,日志中没有什么特别突出的地方:
# at boot
Dec 13 06:29:35 ifcb110 systemd-networkd[3233]: eth0: IPv6 successfully enabled
Dec 13 06:29:35 ifcb110 systemd-networkd[3233]: eth0: Link UP
Dec 13 06:29:38 ifcb110 systemd-networkd[3233]: eth0: Gained carrier
Dec 13 06:29:39 ifcb110 systemd-networkd[3233]: eth0: Gained IPv6LL
Dec 13 06:29:39 ifcb110 systemd-networkd[3233]: eth0: Configured
# second time that works
Dec 13 06:39:46 ifcb110 systemd-networkd[6781]: eth0: Gained IPv6LL
Dec 13 06:39:46 ifcb110 systemd-networkd[6781]: eth0: Link is not managed by us
Dec 13 06:39:46 ifcb110 systemd-networkd[6781]: eth0: IPv6 successfully enabled
Dec 13 06:39:49 ifcb110 systemd-networkd[6781]: eth0: Gained carrier
Dec 13 06:39:49 ifcb110 systemd-networkd[6781]: eth0: Configured
输出内容如下netplan --debug apply
(已删节):
$ sudo netplan --debug apply
** (generate:7015): DEBUG: 06:50:14.054: Processing input file //etc/netplan/config.yaml..
** (generate:7015): DEBUG: 06:50:14.054: starting new processing pass
** (generate:7015): DEBUG: 06:50:14.054: eth0: setting default backend to 1
** (generate:7015): DEBUG: 06:50:14.054: Generating output files..
** (generate:7015): DEBUG: 06:50:14.055: NetworkManager: definition eth0 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:device eth0 operstate is up, not replugging
DEBUG:netplan triggering .link rules for eth0
什么原因可能导致设置无法第一次生效?
eth0
(我怀疑在可用的接口和在 .link 文件中应用 udev 规则之间存在竞争。)
答案1
听起来有点像这个错误几年前就已经关闭了,但这个问题仍然存在。
相反,我最终创建了一个[email protected]
包含
[Unit]
Description=Fix MTU on Interface
[Service]
Type=oneshot
ExecStart=/sbin/ip link set dev %i mtu 9000
[Install]
WantedBy=sys-subsystem-net-devices-%i.device
我对这个解决方法不太满意,因为它似乎systemd-networkd
应该为我做到这一点。