Check DHCP Leases with netplan ip
netplan ip leases asks Netplan what it knows about a DHCP lease on one interface, without renewing, applying YAML or restarting anything. Allow about five minutes and have your interface name ready.
The route
Jump straight to the step you need, or tick off Done means at the end.
This guide describes netplan.io version 1.1.2-8ubuntu1~24.04.3. The installed command is netplan at /usr/sbin/netplan. Later releases may add commands or change wording, so treat the exit status and the documented purpose as the stable parts.
1. Identify the interface
List the link names on the machine first. You need the exact name, not a description like "wired network":
$ ip -brief link
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
enp0s31f6 UP 02:00:00:00:00:01 <BROADCAST,MULTICAST,UP,LOWER_UP>
Interface names vary. Common examples are enp0s31f6, enp5s0 and wlp2s0. Copy the exact name from your own output: a name that does not exist is not converted into an address or guessed from configuration.
Checkpoint
Save the interface name, for example enp0s31f6, before moving on.
2. Ask Netplan for the lease
Run the command with the interface name as the final argument:
$ sudo netplan ip leases enp0s31f6
- Why sudo shows up here. Netplan may need to read root-owned YAML under
/etc/netplanplus the runtime lease data. If your host lets you run it unprivileged, leavesudoout. - Why root is not really required. The command inspects files, it does not change the network, so it needs read access rather than write power.
When a lease exists, Netplan prints what it found for that interface; exact fields depend on the backend and the lease data present. Check the exit status right after:
$ printf '%s\n' "$?"
0
Do not run anything else between the lease command and the status check. A zero status means the query completed, not that the interface actually has a lease if the output itself is empty or says none was found.
3. Read a missing-lease result correctly
A configured interface will not necessarily have a DHCP lease. A statically addressed interface can be perfectly managed by Netplan and still have no lease file. Expect a diagnostic like this:
No lease found for interface 'enp0s31f6': [Errno 2] No such file or directory: '/run/systemd/netif/leases/2'
That is not a cue to run netplan apply. Check the configuration and current addresses first, without changing anything:
$ sudo netplan get ethernets.enp0s31f6
$ ip address show dev enp0s31f6
- Look for a DHCP setting such as
dhcp4: trueordhcp6: true. A configuration with only fixedaddressesis expected not to produce a DHCP lease. - Check you queried the right interface. A bridge, container link or loopback device is not the interface Netplan actually manages.
Checkpoint
Classify the result as a lease returned, no lease because DHCP is not in use, or an access or configuration error. A non-zero result is not automatic proof that networking is broken.
4. Use debug output when the result is unclear
Add the global --debug option before ip to see the helper Netplan actually invokes:
$ sudo netplan --debug ip leases enp0s31f6
DEBUG:command ip leases: running ['/usr/libexec/netplan/generate', '--mapping', 'enp0s31f6']
No lease found for interface 'enp0s31f6' (not managed by Netplan)
Warning
Debug output can expose configuration paths and backend details. Keep it out of public support tickets if your file names or network design are sensitive.
If an unprivileged run reports Permission denied opening a file under /etc/netplan, rerun the same read-only query with sudo. Do not edit YAML or apply a guessed configuration just to make the message go away.
5. Use a different configuration root only for offline data
--root-dir tells Netplan to search for configuration below another root instead of /:
$ sudo netplan ip leases --root-dir=/path/to/root enp0s31f6
Handy for inspecting an installed system from recovery media or a mounted filesystem, as long as the path is a real root with the expected Netplan layout. It is not a way to pick a different live network interface, and it will not create a lease inside that root.
Do not point --root-dir at an arbitrary directory and then treat a missing lease as a live-network failure. Check the configuration files in the alternate root first, and keep the option out of ordinary commands unless you are deliberately inspecting offline data.
Common traps
- Wrong interface. Use
ip -brief linkand copy the exact name.lo, Docker links and bridge members are usually not the DHCP client interface you want. - Static configuration. An address shown by
ip addresscan be static and therefore unrelated to any DHCP lease. - Unnecessary disruption.
netplan ip leasesdoes not apply configuration. Do not boltnetplan applyonto a troubleshooting command; applying a changed network configuration can disconnect the host. - Stale assumptions. Lease files are runtime state: a lease can expire, vanish after a reboot, or be held by a different network manager. Repeat the query after confirming which renderer manages the interface.
- Output parsing. Do not write a script that assumes one fixed set of fields. Use the exit status, keep the diagnostic, and test against the exact Netplan version the script targets.
Done means
- Identified the real interface name with
ip -brief link. - Ran netplan ip leases INTERFACE and captured its output and immediate exit status.
- Told apart a lease, a static address, and a missing or inaccessible lease.
- Used sudo only when file permissions required it.
- Made no changes. No
netplan apply, no restart, no configuration edits while inspecting.