I have my eth0
interface configured for DHCPv4 via netplan
:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
dhcp6: true
optional: true
How do I tell systemd-networkd
to renew my DHCP lease? I know with dhclient
it's as simple as dhclient -r eth0 && dhclient eth0
, as explained in many other answers on this site, but how do I do it for systemd-networkd
?
I'm in Ubuntu 18.04 Server.
Starting from systemd version 244, you can renew DHCP lease in systemd-networkd with the following command:
Ubuntu 20.04 shipped with systemd 245.4 and is the first version of Ubuntu where this command is available.
I found a freedesktop.org mailing list post from Tom Gundersen in August 2014 that answers my question, at least as of the time it was written:
So apparently if you do one of these two things,
systemd-networkd
will renew your DHCP lease.I have found that if you do a restart on
systemd-networkd
, it ignores the previous lease and just starts over with a clean request.If you're also using a
dhcpd
that does a ping check you end up with a second. That might be an interaction with how I've set up the network config. We use Critical because otherwisesystemd-network
sends aDHCPRELEASE
on shutdown and, most critically, also forgets the lease it had before. So rebooting twosystemd-networkd
servers at the same time has a very high chance of both of them losing their IP addresses.I'm unsure what the conditions that cause this to happen are, however, I've found that if you send a
-HUP
tosystemd-networkd
, and then start the service (not restart) it will use the leases that are in/var/run/systemd/netif
as you would expect.