Community discussions

Forum Veteran
Forum Veteran
Topic Author
Posts: 774
Joined: Mon May 14, 2012 9:30 pm

2 dynamic ISPs enabling failover

Wed Dec 12, 2012 5:34 pm

Every "how to" seems to be only for static IPs.

So I have 2 WAN connections. From 2 ISPs.
Using "add default route" in DHCP client... I set WAN 1 to 1 and WAN 2 to 2. Unplug or kill the port for WAN 1 and things hop to WAN 2.

Now the issue is when the connection is still UP but not working... like a locked up modem.

Going into routes I tried to set a route like this
/ip route
add check-gateway=ping disabled=no distance=1 dst-address= \
    gateway=ether10-WAN scope=30 target-scope=10
If I do this it shows as Active and Reachable.

The idea was so the router would try to reach OpenDNS via Ether-10. When this route is down that would be used to tell the router to use ISP 2.

So I tried making a netwatch to check that IP.
Figuring I could maybe get a script to increase the distance on the route to 3 when its down. So that ISP 2 would handle traffic. Then when that route was active again... have an up script that sets distance back to 1.

The issue is that the route always appears as up to netwatch. Even when I set gateway to Ether-3 which is local subnet.

Am I over thinking this or is there a better method?
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so."
Mark Twain
User avatar
Member Candidate
Member Candidate
Posts: 138
Joined: Wed May 30, 2007 10:57 am
Location: USA

Re: 2 dynamic ISPs enabling failover

Tue Feb 26, 2013 8:13 pm

I have many posts on the use of dyanmic IPs used in both load balancing as well as active-backup scenarios. The simplest, active-backup failover that you are trying to accomplish, can be obtained by creating two static routes, each to a single address reachable via one of the providers. I like to use public DNS servers, but you could also use that ISPs DNS servers. Then create your Netwatch to monitor these IPs and enable or disable the appropriate gateway.

With your two ISP gateways set to a distance of 10 and 11 in dhcp-client (replace with appropriate gateways specific to each provider):
/ip route add dst-address= gateway=<ISP1 gateway>
/ip route add dst-address= gateway=<ISP2 gateway>
Netwatch rules as follows:
/tools netwatch add comment=Provider1 host= down-script="/ip route set [find distance=10] disabled=yes" up-script="/ip route set [find distance=10] disabled=no"
/tools netwatch add comment=Provider2 host= down-script="/ip route set [find distance=11] disabled=yes" up-script="/ip route set [find distance=11] disabled=no"
Even though most providers dynanically assign the IP, the range of addresses is usually such that the gateway NEVER changes and lends itself to the static route creation above. If, however, the gateway does periodically change, you will need to employ the optional routing package to create routing filters that mark the dynamically learned routes and then mangle the traffic appropriately to also mark the connections to those routing marks. Lookup my other posts for full details on this method.
- If I helped you solve your problem... I am now able to accept tax-deductible Karma donations!
User avatar
Posts: 33
Joined: Tue Apr 29, 2014 5:55 am

Re: 2 dynamic ISPs enabling failover

Tue Oct 17, 2017 11:22 pm

Any reason this does not have "find distance=1" and "find distance=2" in the script? Those are my distances for WAN 1 and WAN 2. Is that related??

Who is online

Users browsing this forum: No registered users and 36 guests