20

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.

3 Answers 3

22

Starting from systemd version 244, you can renew DHCP lease in systemd-networkd with the following command:

networkctl renew DEVICES...

Ubuntu 20.04 shipped with systemd 245.4 and is the first version of Ubuntu where this command is available.

2
  • Nice find! I'm trying to find out which version of Ubuntu that systemd 244 is first included in, so we can add that to your answer. Unfortunately, the release notes don't seem to specify...
    – villapx
    Commented May 26, 2021 at 19:48
  • You can find this information well and conveniently formatted here. Ubuntu 20.04 is the oldest release with systemd >244.
    – jzyken
    Commented May 27, 2021 at 20:21
6

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:

> Is there a way to force a DHCPv4 release/renew with systemd-networkd?

We don't currently allow dynamic interaction with networkd, but you can force renew the release by either restarting networkd or unplugging/replugging the cable (or switching your wifi off/on if that's what you are using).

-t

So apparently if you do one of these two things, systemd-networkd will renew your DHCP lease.

2
  • 2
    Did it work for you? This seems right, but systemctl restart systemd-networkd didn't help, only dhclient -v -r eth0; dhclient -v eth0 (testing with dhcpdump -i eth0 on other terminal). Commented Sep 23, 2019 at 6:26
  • 1
    @PabloA If you're using systemd-networkd, then you don't want to use dhclient...it will interfere with systemd-networkd. Or, perhaps more accurately, systemd-networkd will probably interfere with your use of dhclient at some point. I'm not 100% sure that it worked, as I didn't really look that closely in my router's webpage after running the command, but I assume it did since I see that in multiple other answers on this site that that's the correct way to do it for systemd-networkd.
    – villapx
    Commented Sep 23, 2019 at 20:28
0

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 otherwise systemd-network sends a DHCPRELEASE on shutdown and, most critically, also forgets the lease it had before. So rebooting two systemd-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 to systemd-networkd, and then start the service (not restart) it will use the leases that are in /var/run/systemd/netif as you would expect.

1
  • 1
    What do you mean when you write we use Critical? I would like not to send DHCPRELEASE as well when restarting systemd-networkd
    – WoJ
    Commented Aug 19, 2022 at 9:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .