systemd-networkd 重置我的静态 eth0.network 配置

systemd-networkd 重置我的静态 eth0.network 配置

我正在运行基于 Yocto 的定制 Linux,内核版本为 5.4.41。我正在使用 systemd-network 来管理我的网络。

root@box:~# systemctl --version
systemd 244 (244.3+)
+PAM -AUDIT -SELINUX +IMA -APPARMOR -SMACK +SYSVINIT -UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID -ELFUTILS +KMOD -IDN2 -IDN -PCRE2 default-hierarchy=hybrid

我使用以下命令启用了 systemd-networkd 详细调试: 如何调试 systemd-networkd?

我想在 'eth0' 的 DHCP 和静态配置之间切换。DHCP 配置工作正常。当我为以下静态配置编写 eth0.network 文件时,该文件在大约 3 秒后被 systemd-networkd 以某种方式“更改”。我不明白它为什么要更改我写的内容,也没有看到明显的错误。

事件:

  1. ip link 设置关闭 eth0
  2. 将配置文件写入 /etc/systemd/network/eth0.network
  3. networkctl 重新加载
  4. networkctl 重新配置 eth0

重新配置命令后,我快速检查了我编写的文件,如下所示:

[Match]
Name=eth0

[Network]
Address=192.168.1.7/24
DNS=192.168.1.1
[Route]
Gateway=192.168.1.1
Destination=0.0.0.0/0
Metric=1024

然后,几秒钟后,networkd 以某种方式将文件重写为如下形式(仅当插入电缆时 - 如果没有插入电缆,文件将保持我写入时的状态):

[Match]
Name=eth0

[Network]
Address=192.168.1.7/24
DNS=192.168.1.7
[Route]
Gateway=192.168.1.7
Destination=192.168.1.7/0
Metric=1024

我无法 ping 通 Google,因为网关错误。我尝试了许多不同的 IP 地址。

以下是重写文件时 systemd-networkd 的详细日志:

Jan 27 15:27:13 box systemd-networkd[9940]: rtnl: received non-static neighbor, ignoring.
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Remembering route: dst: ff00::/8, src: n/a, gw: n/a, prefsrc: n/a, scope: global, table: main, proto: boot, type: unicast
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Remembering route: dst: fe80::/64, src: n/a, gw: n/a, prefsrc: n/a, scope: global, table: main, proto: kernel, type: unicast
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Flags change: +LOWER_UP +RUNNING
Jan 27 15:27:14 box systemd-networkd[9940]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=134 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Gained carrier
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Setting addresses
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Remembering updated address: 192.168.1.7/24 (valid forever)
Jan 27 15:27:14 box systemd-networkd[9940]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=135 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Remembering route: dst: 192.168.1.7/32, src: n/a, gw: n/a, prefsrc: 192.168.1.7, scope: host, table: local, proto: kernel, type: local
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Remembering route: dst: 192.168.1.255/32, src: n/a, gw: n/a, prefsrc: 192.168.1.7, scope: link, table: local, proto: kernel, type: broadcast
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Remembering route: dst: 192.168.1.0/24, src: n/a, gw: n/a, prefsrc: 192.168.1.7, scope: link, table: main, proto: kernel, type: unicast
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Remembering route: dst: 192.168.1.0/32, src: n/a, gw: n/a, prefsrc: 192.168.1.7, scope: link, table: local, proto: kernel, type: broadcast
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Addresses set
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Configuring route: dst: n/a, src: n/a, gw: 192.168.1.1, prefsrc: n/a, scope: global, table: main, proto: static, type: unicast
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Setting routes
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Received remembered route: dst: n/a, src: n/a, gw: 192.168.1.1, prefsrc: n/a, scope: global, table: main, proto: static, type: unicast
Jan 27 15:27:14 box systemd-networkd[9940]: eth0: Routes set
Jan 27 15:27:14 box systemd-networkd[9940]: Got message type=method_call sender=:1.274 destination=org.freedesktop.network1 path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=Get cookie=2 reply_cookie=0 signature=ss error-name=n/a error-message=n/a
Jan 27 15:27:14 box systemd-networkd[9940]: Sent message type=method_return sender=n/a destination=:1.274 path=n/a interface=n/a member=n/a cookie=136 reply_cookie=2 signature=v error-name=n/a error-message=n/a
Jan 27 15:27:14 box systemd-networkd[9940]: Got message type=method_call sender=:1.275 destination=org.freedesktop.network1 path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=Get cookie=2 reply_cookie=0 signature=ss error-name=n/a error-message=n/a
Jan 27 15:27:14 box systemd-networkd[9940]: Sent message type=method_return sender=n/a destination=:1.275 path=n/a interface=n/a member=n/a cookie=137 reply_cookie=2 signature=v error-name=n/a error-message=n/a
Jan 27 15:27:15 box systemd-networkd[9940]: eth0: Remembering foreign address: fe80::691:62ff:fe40:283c/64 (valid forever)
Jan 27 15:27:15 box systemd-networkd[9940]: eth0: Gained IPv6LL
Jan 27 15:27:15 box systemd-networkd[9940]: eth0: State changed: configuring -> configured
Jan 27 15:27:15 box systemd-networkd[9940]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=138 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
Jan 27 15:27:15 box systemd-networkd[9940]: eth0: Discovering IPv6 routers
Jan 27 15:27:15 box systemd-networkd[9940]: NDISC: Started IPv6 Router Solicitation client
Jan 27 15:27:16 box systemd-networkd[9940]: eth0: Remembering route: dst: fe80::691:62ff:fe40:283c/128, src: n/a, gw: n/a, prefsrc: n/a, scope: global, table: main, proto: kernel, type: local
Jan 27 15:27:16 box systemd-networkd[9940]: Got message type=method_call sender=:1.276 destination=org.freedesktop.network1 path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=Get cookie=2 reply_cookie=0 signature=ss error-name=n/a error-message=n/a
Jan 27 15:27:16 box systemd-networkd[9940]: Sent message type=method_return sender=n/a destination=:1.276 path=n/a interface=n/a member=n/a cookie=139 reply_cookie=2 signature=v error-name=n/a error-message=n/a
Jan 27 15:27:17 box systemd-networkd[9940]: NDISC: Sent Router Solicitation, next solicitation in 4s

我如何避免 systemd-networkd 重写我的文件?谢谢。

相关内容