Community discussions

MikroTik App
 
mihaifpopa
just joined
Topic Author
Posts: 10
Joined: Wed Jul 28, 2021 1:21 pm

Reject DHCP lease

Thu Nov 03, 2022 12:55 pm

Hello!

I have a problem with my hAP AC3. Whenever my cable modem goes down, my MikroTik gets a 192.168.100.x IP from it instead of the WAN public address. Coming from pfSense, which had this option to reject DHCP leases from an IP, how can I get this done on RouterOS?

Link here for the option on pfSense: https://www.reddit.com/r/PFSENSE/commen ... are_button

Thank you!
 
User avatar
BrateloSlava
Member Candidate
Member Candidate
Posts: 132
Joined: Mon Aug 09, 2021 10:33 am
Location: Ukraine, Kharkiv

Re: Reject DHCP lease

Thu Nov 03, 2022 5:21 pm

If you receive an address from the 192.168.100.0 subnet, is the global network available?

Or rather, not even so. See, what gateway address your router is getting on the 192.168.100.0 network. I understand, that this address will be available only if there is no access to the global network. Therefore, through NetWatch, you can check. If this address is available, execute the dhcp client reset command on the required interface.

This is the first thing, that came to mind.
 
mihaifpopa
just joined
Topic Author
Posts: 10
Joined: Wed Jul 28, 2021 1:21 pm

Re: Reject DHCP lease

Mon Nov 07, 2022 5:45 pm

I have no clue how to do that, honestly. Any help with that?
Thank you so much!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 9595
Joined: Tue Feb 25, 2014 12:49 pm
Location: 🇮🇹, my 💔 is in 🇺🇦

Re: Reject DHCP lease  [SOLVED]

Mon Nov 07, 2022 6:04 pm

Based on this:
viewtopic.php?t=190573#p965860

Paste this on DHCP Client / Advanced / Script
:if ($bound = 1) do={
    :local leaseIP $"lease-address"
    :local iname   [/interface get $interface name]
    :if ($leaseIP in 192.168.100.0/24) do={
        :log warning "I do not like $leaseIP provided by the DHCP Server on $iname, I am about to provoke a Release in 10 seconds."
        :delay 10s ; # this prevents excessive CPU usage
        /ip dhcp-client
        release [find where interface=$iname]
    } else={
        :log info "I like $leaseIP provided by the DHCP Server on $iname."
    }
}
 
mihaifpopa
just joined
Topic Author
Posts: 10
Joined: Wed Jul 28, 2021 1:21 pm

Re: Reject DHCP lease

Mon Nov 07, 2022 7:09 pm

While I have found this workaround which is similar but less efficient since it pings 8.8.8.8 continuously, I'm using yours because it's much, much more efficient.

viewtopic.php?t=153318#p839035

Thank you so much for your quick reply! Tested and it's working amazing!
Last edited by BartoszP on Mon Nov 07, 2022 7:34 pm, edited 1 time in total.
Reason: removed excessive quotting of preceding post; be wise, quote smart.

Who is online

Users browsing this forum: Ahrefs [Bot] and 15 guests