Feature suggestion: Check gateway when using DHCP client

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

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.

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
Screenshot from 2017-06-28 20-02-28.png

/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)”.

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
}

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?