Re: How can I prevent systemd.network from auto-deleting my manually-assigned static IPv4 addresses?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I believe you want KeepConfiguration="static".

On Wed, Sep 13, 2023, at 18:32, Jeremy Friesner wrote:
Hi all,

I apologize for this basic question, but I haven’t been able to figure it out on my own.

I’m working on an embedded device, which includes a little GUI that (among other things) allows the user to specify a static IPv4 address (and netmask and gateway) to be associated with a given Ethernet port on the device.

The user enters the IPv4 settings-values he wants into the GUI, clicks “Apply”, and the server runs a couple of simple shell commands:

/sbin/ip -4 a add 192.168.2.88/24 dev eno1 label eno1:p0s0
/bin/arping -c 3 -A -I eno1 192.168.2.88

… et voila, Ethernet device eno1 now uses the IP address 192.168.2.88 (associated with the label eno1:p0s0), as shown in ifconfig:

root@embedded-device:~# ifconfig
[…]

eno1:p0s0 Link encap:Ethernet HWaddr 00:07:32:95:93:7D 
inet addr:192.168.2.88 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
Memory:a5b00000-a5b1ffff

If the user later changes his mind and wants to clear his IPv4 settings, he can do that and the server will run this shell command:

/sbin/ip -4 addr flush label eno1:p0s0

This all works fine and has for a long time; the problem is that the new version of the device is running systemd.networkd and networkd has some functionality in it where it detects when an Ethernet device has lost its carrier, and responds by removing all the IPv4 addresses associated with that Ethernet device.

The user-visible result of that behavior is that if the user unplugs his Ethernet cable and then plugs it in again, his IPv4 settings are no longer in effect (at least not until he goes and re-enters them into the GUI again to re-establish them).

The behavior I would like is that this manually-assigned IPv4 address is left alone by systemd, and doesn’t change unless/until the user explicitly updates it using the GUI.  Is there some way to convince networkd to leave my server’s IPv4 settings alone?

I tried various permutations of config files, like the one shown below, but they didn’t seem to have any effect on networkd's behavior.

root@embedded-device:~# cat /etc/systemd/network/eno1.network 
[Match]
Name=eno1

[Network]
DHCP=no
IgnoreCarrierLoss=yes

[Link]
ActivationPolicy=always-up

Thanks,
Jeremy
NOTICE: This email may contain confidential information. Please see https://meyersound.com/legal/#email-policy for our complete policy.

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux