我的配置是:
/etc/systemd/network 中的文件:
File: eth0.1.netdev
[NetDev]
Name=enp2s0.1
Kind=vlan
[VLAN]
Id=1
File: 30-static.network
[Match]
MACAddress=b8:ae:ed:eb:b9:2c
[Network]
Address=192.168.1.44/24
Gateway=192.168.1.11
DNS=8.8.8.8
DNS=8.8.4.4
File: eth0.network
[Match]
Name=enp2s0
[Network]
VLAN=enp2s0.1
DHCP=no
File: eth2.1.network
[Match]
Name=enp2s0.1
Kind=vlan
[Network]
DHCP=no
[Address]
Address=192.168.1.25/24
输出ip -d 地址显示跑步后sudo systemctl 重新启动 systemd-networkd
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether b8:ae:ed:eb:b9:2c brd ff:ff:ff:ff:ff:ff promiscuity 0 numtxqueues 1 numrxqueues 1 gso_max_size 64000 gso_max_segs 64
inet 192.168.1.44/24 brd 192.168.1.255 scope global enp2s0
valid_lft forever preferred_lft forever
3: enp2s0.1@enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether b8:ae:ed:eb:b9:2c brd ff:ff:ff:ff:ff:ff promiscuity 0
vlan protocol 802.1Q id 1 <REORDER_HDR> numtxqueues 1 numrxqueues 1 gso_max_size 64000 gso_max_segs 64
inet 192.168.1.44/24 brd 192.168.1.255 scope global enp2s0.1
valid_lft forever preferred_lft forever
inet6 fe80::baae:edff:feeb:b92c/64 scope link
valid_lft forever preferred_lft forever
为什么我没有在 vlan 接口上获取 IP 地址 192.168.1.25/24,但却获取了与分配给非 VLAN 接口相同的 IP 地址?
答案1
在阅读 systemd.network 的手册页后,我找到了解决方案。我改变了
File: 30-static.network to
[Match]
Name=enp2s0
[Network]
Address=192.168.1.44/24
Gateway=192.168.1.11
DNS=8.8.8.8
DNS=8.8.4.4
还将其重命名为 10-static.network。
为什么?MACAddress 匹配会导致与 VLAN 接口发生冲突,因为 VLAN 接口也具有相同的 MACAddress。因此,命名接口会使其与 VLAN 接口区分开来。此外,文件命名的词汇顺序也很重要。如果匹配满足特定条件,则匹配相同条件的后续文件将被忽略。