Community discussions

MikroTik App
 
User avatar
agomes
newbie
Topic Author
Posts: 38
Joined: Thu Mar 17, 2016 8:16 am

Feature suggestion: Check gateway when using DHCP client

Wed Jun 28, 2017 2:43 pm

Hello,

as the topic suggests, some ISP provide the internet link using DHCP and in RouterOS it's not possible to set the option "Check gateway: <ping/arp>" on the default route added dynamically by the DHCP clent. Therefore if the lease time is set high on the ISP DHCP server and the ISP gateway isn't rechable anymore, the default route is shown reachable where as it's actually not.

Such a feature would be really handy when using RouterOS as Load Balancer with multiple DHCP ISP links.
Let me know what you think about it.

Best regards
Aleksandar
 
User avatar
che
Member Candidate
Member Candidate
Posts: 111
Joined: Fri Oct 07, 2005 1:04 pm

Re: Feature suggestion: Check gateway when using DHCP client

Wed Jun 28, 2017 3:29 pm

Hello Aleksandar, I've had the same obstacle and here is what I've done in the end.

I've created a static route with option check gateway ping and "dhcp gw" comment. Then I've written a short Frankenstein AI that reads DHCP parameters and updates few global variables:
:global fwIP
:global dynamicIP

:local readIP [/ip address get value-name=address [/ip address find where actual-interface="ether2 - dhcp"];
:global dhcpGW [/ip dhcp-client get value-name=gateway number=0];

:set dynamicIP [:pick $readIP 0 [:find $readIP "/"]];
:global stateofGW [:typeof $dhcpGW];

:if ($dynamicIP != $fwIP) do={
       :set fwIP $dynamicIP
       /ip firewall address-list set [/ip firewall address-list find comment="WAN - DHCP"] address=$dynamicIP
       /ip route set [/ip route find comment="dhcp gw"] gateway=$dhcpGW
       /ip dns static set [/ip dns static find name="dhcp.gw"] address=$dhcpGW
       :log info "DHCP WAN IP updated. Firewall DST-NAT and routes fixed."
}
You can safely remove adress-list and dns related lines since those are not related to your question.

I've scheduled it to run every 15 munutes.
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: Feature suggestion: Check gateway when using DHCP client  [SOLVED]

Wed Jun 28, 2017 4:09 pm

You can use routing filters to set check-gateway, routing-mark and other parameters for DHCP routes:
/ip dhcp-client
add default-route-distance=33 interface=<name>
/routing filter
add chain=dynamic-in distance=33 set-check-gateway=ping set-distance=1
Distance 33 is just some unique value to identify the route. Direct options in DHCP client would feel more user friendly, but this works too.
 
User avatar
agomes
newbie
Topic Author
Posts: 38
Joined: Thu Mar 17, 2016 8:16 am

Re: Feature suggestion: Check gateway when using DHCP client

Wed Jun 28, 2017 9:15 pm

You can use routing filters to set check-gateway, routing-mark and other parameters for DHCP routes:
/ip dhcp-client
add default-route-distance=33 interface=<name>
/routing filter
add chain=dynamic-in distance=33 set-check-gateway=ping set-distance=1
Distance 33 is just some unique value to identify the route. Direct options in DHCP client would feel more user friendly, but this works too.
Nice. I did not know that filter rules based on routing triggers could be set. Thank you very much for showing me this. Now, as you said "Direct options in DHCP client would feel more user friendly, but this works too.". @che: Also, thank you for sharing your script with us. I will go with Sob's solution because this way is already implemented into the OS.

Best regards
Aleksandar
You do not have the required permissions to view the files attached to this post.
 
dejanr
just joined
Posts: 2
Joined: Mon May 08, 2023 7:50 pm

Re: Feature suggestion: Check gateway when using DHCP client

Mon May 08, 2023 7:52 pm

/routing filter
add chain=dynamic-in distance=30 set-check-gateway=ping set-distance=31

does not work? Please check
 
surgeon1
just joined
Posts: 2
Joined: Sat May 20, 2023 10:36 pm

Re: Feature suggestion: Check gateway when using DHCP client

Sat May 20, 2023 10:45 pm

/routing filter
add chain=dynamic-in distance=30 set-check-gateway=ping set-distance=31

does not work? Please check
Confirmed (ROS 7.7-7.8 tested).
It returns "bad command name add (line 1 column 1)".
 
rrusch
just joined
Posts: 1
Joined: Sat May 27, 2023 5:43 pm

Re: Feature suggestion: Check gateway when using DHCP client

Sat May 27, 2023 5:51 pm

As far as i know, this is no longer possible in RouterOS v7. There were huge changes in /routing/filter/, this is why you experience the "bad command" error. But even if you change the command to create a filter that is accepted, it will not work because chain "dynamic-in" no longer exists.
I'm using a dhcp client script to enable gateway check:
if ($bound=1) do={
:local r [/routing/route find distance=33]
/ip/route/set $r check-gateway=ping
/ip/route/set $r distance=1
}
 
surgeon1
just joined
Posts: 2
Joined: Sat May 20, 2023 10:36 pm

Re: Feature suggestion: Check gateway when using DHCP client

Fri Jul 21, 2023 8:04 pm

I'm using a dhcp client script
And what if the second gateway is some PPP (PPTP, for instance) with "Enable default route" and without particular dhcp client? Will setting that script be sufficient only on one dhcp client?

Who is online

Users browsing this forum: Bing [Bot], Omerik and 99 guests