Home / Alt manpages / netplan-ip(8)

  • netplan-ip(8)
  • Admin command
  • linux

Inspect DHCP leases safely with netplan ip

You will use netplan ip leases to ask Netplan for the DHCP lease information associated with one network interface. The command is a read-only inspection: it does not renew a lease, apply YAML, restart networking or alter the interface. Allow about five minutes. You need the netplan.io package and the interface name you want to inspect.

This guide describes netplan.io version 1.1.2-8ubuntu1~24.04.3, installed on the reference system. The installed command is netplan at /usr/sbin/netplan. Later releases may add commands or change diagnostic wording, so treat the exit status and the documented purpose as the stable parts.

1. Identify the interface

First list the link names visible on the machine. Use the name after netplan ip leases, not a descriptive label such as "wired network".

$ ip -brief link
lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
enp0s31f6         UP             90:1b:0e:da:cc:ef <BROADCAST,MULTICAST,UP,LOWER_UP>

Interface names vary. Common examples include 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 the configuration.

Checkpoint

Save the interface name, for example enp0s31f6, before moving to the next step.

2. Ask Netplan for the lease

Run the command with the interface name as its final argument:

$ sudo netplan ip leases enp0s31f6

sudo is shown because Netplan may need to read root-owned YAML under /etc/netplan and the runtime lease data. If the command works without elevated privileges on your host, leave sudo out. The command does not need root because it changes the network; it needs access to the files used for inspection.

When a DHCP lease is available, Netplan prints the lease information it found for that interface. The exact fields and formatting depend on the backend and the lease data present on the machine. Check the exit status immediately afterwards:

$ printf '%s\n' "$?"
0

Do not place another command between netplan ip leases and the status check. A zero status means the query completed successfully. It does not mean that the interface has a DHCP lease if the output itself is empty or says that no lease was found.

3. Read a missing-lease result correctly

A configured interface does not necessarily have a DHCP lease. For example, a statically addressed interface may be managed by Netplan but have no DHCP lease file. The installed command reports this as a diagnostic similar to:

No lease found for interface 'enp0s31f6': [Errno 2] No such file or directory: '/run/systemd/netif/leases/2'

That result is not a request to run netplan apply. First inspect the configuration and the current addresses without changing anything:

$ sudo netplan get ethernets.enp0s31f6
$ ip address show dev enp0s31f6

Look for a DHCP setting such as dhcp4: true or dhcp6: true. A configuration containing only fixed addresses is expected not to produce a DHCP lease. Also check that you queried the interface actually managed by Netplan, rather than a bridge, container link or loopback device.

Checkpoint

Classify the result as a lease returned, no lease because DHCP is not in use, or an access or configuration error. Do not treat all non-zero results as proof that networking is broken.

4. Use debug output when the result is unclear

Add the global --debug option before ip when you need to see the helper Netplan 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)

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. It remains an inspection command, but it can reveal more host information than the normal invocation.

If an unprivileged run reports Permission denied while opening a file under /etc/netplan, rerun the same read-only query with sudo. Do not edit the YAML or apply a guessed configuration merely to make the diagnostic disappear.

5. Use a different configuration root only for offline data

The --root-dir option tells Netplan to search for configuration files below another root instead of /:

$ sudo netplan ip leases --root-dir=/path/to/root enp0s31f6

This is useful when inspecting an installed system from recovery media or a mounted filesystem. The path must be a real root containing the expected Netplan layout. It is not an option for selecting a different live network interface, and it does not create a lease in that root.

Do not point --root-dir at an arbitrary directory and infer that a missing lease is 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.

6. Avoid the common traps

  • Wrong interface: use ip -brief link and copy the exact name. lo, Docker links and bridge members usually are not the DHCP client interface you want.
  • Static configuration: an address shown by ip address can be statically configured and therefore unrelated to a DHCP lease.
  • Unnecessary service disruption: netplan ip leases does not apply configuration. Do not add netplan apply to a troubleshooting command; applying a changed network configuration can disconnect the host.
  • Stale assumptions: lease files are runtime state. A lease can expire, disappear 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, retain the diagnostic, and test the exact Netplan version used by the script.

Done means

  • You identified the real interface name with ip -brief link.
  • You ran netplan ip leases INTERFACE and captured its output and immediate exit status.
  • You distinguished a DHCP lease from a static address and from a missing or inaccessible runtime lease.
  • You used sudo only when file permissions required it.
  • You did not run netplan apply, restart networking or modify configuration while inspecting the lease.