systemd.网络管理

systemd.网络管理

我尝试遵循以下手动示例man systemd.network

# /etc/systemd/network/27-xfrm.netdev
[NetDev]
Name=xfrm0
Kind=xfrm

[Xfrm]
InterfaceId=7
# /etc/systemd/network/27-eth0.network
[Match]
Name=ens5

[Network]
Xfrm=xfrm0

然后systemctl daemon-reload+ systemctl restart systemd-networkd。没事了。其中systemctl status systemd-networkd也没有显示任何对以下内容的引用xfrm

Apr 16 23:52:07 ip-10-100-1-205 systemd[1]: Starting Network Configuration...
Apr 16 23:52:07 ip-10-100-1-205 systemd-networkd[960]: ens5: Link UP
Apr 16 23:52:07 ip-10-100-1-205 systemd-networkd[960]: ens5: Gained carrier
Apr 16 23:52:07 ip-10-100-1-205 systemd-networkd[960]: lo: Link UP
Apr 16 23:52:07 ip-10-100-1-205 systemd-networkd[960]: lo: Gained carrier
Apr 16 23:52:07 ip-10-100-1-205 systemd-networkd[960]: ens5: Gained IPv6LL
Apr 16 23:52:07 ip-10-100-1-205 systemd-networkd[960]: Enumeration completed
Apr 16 23:52:07 ip-10-100-1-205 systemd[1]: Started Network Configuration.
Apr 16 23:52:07 ip-10-100-1-205 systemd-networkd[960]: ens5: DHCPv4 address 10.100.1.205/24 via 10.100.1.1

它是 aws 上的 ubuntu 22.04,带有 systemd v249。

我还尝试添加另一个.network模块:

[Match]
Name=xfrm*

[Link]
ActivationPolicy=up
RequiredForOnline=no

没有成功。

我缺少什么?

UPD:

# ip a
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
    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: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
    link/ether 06:ea:6f:cf:a8:51 brd ff:ff:ff:ff:ff:ff
    inet 10.100.1.205/24 metric 100 brd 10.100.1.255 scope global dynamic ens5
       valid_lft 2529sec preferred_lft 2529sec
    inet6 fe80::4ea:6fff:fecf:a851/64 scope link 
       valid_lft forever preferred_lft forever

(我手动添加了xfrm接口,因此ens5MTU已降至1500,否则它是同一台机器)

# networkctl status ens5
● 2: ens5                                                                      
                     Link File: /usr/lib/systemd/network/99-default.link
                  Network File: /run/systemd/network/10-netplan-ens5.network
                          Type: ether
                         State: routable (configured)
                  Online state: online                                         
             Alternative Names: enp0s5
                          Path: pci-0000:00:05.0
                        Driver: ena
                        Vendor: Amazon.com, Inc.
                         Model: Elastic Network Adapter (ENA)
                    HW Address: 06:ea:6f:cf:a8:51
                           MTU: 1500 (min: 128, max: 9216)
                         QDisc: mq
  IPv6 Address Generation Mode: eui64
          Queue Length (Tx/Rx): 2/2
                       Address: 10.100.1.100
                                10.100.1.205
                                fe80::4ea:6fff:fecf:a851
                       Gateway: 10.100.1.1
             Activation Policy: up
           Required For Online: yes
             DHCP6 Client DUID: DUID-EN/Vendor:0000ab11874fdc08796f22200000

Apr 17 02:55:13 ip-10-100-1-205 systemd-networkd[322]: ens5: Link UP
Apr 17 02:55:13 ip-10-100-1-205 systemd-networkd[322]: ens5: Gained carrier
Apr 17 02:55:13 ip-10-100-1-205 systemd-networkd[322]: ens5: Link DOWN
Apr 17 02:55:13 ip-10-100-1-205 systemd-networkd[322]: ens5: Lost carrier
Apr 17 02:55:13 ip-10-100-1-205 systemd-networkd[322]: ens5: Link UP
Apr 17 02:55:14 ip-10-100-1-205 systemd-networkd[322]: ens5: Gained carrier
Apr 17 02:55:15 ip-10-100-1-205 systemd-networkd[322]: ens5: Gained IPv6LL

答案1

每个网络接口仅由第一的与接口匹配的.network 文件。您的 ens5 已经与 匹配10-netplan-ens5.network,因此27-eth0.network将被忽略。

如果您的 systemd 版本足够现代,您可以通过 .netplan 提供的文件添加自定义设置/etc/systemd/network/10-netplan-ens5.network.d/*.conf

如果您不需要硬件 IPsec 卸载,将 netdev 设置为独立可能就足够了,这样就可以在不从 .network 文件 ( Independent=yes) 调用的情况下创建它。

答案2

我觉得更新别人的答案是不对的,因此发布一个只是为了使最终的解决方案更加明显:

创造/etc/systemd/network/10-netplan-ens5.network.d/xfrm0.conf

[Network]
Xfrm=xfrm0

这将创建一个xfrm0基于物理的虚拟接口ens5

创造/etc/systemd/network/27-xfrm.network

[Match]
Name=xfrm*

[Link]
ActivationPolicy=up
RequiredForOnline=no

这使得所有xfrm*接口都UP处于启动状态。

相关内容