Community discussions

MikroTik App
 
jebz
Member
Member
Topic Author
Posts: 367
Joined: Sun May 01, 2011 12:03 pm
Location: Australia

/ip route with named gateway doesn't work

Tue Apr 11, 2017 7:01 am

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
Last edited by jebz on Tue Apr 11, 2017 7:35 am, edited 2 times in total.
 
User avatar
null31
Member Candidate
Member Candidate
Posts: 183
Joined: Fri Dec 23, 2016 6:07 pm
Location: Brazil

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

Tue Apr 11, 2017 7:16 am

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.
 
jebz
Member
Member
Topic Author
Posts: 367
Joined: Sun May 01, 2011 12:03 pm
Location: Australia

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

Tue Apr 11, 2017 7:46 am

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.
 
User avatar
null31
Member Candidate
Member Candidate
Posts: 183
Joined: Fri Dec 23, 2016 6:07 pm
Location: Brazil

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

Tue Apr 11, 2017 7:58 am

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.
 
scampbell
Trainer
Trainer
Posts: 487
Joined: Thu Jun 22, 2006 5:20 am
Location: Wellington, NZ
Contact:

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

Tue Apr 11, 2017 11:18 am

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
 
jebz
Member
Member
Topic Author
Posts: 367
Joined: Sun May 01, 2011 12:03 pm
Location: Australia

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

Tue Apr 11, 2017 4:10 pm

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.
 
User avatar
null31
Member Candidate
Member Candidate
Posts: 183
Joined: Fri Dec 23, 2016 6:07 pm
Location: Brazil

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

Tue Apr 11, 2017 6:30 pm

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.

Who is online

Users browsing this forum: andrewrmack, Evaluator and 137 guests