systemd.network management

I try to follow the manual example from 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

Then systemctl daemon-reload + systemctl restart systemd-networkd. And – nothing. In systemctl status systemd-networkd it also does not show any references to 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

It’s ubuntu 22.04 on aws with systemd v249.

I also tried to add another .network module with:

[Match]
Name=xfrm*

[Link]
ActivationPolicy=up
RequiredForOnline=no

with no success.

What am I missing?

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

(I manually added xfrm interface hence ens5 MTU has dropped to 1500, otherwise it’s the same machine)

# 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
Asked By: zerkms

||

Each network interface is configured only by the first .network file that matches the interface. Your ens5 is already matched by 10-netplan-ens5.network, therefore 27-eth0.network will be ignored.

If your systemd version is modern enough, you can add custom settings to the Netplan-provided file via /etc/systemd/network/10-netplan-ens5.network.d/*.conf.

If you don’t require hardware IPsec offload, it might be enough to set the netdev as independent so that it would be created without being called from a .network file (Independent=yes).

Answered By: u1686_grawity

I don’t feel right to update someonelse’s answer, hence posting one just to make the final solution more visible:

Create /etc/systemd/network/10-netplan-ens5.network.d/xfrm0.conf:

[Network]
Xfrm=xfrm0

This creates a virtual xfrm0 interface based on physical ens5.

Create /etc/systemd/network/27-xfrm.network

[Match]
Name=xfrm*

[Link]
ActivationPolicy=up
RequiredForOnline=no

This makes all xfrm* interfaces UP on boot.

Answered By: zerkms
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.