啟動時未建立 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 設定檔是區分大小寫的 - 確保所有內容都以正確的大小寫正確輸入,否則它將無法運作。

相關內容