Community discussions

MikroTik App
 
hkr
just joined
Topic Author
Posts: 12
Joined: Fri Sep 25, 2009 11:16 pm

Looking for a failover script

Mon Oct 12, 2009 9:27 am

Hello All,

I wonder if anyone has an adaptable/adoptable failover script or can help me write one. I am quite new to RouterOS, and have very limited knowledge.

I have a CATV internet connection on ether2, a PPPoE ADSL link on ether3, and a second local router on the LAN port ether1, with 192.168.2.2. I use the basic failover setup at the moment, if I unplug the wire from ether2, packets go to ether3, and if I unplug that too, packets go via the other router on the LAN. So far so good. But.

This morning I found that the internet was unreachable. I unplugged ether2, and bingo, the failover link was activated, I had internet on my ADSL backup link.. So I checked things, and the problem is that while the cable gateway IS reachable, packets go no further from the gateway. This nicely prevents the failover to hand over traffic to my ADSL or 3G connections. So it would be better to ping remote hosts on the internet to determine if the connection is up or not, rather than just pinging the gateway.

Has anyone by any chance written a failover script that could be adapted/adopted ? What I thought of: ping a series of servers regularly using different routes. If on a specific route X pings in sequence fail, but the host is available on another route, disable the default route using the given inteface/gateway. And when the host becomes available again, re-activate it.

Or any other solution? Does anyone have any working solution?
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Looking for a failover script

Mon Oct 12, 2009 7:02 pm

Use "/tool netwatch" to watch any host IP and fire scripts on up and down events.

However, it's a little tricky to do this fully automated without event loops. Let's say you're monitoring google.com and disable the CATV interface when that host goes down. Now the ADSL link is up, google is back up, and the 'up' event re-enables the CATV interface. Now google is back down, ad infinitum.

To get around that, either watch a host that is guaranteed unreachable via the failover connection (not that easy to do with specific routes since those will be invalid once their target interface gets disabled), or don't implement an up script and code the down script to include log warnings or emails sent out, causing you to manually check for the main link to be up again.
 
hkr
just joined
Topic Author
Posts: 12
Joined: Fri Sep 25, 2009 11:16 pm

Re: Looking for a failover script

Mon Oct 12, 2009 7:30 pm

Hi, thanks for the hint.

I thought of something like:

We choose one/several test hosts that we want to ping. We set up individual routes to these hosts in the IP routes table via all available ports/gateways.
We periodically these internet hosts via the specific gateway/port. If there is no reply after 5 consecutive pings, we mark the default route (0.0.0.0/0) associated with that gateway down, or even remove it. We can run same/similar script for all gateways/ports. We keep pinging these test hosts on their individually set-up routes, and when we see that the host is available again, we enable/add a 0.0.0.0/0 route with the associated distance weight. This way we would avoid a situation like the one you mention.

There might be good solutions, and I am sure someone already has written a nice script for this purpose for RouterOS. Even my Draytek dual WAN router I have can ping remote hosts to determine if a specific WAN port can reach the internet or not and activate/deactivate roting via its WAN ports.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Looking for a failover script

Mon Oct 12, 2009 7:48 pm

Since specific routes would turn invalid (and would not be consulted) on interface failures, that would be rather complex to set up. Additionally, consider that the monitored host going down doesn't necessarily mean the WAN connection is actually down. Any host upstream could fail for any reason.
 
hkr
just joined
Topic Author
Posts: 12
Joined: Fri Sep 25, 2009 11:16 pm

Re: Looking for a failover script

Mon Oct 12, 2009 8:26 pm

Originally I thought of testing the availability of a series of hosts, and if X% of those fail on the link, while they still work via another gateway, that would trigger a failover. If one particular host is down on one particular interface, but not on another it would trigger a specific route to that host. And if a host is unavailable on all gateways, we would consider that a problem with the host rather than our own connection.

Who is online

Users browsing this forum: No registered users and 20 guests