Clear DHCP Server Leases - Any workarounds?

I have a number of leases that I need to clear. A hit a bug in my auto-provisioning system that consumed all of my pool IPs.

Today, it doesn’t appear we have a command to clear DHCP leases?!?

So, is there a known workaround to clear DHCP leases so that I can begin provisioning more stuff? - For now I reduced to lease timer, but still I have to waste 3-7 days for my leases to fully expire. :frowning:

I see there’s a feature request open - so I’m just looking for a workaround to fix this right now.

Hello @trevspires,

Yes, feature request opened ⚓ T1375 Add clear dhcp server lease function
I think you can stop DHCP server manually and clear the lease file

sudo su -l
systemctl stop isc-dhcp-server.service
rm /config/dhcpd.leases~
echo "" > /config/dhcpd.leases 
systemctl start isc-dhcp-server.service
exit

Or just edit /config/dhcpd.leases file manually if you want to delete some leases.

Unfortunately, nothing has changed since the time I last tried that. See ⚓ T1375 Add clear dhcp server lease function for details.

The reason we removed the original command for removing a lease is that its script didn’t fully understand the lease file format, especially when failover is involved. It could leave the user with a broken lease file, which is far worse than just telling the user to edit the file by hand.

I suppose the best option would be to patch ISC DHCPD to support lease removal. I’m not sure if they would accept that patch to the upstream though.

Trying to modify lease files also runs into a concurrency problem: dhcpd may attempt to write a lease when the removal script is running.

We may also “just” automate lease purging for emergency situations though, which may be better than nothing.