我使用 4 个以太网插座中的 2 个作为桥接器,并使用 netplan 进行配置:
network:
version: 2
renderer: networkd
ethernets:
eno1:
dhcp4: no
eno2:
dhcp4: no
eno3:
dhcp4: no
dhcp6: no
addresses: [192.168.0.23/24]
eno4:
dhcp4: no
dhcp6: no
addresses: [192.168.0.24/24]
bridges:
br0:
interfaces: [eno1, eno2]
addresses: [192.168.0.4/24]
gateway4: 192.168.0.1
link-local: []
nameservers:
search: []
addresses: [8.8.8.8]
运行时没有问题sudo netplan apply
,但重启时连接丢失(eno1 连接到互联网路由器,eno2 连接到另一台没有互联网访问的服务器,eno3 和 eno4 没有插入)。运行后它再次正常工作sudo netplan apply
。
我设置了SYSTEMD_LOG_LEVEL=debug
环境变量并发现了这些令人费解的条目:
May 24 19:08:00 dave systemd-networkd[2900]: eno2: Joined netdev
May 24 19:08:00 dave systemd-networkd[2900]: eno2: Bringing link up
May 24 19:08:01 dave systemd-networkd[2900]: eno1: rtnl: received neighbor message with invalid family '7', ignoring.
May 24 19:08:01 dave systemd-networkd[2900]: eno1: rtnl: received neighbor message with invalid family '7', ignoring.
May 24 19:08:01 dave systemd-networkd[2900]: br0: MAC address: 00:22:19:cc:db:0c
May 24 19:08:01 dave systemd-networkd[2900]: eno1: Joined netdev
May 24 19:08:01 dave systemd-networkd[2900]: eno1: Bringing link up
May 24 19:08:01 dave systemd-networkd[2900]: br0: Remembering updated address: 192.168.0.4/24 (valid forever)
May 24 19:08:01 dave systemd-networkd[2900]: br0: Addresses set
May 24 19:08:01 dave systemd-networkd[2900]: br0: Configuring route: dst: n/a, src: n/a, gw: 192.168.0.1, prefsrc: n/a, scope: global, table: main, proto: static, type: unicast
May 24 19:08:01 dave systemd-networkd[2900]: br0: Setting routes
May 24 19:08:01 dave systemd-networkd[2900]: br0: Forgetting address: 192.168.0.4/24 (valid forever)
May 24 19:08:01 dave systemd-networkd[2900]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_36 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=25 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
May 24 19:08:01 dave systemd-networkd[2900]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=26 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
May 24 19:08:01 dave systemd-networkd[2900]: br0: Forgetting route: dst: 192.168.0.0/24, src: n/a, gw: n/a, prefsrc: 192.168.0.4, scope: link, table: main, proto: kernel, type: unicast
May 24 19:08:01 dave systemd-networkd[2900]: br0: Forgetting route: dst: 192.168.0.255/32, src: n/a, gw: n/a, prefsrc: 192.168.0.4, scope: link, table: local, proto: kernel, type: broadcast
May 24 19:08:01 dave systemd-networkd[2900]: br0: Forgetting route: dst: 192.168.0.0/32, src: n/a, gw: n/a, prefsrc: 192.168.0.4, scope: link, table: local, proto: kernel, type: broadcast
May 24 19:08:01 dave systemd-networkd[2900]: br0: Forgetting route: dst: 192.168.0.4/32, src: n/a, gw: n/a, prefsrc: 192.168.0.4, scope: host, table: local, proto: kernel, type: local
May 24 19:08:01 dave systemd-networkd[2900]: eno2: Flags change: +UP +RUNNING
May 24 19:08:01 dave systemd-networkd[2900]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_33 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=27 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
May 24 19:08:01 dave systemd-networkd[2900]: eno2: Link UP
May 24 19:08:01 dave systemd-networkd[2900]: LLDP: Started LLDP client
May 24 19:08:01 dave systemd-networkd[2900]: eno2: Started LLDP.
May 24 19:08:01 dave systemd-networkd[2900]: eno1: Flags change: +UP +RUNNING
May 24 19:08:01 dave systemd-networkd[2900]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=28 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
May 24 19:08:01 dave systemd-networkd[2900]: eno1: Link UP
May 24 19:08:01 dave systemd-networkd[2900]: LLDP: Started LLDP client
May 24 19:08:01 dave systemd-networkd[2900]: eno1: Started LLDP.
May 24 19:08:01 dave systemd-networkd[2900]: br0: Could not set route: Nexthop has invalid gateway. Network is unreachable
May 24 19:08:01 dave systemd-networkd[2900]: br0: Failed
May 24 19:08:01 dave systemd-networkd[2900]: br0: State changed: configuring -> failed
我从这些日志中得到的信息是,networkd 记住了网桥的正确配置(192.168.0.4/24),然后忘记了它,然后抱怨网关(192.168.0.1)无法访问...知道为什么 networkd 会忘记配置,或者如何解决这个问题?
我还没有尝试过像在启动时调用这样的解决方法netplan apply
。
答案1
不完全是答案,但是解决方法对我有用:
sudo crontab -e
@reboot /usr/sbin/netplan apply