启动时未创建 Systemd-networkd 桥

启动时未创建 Systemd-networkd 桥

我正在尝试使用 systemd-networkd 创建以太网桥,以便 KVM 来宾可以访问网络。我在 Debian 11 Bullseye 上,尝试在物理设备“eno1”上创建桥“host1”。

root@debian-kvm:/etc/systemd/network# ls
    
20-wired.network  host1.netdev  host1.network  uplink.network

root@debian-kvm:/etc/systemd/network# cat 20-wired.network

[Match]
Name=eno1

[Network]
DHCP=No
Address=192.168.1.57/24
Gateway=192.168.1.1
DNS=1.1.1.1

root@debian-kvm:/etc/systemd/network# cat host1.netdev

[Netdev]
Name=host1
Kind=bridge

root@debian-kvm:/etc/systemd/network# cat host1.network

[Match]
Name=host1

[Network]
Address=192.168.1.2/24
Gateway=192.168.1.1
DNS=1.1.1.1

root@debian-kvm:/etc/systemd/network# cat uplink.network

[Match]
Name=eno1

[Network]
Bridge=host1

但是,当我执行“systemctl restart systemd-networkd”时,它不起作用。 eno1 很好,保留了网络连接,我可以 ping 通网站和 IP 地址,但桥接主机 1 从未出现。

root@debian-kvm:/etc/systemd/network# networkctl

IDX LINK TYPE     OPERATIONAL SETUP
  1 lo   loopback carrier     unmanaged
  2 eno1 ether    routable    configured
  3 eno2 ether    off         unmanaged
  4 eno3 ether    off         unmanaged
  5 eno4 ether    off         unmanaged

root@debian-kvm:/etc/systemd/network# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether b8:ca:3a:64:65:88 brd ff:ff:ff:ff:ff:ff
    altname enp1s0f0
3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether b8:ca:3a:64:65:89 brd ff:ff:ff:ff:ff:ff
    altname enp1s0f1
4: eno3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether b8:ca:3a:64:65:8a brd ff:ff:ff:ff:ff:ff
    altname enp1s0f2
5: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether b8:ca:3a:64:65:8b brd ff:ff:ff:ff:ff:ff
    altname enp1s0f3

据我所知,它应该有效。这些文件位于 /etc/systemd/network 中,优先级最高,有一个具有正确语法和名称的 .netdev 文件,有一个 uplink.network 文件指示父级为 eno1,还有一个 host1.network 文件用于配置IP、DNS等将host1.network移动到25-wired.network也没有帮助,所以它似乎不是文件名。

如果它位于 /etc/network/interfaces 中,但我不认为 systemd-networkd 会读取此文件:

root@debian-kvm:/etc/systemd/network# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eno1
iface eno1 inet manual

# KVM Host interface, use this to avoid conflicts, physical device is just for physical connection
iface host1 inet manual

# FreeBSD KVM bridge
#iface frbsd1 inet static
#   bridge_ports eno1
#   address 192.168.1.45
#   broadcast 192.168.1.255
#   netmask 255.255.255.0
#   gateway 192.168.1.1

我知道我可以创建一个初始化脚本来在每次启动时创建一个桥,但这有点老套,我想以可持续的方式解决这个问题。

这里发生了什么以及如何修复它以正确创建桥梁?

答案1

正如 wangkaibule 在问题评论中提到的,我应该输入 [NetDev] 而不是 [Netdev]。

对于处于类似情况的任何人,systemd 配置文件是区分大小写的 - 确保所有内容都以正确的大小写正确输入,否则它将无法工作。

相关内容