Community discussions

MikroTik App
 
AiroSam
newbie
Topic Author
Posts: 31
Joined: Mon Jan 30, 2012 7:48 pm
Location: Oklahoma, USA

Needing help on clearing DHCP Leases after Reboot

Thu Oct 29, 2015 11:30 pm

Here's the situation I am running into:

I have a 911G-5HPnD on a clients roof, handing out an IP address via DHCP to the client's router. The DHCP network uses a /30 subnet, therefore there is only one available IP address to hand out (the other is the Gateway on our 911).

What will happen is, the client will plug a different device into our line, and it will not pull an IP address because the pool is empty. This is to be expected, yes, but it seems the only way for the previous DHCP Lease to go away is for me to log into the radio and manually remove it (or let the lease time run out). Rebooting does not work.

I'm looking for a way to automatically clear the DHCP Leases upon a reboot. I tried ip dhcp-server config set store-leases-disk=never and it didn't seem to work.

Perhaps there is a simple script to achieve what I'm looking for? That, or any other suggestions, would be much appreciated.
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 282
Joined: Tue Feb 10, 2015 3:21 pm

Re: Needing help on clearing DHCP Leases after Reboot

Fri Oct 30, 2015 12:01 pm

You can also set lease time to very small time interval, it should solve the problem.

for e.g.
/ip dhcp-server set lease-time=15s
 
bhesterberg
newbie
Posts: 36
Joined: Wed Jul 06, 2016 8:27 pm
Location: Gifford, IL
Contact:

Re: Needing help on clearing DHCP Leases after Reboot

Thu Mar 30, 2017 1:38 am

You can also set lease time to very small time interval, it should solve the problem.

for e.g.
/ip dhcp-server set lease-time=15s
That doesn't seem to be best practices. You can't set a DHCP lease on an active network to 15 seconds.
Are you telling me there is no way to flush DHCP leases in Mikrotik???
 
AiroSam
newbie
Topic Author
Posts: 31
Joined: Mon Jan 30, 2012 7:48 pm
Location: Oklahoma, USA

Re: Needing help on clearing DHCP Leases after Reboot

Thu Mar 30, 2017 4:08 pm

You can also set lease time to very small time interval, it should solve the problem.

for e.g.
/ip dhcp-server set lease-time=15s
That doesn't seem to be best practices. You can't set a DHCP lease on an active network to 15 seconds.
Are you telling me there is no way to flush DHCP leases in Mikrotik???
I ended up going with the following solution:
/system scheduler
add name="Remove-Lease on Reboot" on-event="/system script run \"Remove-Lease\"" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=startup
/system script
add name=Remove-Lease owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source="/ip dhcp-server lease rem 0\r\
    \n:log info \"Removed DHCP Lease due to reboot\""

It's pretty simple and works great for what we were needing.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10231
Joined: Mon Jun 08, 2015 12:09 pm

Re: Needing help on clearing DHCP Leases after Reboot

Thu Mar 30, 2017 4:45 pm

What about simply setting the store-leases-on-disk time to "never" ?
 
bhesterberg
newbie
Posts: 36
Joined: Wed Jul 06, 2016 8:27 pm
Location: Gifford, IL
Contact:

Re: Needing help on clearing DHCP Leases after Reboot

Fri Mar 31, 2017 1:22 am

What about simply setting the store-leases-on-disk time to "never" ?
Did that. Didn't work.
 
bhesterberg
newbie
Posts: 36
Joined: Wed Jul 06, 2016 8:27 pm
Location: Gifford, IL
Contact:

Re: Needing help on clearing DHCP Leases after Reboot

Fri Mar 31, 2017 1:24 am

You can also set lease time to very small time interval, it should solve the problem.

for e.g.
/ip dhcp-server set lease-time=15s
That doesn't seem to be best practices. You can't set a DHCP lease on an active network to 15 seconds.
Are you telling me there is no way to flush DHCP leases in Mikrotik???
I ended up going with the following solution:
/system scheduler
add name="Remove-Lease on Reboot" on-event="/system script run \"Remove-Lease\"" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=startup
/system script
add name=Remove-Lease owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source="/ip dhcp-server lease rem 0\r\
    \n:log info \"Removed DHCP Lease due to reboot\""

It's pretty simple and works great for what we were needing.

Although I'm sure this does work, it's hardly simple. It still doesn't answer the question as to why there's no way to flush DHCP leases. That seems like such a basic feature that ALL DHCP servers should have. I'm looking for ONE button that says "Flush DHCP Leases". MT should have that.
And even after I removed all the leases manually, they were still active and passing traffic, not pulling a new DHCP lease.
 
idlemind
Forum Guru
Forum Guru
Posts: 1146
Joined: Fri Mar 24, 2017 11:15 pm
Location: USA

Re: Needing help on clearing DHCP Leases after Reboot

Fri Mar 31, 2017 2:15 am

You can also set lease time to very small time interval, it should solve the problem.

for e.g.
/ip dhcp-server set lease-time=15s
That doesn't seem to be best practices. You can't set a DHCP lease on an active network to 15 seconds.
Are you telling me there is no way to flush DHCP leases in Mikrotik???
I ended up going with the following solution:
/system scheduler
add name="Remove-Lease on Reboot" on-event="/system script run \"Remove-Lease\"" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=startup
/system script
add name=Remove-Lease owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source="/ip dhcp-server lease rem 0\r\
    \n:log info \"Removed DHCP Lease due to reboot\""

It's pretty simple and works great for what we were needing.

Although I'm sure this does work, it's hardly simple. It still doesn't answer the question as to why there's no way to flush DHCP leases. That seems like such a basic feature that ALL DHCP servers should have. I'm looking for ONE button that says "Flush DHCP Leases". MT should have that.
And even after I removed all the leases manually, they were still active and passing traffic, not pulling a new DHCP lease.
Let's start by RTFM, RFC2131

https://www.ietf.org/rfc/rfc2131.txt

Looking at what DHCP "must" support:
   The following list gives design goals specific to the transmission of
   the network layer parameters.  DHCP must:

      o Guarantee that any specific network address will not be in
        use by more than one DHCP client at a time,

      o Retain DHCP client configuration across DHCP client reboot.  A
        DHCP client should, whenever possible, be assigned the same
        configuration parameters (e.g., network address) in response
        to each request,

      o Retain DHCP client configuration across server reboots, and,
        whenever possible, a DHCP client should be assigned the same
        configuration parameters despite restarts of the DHCP mechanism,
Great that hits one of your gripes. To be a RFC compliant DHCP server they must be able to retain DHCP client configuration (read lease) across server (read your mikrotik) reboots. Ker-blamo.

The next item. How would a client know that the lease has been deleted on the server? The DHCP client on the PC is not listening for updates from the server and the server is not permitted to send updates to the PC unless it is part of the negotiation initiated by the server. The DHCPRELEASE message is a client issued packet and therefore can't be sent by the server to the client. So that knocks out your other issue.

In other words, "working as intended."

Now I get your problem, you've got a user and they just want an IP. They don't care that they've been given a /30 and what not so I'm in favor you manually doing what you've got to do w/the DHCP lease on reboot.

An alternative solution might be to leverage the MikroTik API and script the removal of the lease in either your NMS, networking monitoring system, or your client portal. Let the customer login and click the "clear leases" button if they need to.

Who is online

Users browsing this forum: Bing [Bot], ihexley and 73 guests