Skip to main content
SysAdmin Shell Scripting Essentials

DHCP Leases in Linux: Management, Commands & Troubleshooting

dhcp leases are temporary IP address assignments from a DHCP server to clients, recorded in lease files. Managed via systemd-networkd, dhclient, or ISC DHCP on Linux.

# View server lease database (systemd-networkd acting as server)
cat /var/lib/systemd/lease/*.lease

Overview

DHCP leases track which IP address, subnet mask, gateway, and lease duration have been assigned to each client. Leases expire unless renewed. Administrators inspect leases to resolve IP conflicts, audit active clients, or verify static reservations. On Linux, the storage location and query tools differ by DHCP implementation.

dhcp leases Syntax Reference

DHCP lease management does not have a single dhcp leases binary. Inspect and manipulate leases using these commands across different implementations.

# systemd-networkd – view active client leases
cat /run/systemd/netif/leases/*

# systemd-networkd – view server lease database (acting as DHCP server)
cat /var/lib/systemd/lease/*.lease

# dhclient – view client leases (ISC DHCP client)
cat /var/lib/dhcp/dhclient.leases

# ISC DHCP server – query active leases
sudo dhcp-lease-list
less /var/lib/dhcp/dhcpd.leases

# Force release/renew with dhclient
sudo dhclient -r eth0
sudo dhclient eth0

# systemd-networkd – restart to reload leases
sudo systemctl restart systemd-networkd

# Logs for DHCP events
journalctl -u systemd-networkd --no-pager | grep -i lease

dhcp leases Rapid Reference Cheat Sheet

Action systemd-networkd dhclient / ISC DHCP client ISC DHCP server
View client lease file cat /run/systemd/netif/leases/* cat /var/lib/dhcp/dhclient.leases N/A
View server lease database cat /var/lib/systemd/lease/*.lease N/A less /var/lib/dhcp/dhcpd.leases
Renew lease sudo systemctl restart systemd-networkd or sudo networkctl renew <iface> sudo dhclient -v <iface> N/A (server)
Release lease sudo networkctl down <iface>; sudo networkctl up <iface> sudo dhclient -r <iface> N/A
Add static lease (server) [DHCPServerStaticLease] in .network file N/A host foo { hardware ethernet ...; fixed-address ...; } in dhcpd.conf
Query DHCP server status systemctl status systemd-networkd N/A dhcpd -t -cf /etc/dhcp/dhcpd.conf

Advanced Implementation & Parameters

systemd-networkd DHCP Server Lease Storage

When systemd-networkd acts as a DHCP server (configured via DHCPServer=yes in a .network file), leases are written to /var/lib/systemd/lease/. Each lease file is named by the client identifier (usually the MAC address) and contains JSON with assigned IP, lease time, and options.

# Inspect a server lease
cat /var/lib/systemd/lease/be:5e:56:66:75:16.lease
{
  "address": "192.168.223.225",
  "lease_time": 86400,
  "client_id": "01:be:5e:56:66:75:16",
  "gateway": "192.168.223.1",
  "subnet_mask": "255.255.255.240",
  "server_id": "192.168.223.1"
}

Static Leases in systemd-networkd

Static leases are defined in the [DHCPServerStaticLease] section of a .network file. The server must be configured with DHCPServer=yes and a pool address range (e.g., Pool=). The MAC address must match the client’s actual MAC.

[Match]
Name=ve-perft3

[Network]
DHCPServer=yes
Address=0.0.0.0/28

[DHCPServerStaticLease]
MACAddress=be:5e:56:66:75:16
Address=192.168.223.225

Frequently Asked Questions

What is the difference between `dhclient -r` and `dhclient -x`?

Answer: `-r` releases the current lease without stopping the client; `-x` stops the client and releases the lease.

See also  Export-CSV PowerShell: Syntax, Flags, Exit Codes, Troubleshooting

`dhclient -r` sends a DHCPRELEASE packet for the current lease, then exits, leaving the interface unconfigured. `dhclient -x` instructs the running daemon to release the lease and terminate itself. Use `-r` for one-shot release during scripts; use `-x` to cleanly stop a persistent dhclient process.

# Release current lease without stopping dhclient
sudo dhclient -r eth0
# Stop dhclient daemon and release lease
sudo dhclient -x eth0

When should I use the `dhcp-lease-list` command from the `isc-dhcp-server` package?

Answer: Use `dhcp-lease-list` to quickly inspect active DHCP leases from the server’s lease database without parsing the raw file.

This command reads `/var/lib/dhcp/dhcpd.leases` and presents a formatted table of IP, MAC, start/end times, and hostname. It is ideal for rapid audits or scripting checks for lease exhaustion. For real-time monitoring, combine with `watch`.

# Display all active leases
sudo dhcp-lease-list
# Continuous refresh every 5 seconds
watch -n 5 sudo dhcp-lease-list

How do I fix the error `dhcpd: No subnet declaration for eth0` when starting ISC DHCP server?

Answer: Add a subnet declaration for the interface’s network in `/etc/dhcp/dhcpd.conf`.

The server requires explicit subnet blocks even if no dynamic IP ranges are defined. Use `ip addr show eth0` to get the network details, then append a subnet statement. For a simple static-only config, an empty declaration suffices.

# Example: eth0 IP 192.168.1.10/24
subnet 192.168.1.0 netmask 255.255.255.0 {
}
# Then restart dhcpd
sudo systemctl restart isc-dhcp-server

Does the `show ip dhcp binding` command work on AWS VPC DHCP option sets?

Answer: No.

AWS VPC DHCP automatically assigns IPs from the subnet range via EC2-VPC platform. To list DHCP leases in AWS, use the AWS CLI: `aws ec2 describe-network-interfaces`. For on-premises Cisco devices, the command shows active bindings from the DHCP pool.

# AWS: list all private IPs assigned via DHCP
aws ec2 describe-network-interfaces --query 'NetworkInterfaces[*].PrivateIpAddress'
# On Cisco IOS:
show ip dhcp binding

What is the fastest way to export all active DHCP leases from an ISC DHCP server to CSV using command-line tools?

Answer: Parse the lease file with `grep` and `awk`, then pipe to `csvformat` or redirect with comma separators.

See also  PowerShell Install Module Active Directory via RSAT Guide

The lease file `/var/lib/dhcp/dhcpd.leases` is line‑based. Extract active leases (those without `ends never` or past `ends …`). Use `csvkit` for robust CSV output. This method runs in <100ms on a 10K lease file.

# Fast pipeline for active leases to CSV
sudo awk '/lease/{ip=$2} /starts/{s=$2 $3} /ends/{e=$2 $3; if(e >= systime()) print ip", "s", "e}' /var/lib/dhcp/dhcpd.leases > active_leases.csv
# Alternative with csvformat
sudo grep -B2 -A2 'binding state active' /var/lib/dhcp/dhcpd.leases | awk ... | csvformat -d ' '