Why DHCP client fails to get IP with no free leases error?
Recently I was trying to perform an automated installation which requires a DHCP server to provide the IP Address to the client, I started getting this error message on my DHCP server:
Jan 12 09:18:33 ubuntu dhcpd[57461]: DHCPDISCOVER from 00:17:a4:77:00:32 via eno49: network 10.43.138.0/27: no free leases
Jan 12 09:18:53 ubuntu dhcpd[57461]: DHCPDISCOVER from 00:17:a4:77:00:32 via eno49: network 10.43.138.0/27: no free leases
Jan 12 09:18:55 ubuntu dhcpd[57461]: DHCPDISCOVER from 00:17:a4:77:00:32 via eno49: network 10.43.138.0/27: no free leases
Jan 12 09:18:59 ubuntu dhcpd[57461]: DHCPDISCOVER from 00:17:a4:77:00:32 via eno49: network 10.43.138.0/27: no free leases
This basically means that your DHCP server was unable to provide any IP Address to the client.
How DHCP Works?
If you are not familiar with the DHCP flow request, then it would look like something below (sequential steps from top to down)
- DHCP Client send IP Address request via DHCPDISCOVER. Now this is basically a broadcast message to all the available servers in the private network
- DHCP Server then offers the IP Address via DHCPOFFER. This contains the protocol information such as lease duration, client ID etc
- Now this DHCPOFFER message is also received by all the hosts in the private network, but the host that sent the DHCPDISCOVER message will only accept the DHCPOFFER message, and all others would ignore it. This is done via the MAC address from DHCPDISCOVER offer which was sent in the very first step. Once client accepts DHCPOFFER, it sends DHCPREQUEST message to confirm that it wants to use the offered IP Address
- When the DHCP server receives a DHCPREQUEST message from the client, the server sends DHCPACK message as an acknowledgement to confirm that it has received DHCPREQUEST message and the client can use the offered IP Address
So when we get this error, we are basically stuck at Stage 1 i.e. DHCPDISCOVER stage wherein client is broadcasting a request to get IP Address but for some reason the DHCP Server is unable to perform DHCPOFFER.
Different possible causes and fix for "no free leases" error
Cause-1: range directive not defined in DHCP Server
In a DHCO server configuration file, we either specify range of IP Addresses which can be used by the client or we provide the host identifier such as MAC or hostname to identify any host and then provide a static IP Address.
It is possible that the client which is trying to request the IP Address is not added in your dhcpd.conf
file using host
directive. So it is always recommended to have a range directive in place unless you don't want any additional client to use your DHCP server.
So, to summarise, you can either add a range
directive as shown below for IPv4:
subnet 10.10.10.0 netmask 255.255.255.0 {
option routers 10.10.10.1;
option domain-name-servers 127.0.0.1;
range 10.10.10.100 10.10.10.140;
next-server 10.10.10.12;
filename "pxelinux/pxelinux.0";
}
Or add range6
directive for IPv6 as shown below:
subnet6 2001:0001:0001:1442::0400/122
{
range6 2001:0001:0001:1442::0405 2001:0001:0001:1442::0420;
option dhcp6.bootfile-url "tftp://[2001:0001:0001:1442::0407]/pxelinux/BOOTX64.EFI";
}
The other parameters added in my sample dhcpd.conf
/dhcpd6.conf
are optional and can be ignored.
Alternatively, if you can't find the client's MAC address as shown in your log file i.e. 00:17:a4:77:00:32
must be added with a proper IP Address:
DHCPDISCOVER from 00:17:a4:77:00:32 via eno49: network 10.43.138.0/27: no free leases
For Example:
host server-1 {
hardware ethernet 00:17:a4:77:00:32;
fixed-address 10.43.138.2;
}
Post the modification, you can restart the dhcpd service to activate the changes.
For IPv4 on RHEL/CentOS/Rocky Linux/AlmaLinux
systemctl restart dhcpd.service
For IPv6 on RHEL/CentOS/Rocky Linux/AlmaLinux
systemctl restart dhcpd6.service
On Ubuntu/Debian
systemctl restart isc-dhcp-server.service
Cause-2: The DHCP server has run out of free leases
As the error states, it is possible that your DHCP server has actually no free IP available to give to it's clients. In such case also we will get the same error i.e.:
DHCPDISCOVER from 00:17:a4:77:00:32 via eno49: network 10.43.138.0/27: no free leases
So, to fix this you should check your lease file entry. The path for lease file can vary for IPv4 and IPv6 or if you are using some custom location. By default the lease file for IPv4 is available at /var/lib/dhcp/dhcpd.leases
and for IPv6 you can check /var/lib/dhcpd/dhcpd6.leases
file.
Sample entry from /var/lib/dhcpd/dhcpd6.leases
:
ia-na "\016\267\246\377\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" { cltt 0 2022/01/02 10:40:50; iaaddr 2001:1:1:1442::41a { binding state released; preferred-life 604800; max-life 2592000; ends 2 2022/02/01 10:40:48; } }
Sample entry from /var/lib/dhcp/dhcpd.leases
:
lease 10.43.138.26 { starts 3 2022/01/12 03:52:59; ends 3 2022/01/12 04:07:59; cltt 3 2022/01/12 03:52:59; binding state active; next binding state free; rewind binding state free; hardware ethernet 00:17:a4:77:00:32; set vendor-class-identifier = "PXEClient:Arch:00000:UNDI:002001"; }
So, you can go through this list and remove any client entry which you feel is not required. But this must be done carefully to avoid any impact in your network.
Or alternatively you can plan to increase the range or add new range in your DHCP server to server more number of clients which we discussed in the previous section.
Post the modification, you can restart the dhcpd service
For IPv4 on RHEL/CentOS/Rocky Linux/AlmaLinux
systemctl restart dhcpd.service
For IPv6 on RHEL/CentOS/Rocky Linux/AlmaLinux
systemctl restart dhcpd6.service
On Ubuntu/Debian
systemctl restart isc-dhcp-server.service
This should solve your problem.
Summary
To summarise, the error "no free leases" in dhcpd server is quiet common and can be seen in production environment with large number of hosts so you can explore both the options which I shared to fix this error. It also happens some times that you may have deleted lasrge number of VMs which were acting as dhcp client but they still are occupying the lease so you can always delete the entries for those VMs form the lease file so that those free IPs can be assigned to other hosts.
Further Reading
Configure DHCPv6 Server in Linux
Configure DHCP Server in Linux
References
dhcp server gives "no free leases" error although there should be available IPs