Community discussions

MikroTik App
 
pgf
just joined
Topic Author
Posts: 20
Joined: Fri Feb 18, 2022 6:56 pm

remove all static DHCP leases?

Sun Feb 20, 2022 11:14 pm

I'd like to manage my DHCP static leases outside of the router. (I'll likely be using a simple text file, containing hostname, IP address, and MAC, but how I store my list doesn't really matter.)

I can easily turn that list into the "/ip dhcp-server lease add ..." commands needed to load them into the server. But if I retire a host, and remove it from my text file, it won't (easily) be removed from the router by my script. Similarly, if I want to give a host a new address, simply reimporting will result in two leases for that host.

The obvious clean solution would be to simply clear all static leases, and then add them back again.

Is there a way to clear all static leases using the MikroTik console?
 
Kanta
newbie
Posts: 31
Joined: Tue May 15, 2018 7:54 pm

Re: remove all static DHCP leases?

Mon Feb 21, 2022 12:27 am

use find
this will remove all leases, including dynamic ones
/ip dhcp-server lease remove [find] 
something like this to find leases with a specific adress
/ip dhcp-server lease remove [find where where address=insert-ip] 
all available options
.dead               agent-circuit-id        dhcp-option-set      radius         
.id                 agent-remote-id         disabled             rate-limit     
.nextid             allow-dual-stack-queue  dynamic              server         
active-address      always-broadcast        expires-after        src-mac-address
active-client-id    block-access            host-name            status         
active-mac-address  blocked                 insert-queue-before  use-src-mac    
active-server       client-id               last-seen            
address             comment                 lease-time           
address-lists       dhcp-option             mac-address   
No options for finding only static ones or I might be missing something you could use to target just them, seems weird to not have something like that.
 
pgf
just joined
Topic Author
Posts: 20
Joined: Fri Feb 18, 2022 6:56 pm

Re: remove all static DHCP leases?

Mon Feb 21, 2022 1:58 am

Thanks. I certainly wouldn't want to remove the dynamic ones. I can probably cobble something together, by printing the leases and writing a script to find the ones not marked dynamic. But it'll be ugly, I can promise you that.

I suppose anyone that wants to manage addresses off-router uses a radius server. I wish there were something in between that and having to use the CLI, though, like maybe reading static lease information from a file. The other alternative is running a separate DHCP server.
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: remove all static DHCP leases?

Mon Feb 21, 2022 4:55 am

/ip dhcp-server lease remove [find where dynamic=no]
You can both print and export to file.
/ip dhcp-server lease export file=dhcp-static
 
pgf
just joined
Topic Author
Posts: 20
Joined: Fri Feb 18, 2022 6:56 pm

Re: remove all static DHCP leases?

Mon Feb 21, 2022 6:09 am

So, that first command does exactly what I was asking for? That's excellent! Thanks!

paul

Who is online

Users browsing this forum: rizan and 32 guests