Page 1 of 1

/ip route with named gateway doesn't work

Posted: Tue Apr 11, 2017 7:01 am
by jebz
If I have 2x ISP feeds to my router and set both interfaces with a DHCP client and default route but distance of 1,2. They don't fail over even when the second shows active in IP Routes in Winbox.
If I delete the dynamic routes added by the DHCP client and add the following code -
/ip route
add dst-address=0.0.0.0/0  gateway=ether1-WAN1 distance=1
add dst-address=0.0.0.0/0  gateway=ether2-WAN2 distance=2

/ip firewall nat
add chain=src-nat  out-interface=ether1-WAN1 action=masquerade
add chain=src-nat  out-interface=ether2-WAN2 action=masquerade
WAN2 doesn't take over if WAN1 is disconnected the same as dynamic routes. But if I assign direct addresses like this it works -
/ip route
add dst-address=0.0.0.0/0  gateway=10.0.1.1 distance=1
add dst-address=0.0.0.0/0  gateway=192.168.100.1 distance=2
Then the route fail over works.The problem is the IP addresses of WAN1 and WAN2 aren't static as they're assigned via DHCP from the ISP. Is there a way to make this work? I assume this configuration is valid as the option in Winbox provides a dropdown to select the gateway interface from the router's available interfaces.
Tried ROS v6.29, v6.38.5

Re: /ip route with named gateway doesn't work

Posted: Tue Apr 11, 2017 7:16 am
by null31
Are gateway IPs static at least?
The failover need an script to disable default-route from WAN1 when has not connectivity.
Edit: You can use /tool netwatch to run the script.
IP from interfaces don't need to be static to works the failover. Also works fine with dhcp client and add-default-route=no.

Re: /ip route with named gateway doesn't work

Posted: Tue Apr 11, 2017 7:46 am
by jebz
No script should be needed that 's what the distance setting is for. It ranks the gateway in preferred order. As I said it appears as if the gateway isn't specified as an IP address it doesn't fail over as it should.
There's quite a few examples of configurations with named gateway interfaces like -
https://blog.linitx.com/load-balancing- ... /#more-932
Apart from the pick list in Winbox when you attempt to add a new route.

Re: /ip route with named gateway doesn't work

Posted: Tue Apr 11, 2017 7:58 am
by null31
Named gateways works on tunnels interfaces as far as I know.

The example from link uses PPPoE tunnel, when is down, the route will be disabled (not active). He also recommend to use check-gateway=ping to check if route is fine or not, when is an IP Gateway.

Edit: The method I use to do failover, uses netwatch rather than check-gateway=ping.

Re: /ip route with named gateway doesn't work

Posted: Tue Apr 11, 2017 11:18 am
by scampbell
Named interfaces only work on interfaces point to point (ppp) addresses otherwise there are too many possible valid hosts to know which one is the next hop.


Sent from my iPhone using Tapatalk

Re: /ip route with named gateway doesn't work

Posted: Tue Apr 11, 2017 4:10 pm
by jebz
Named interfaces only work on interfaces point to point (ppp) addresses otherwise there are too many possible valid hosts to know which one is the next hop.
Well if you choose "Add default route" on the WAN interface DHCP client it only has one default route address not dissimilar to the PPP interface. In IP route it shows this single address as DAS and the inactive one (Distance=2) as DS.

Re: /ip route with named gateway doesn't work

Posted: Tue Apr 11, 2017 6:30 pm
by null31
In IP route it shows this single address as DAS and the inactive one (Distance=2) as DS.
Because of this you need to use the check-gateway or netwatch to disabled the route with distance=1.
Remember: This default routes need to be added manually to work that methods, you MUST left the options on DHCP Client as add-default-route=no.