Clear all DHCP leases

Hi All,

This question has been asked before but never really answered or I’ve miss read it.
I want a simple way to just flush all DHCP lease entries. I am running VyOS 1.4

There is a command:

clear dhcp-server lease 

Although if I have 50+ leases I don’t want to be going through them individually.

So I thought something like this may work

show dhcp server  leases | awk "{print $1}" | xargs -I {} clear dhcp-server lease {}

Unfortunately this failed :frowning:

Maybe because the script templates were not there.
So I decided to put it into a script but also no luck

#!/bin/vbash

source /opt/vyatta/etc/functions/script-template

run show dhcp server leases | awk '{print $1 }' | xargs -I {} clear dhcp-server lease {}

Anyone have an idea how to clear all entries, without doing them one at a time?

Kind Regards

OR is this the only way? found in another post.

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

Did not really want to play around with the files.

What you’ve posted there will work, basically stop the DHCP Server, remove the lease file, restart the DHCP server.

Your script didn’t work, because your AWK command doesn’t work. Try this:

show dhcp server leases | awk '{print $1 }'
It just prints “1” over and over.

Try this instead:

show dhcp server leases | awk ' NR > 2 {print $1 }'

Still, the easier way is the just stop the DHCP server, nuke the file, restart it.

1 Like

Do you want that we play with this? :wink:
If there is no other way to do it, someone needs to play with it.

1 Like

Thanks all…

Will give the script another crack… may want to delete selected entries. But file removal worked a charm.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.