You are not logged in.

#1 2021-12-05 22:14:33

ectospasm
Member
Registered: 2015-08-28
Posts: 302

[SOLVED] systemd-networkd and achieving persistent WAN DHCP IP address

I figured this out as I was trying things writing this post.  The key that fixed it was using dhcp-requested-address, which is DHCPv4 option number 50 (see http://www.ipamworldwide.com/ipam/isc-d … tions.html).  I added my current IP address to this option, and I got the same IP address when I rebooted.  I suppose dhclient on Debian was doing the same automatically, but there is no mention of where it stores this in the configuration file I posted below.  Here is my current /etc/systemd/network/20-WAN.network:

[Match]
Name=enp3s0

[Network]
DHCP=yes

[DHCPv4]
ClientIdentifier=duid
IAID=1987201769
SendOption=50:ipv4address:<redacted>

Setting <redacted> to my actual IP address (without netmask) was enough to get it working.

Here's my original post, for posterity:

I converted my Intel NUC router with dual Gigabit Ethernet ports from running Debian to Arch in early October.  Since then, I've noticed my public IP address on the WAN interface changes with each reboot.  This was not the case with Debian, I was able to get the same IP address most of the time when it rebooted.

When installing Arch I decided to go with systemd-networkd as my network manager, and for the most part it has worked just fine.  Only, I notice I definitely get a new IP address with each reboot, which wasn't the case with Debian (same ISP, same fiber modem, same hardware/MAC address of the WAN interface).  Here's my /etc/systemd/network/20-WAN.network file:

[Match]
Name=enp3s0

[Network]
DHCP=yes

[DHCPv4]
ClientIdentifier=mac

In troubleshooting this earlier in November, I added the ClientIdentifier=mac parameter with no luck.  I also just ensured my machine-id doesn't change, by setting it up in the kernel command line.  I've set the following parameters with no luck, either:

[DHCPv4]
ClientIdentifier=duid
IAID=1987201769

Rebooting twice, and my WAN IP address changes with every reboot.  I was hoping with ClientIdentifier=duid (DUIDType defaults to "vendor", which should use the machine-id), this would have worked.  But it didn't, every reboot gives me a new IP address. 

Here is my dhclient.conf from Debian:

# Configuration file for /sbin/dhclient, which is included in Debian's
#	dhcp3-client package.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
#	man page for more information about the syntax of this file
#	and a more comprehensive list of the parameters understood by
#	dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
#	not leave anything out (like the domain name, for example), then
#	few changes must be made to this file, if any.
#

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

#send host-name "andare.fugue.com";
#send host-name = gethostname();
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
supersede domain-name-servers 10.20.30.254, 1.1.1.1, 9.9.9.9, 8.8.8.8, 8.8.4.4;
supersede domain-search "ceti";
#prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers, host-name, dhcp6.name-servers, dhcp6.domain-search, netbios-name-servers, netbios-scope, interface-mtu, rfc3442-classless-static-routes, ntp-servers;
#require subnet-mask, domain-name-servers;
#timeout 60;
#retry 60;
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/etc/dhcp3/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;

#alias {
#  interface "eth0";
#  fixed-address 192.5.5.213;
#  option subnet-mask 255.255.255.255;
#}

#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andare.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}

A lot of that configuration is Debian cruft and commented documentation.  Am I missing something simple?  I don't want to reach out to my ISP to get a static IP address (or static DHCP lease), I assume that would add extra cost I don't want to incur right now.  This was working as expected in Debian, and my WAN IP address rarely changed. I do have ddclient set up, and that is working as far as I can tell.  It just takes a few minutes for the DNS updates to occur with that, if I got the same WAN IP address I wouldn't have to wait for the DNS updates to percolate across the Internet.

Offline

#2 2021-12-06 05:10:41

progandy
Member
Registered: 2012-05-17
Posts: 5,304

Re: [SOLVED] systemd-networkd and achieving persistent WAN DHCP IP address

systemd-networkd does not persist leases over a reboot. ClientIdentifier gives a unique identifier to your ISP and the ISP then chooses the IP you get. You can also send a preferred IP to the dhcp server, which you figured out.

dhclient does persist leases. Depending on the service files dhclient it may or may not release them after a reboot I think and then it tries to renew the lease if it is expired or so.

Last edited by progandy (2021-12-06 05:14:33)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#3 2021-12-06 10:56:27

rsmarples
Member
Registered: 2009-05-12
Posts: 288

Re: [SOLVED] systemd-networkd and achieving persistent WAN DHCP IP address

dhcpcd also persists leases and requests it if it's still valid.

Offline

#4 2021-12-06 22:59:44

ectospasm
Member
Registered: 2015-08-28
Posts: 302

Re: [SOLVED] systemd-networkd and achieving persistent WAN DHCP IP address

OK, thanks for the tips.  I think I'll stick with sending option 50 with my desired IP address.  The last one my ISP gave me is aesthetically pleasing to me, so I'll stick to requesting that.  I'm sure if they decide to give me something else, they'll NAK my option 50 and I'll see my IP address change.  Not sure if I will notice right away when that happens.  At least ddclient will always update my personal domain with the correct address.

I'm trying to avoid having too much unnecessary software installed on my router.  I already have the ISC dhcpd service installed, if it becomes a major problem I may switch to using that.

Offline

Board footer

Powered by FluxBB