Community discussions

MUM Europe 2020
 
User avatar
agomes
newbie
Topic Author
Posts: 31
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
Frequent Visitor
Frequent Visitor
Posts: 94
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: 5173
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.
People who quote full posts should be spanked with ethernet cable. Some exceptions for multi-topic threads may apply. Not intended as incentive for masochists.
 
User avatar
agomes
newbie
Topic Author
Posts: 31
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.
Best regards
Aleksandar

Who is online

Users browsing this forum: Google Feedfetcher and 105 guests