Community discussions

MikroTik App
 
electravis
Member Candidate
Member Candidate
Topic Author
Posts: 259
Joined: Tue Jan 26, 2010 12:06 am

ISP failover

Wed Feb 23, 2011 10:20 pm

I have been trying some time to get some form of failover between isps to work. I have tried all the different scripts on the mikrotik page I could find and all come back to the same problem.
I have ISP A on port 1 and ISP B on port 2. In my routes I have ISP A distance 1 and ISP B distance 2. Even if I unhook the ISP A form the incoming connection. My script will run and will change ISP A distance to 3 however it still get pings out of port 1 and thus runs the up script. Below is a copy of what script I have been trying to run. AS i said the scripts run and work but why can I still ping out a port that has no ISP connection? It gets a ping through about every 15th try. Then the next problem I see is if the ISP does come up I still do not get 5 pings in a row for the script to run to switch back the distance.

script 1:

:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 64.233.169.99 interval=3 count=1]=0))};
:if ($i=5 && [/ip route get [find comment="Default Route"] distance]=1) do={:log info "Main Gateway down";
/ip route set [find comment="Default Route"] distance=3}
script 2:

:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 64.233.169.99 interval=3 count=1]=1))};
:if ($i=5 && [/ip route get [find comment="Default Route"] distance]=3) do={:log info "Main Gateway up";
/ip route set [find comment="Default Route"] distance=1}
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1685
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: ISP failover

Wed Feb 23, 2011 11:53 pm

This works. I'm using it for months..
http://wiki.mikrotik.com/wiki/Advanced_ ... _Scripting
Martín Ruiz
martinruiz at ibersystems.es
Experto en redes WiFi y enlaces WiFi.

Facebook: @Ibersystems
Twitter: @Ibersystems

Certified in:
MTCNA - MTCTCE - MTCWE - MTCINE - MTCUME - MTCRE - MTCSE
 
User avatar
acim
Member
Member
Posts: 424
Joined: Mon Sep 12, 2005 12:26 am
Location: Serbia
Contact:

Re: ISP failover

Thu Mar 10, 2011 2:05 pm

This wiki example is not working for me.
/ip route
add dst-address=Host1 gateway=GW1 scope=10
add dst-address=Host2 gateway=GW2 scope=10
add distance=1 gateway=Host1 routing-mark=ISP1 check-gateway=ping
add distance=2 gateway=Host2 routing-mark=ISP1 check-gateway=ping
add distance=1 gateway=Host2 routing-mark=ISP2 check-gateway=ping
add distance=2 gateway=Host1 routing-mark=ISP2 check-gateway=ping
And I've tried this:
/ip route
add dst-address=Host1 gateway=GW1 scope=10
add dst-address=Host2 gateway=GW2 scope=10
add distance=1 gateway=GW1 routing-mark=ISP1 check-gateway=ping
add distance=2 gateway=GW2 routing-mark=ISP1 check-gateway=ping
add distance=1 gateway=GW2 routing-mark=ISP2 check-gateway=ping
add distance=2 gateway=GW1 routing-mark=ISP2 check-gateway=ping
and this is still not working. Do I still need something more in /ip route or not?

Without this failover stuff I have default gateway and when I put this configuration and disable default gateway Internet stops. Please let me know what I am doint wrong? Thank you in advance.
 
forne
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Feb 15, 2011 3:18 pm

Re: ISP failover

Thu Mar 10, 2011 2:19 pm

You need some mangle rules as well. An example is here:

http://forum.mikrotik.com/viewtopic.php ... 00#p252900
 
User avatar
acim
Member
Member
Posts: 424
Joined: Mon Sep 12, 2005 12:26 am
Location: Serbia
Contact:

Re: ISP failover

Thu Mar 10, 2011 2:39 pm

It's good that the author of:

http://wiki.mikrotik.com/wiki/Advanced_ ... _Scripting

didn't say a word about mangle.
 
User avatar
acim
Member
Member
Posts: 424
Joined: Mon Sep 12, 2005 12:26 am
Location: Serbia
Contact:

Re: ISP failover

Thu Mar 10, 2011 3:02 pm

What of these two configurations is correct?

1. This is from wiki:
/ip route
add dst-address=Host1 gateway=GW1 scope=10
add dst-address=Host2 gateway=GW2 scope=10
add distance=1 gateway=Host1 routing-mark=ISP1 check-gateway=ping
add distance=2 gateway=Host2 routing-mark=ISP1 check-gateway=ping
add distance=1 gateway=Host2 routing-mark=ISP2 check-gateway=ping
add distance=2 gateway=Host1 routing-mark=ISP2 check-gateway=ping
But I supose that Host1 and Host2 cant't be our gateways because they are not on our network, they can be Google and Yahoo, like author of wiki tutorial said. Instead, I think GW1 and GW2 should be used:
/ip route
add dst-address=Host1 gateway=GW1 scope=10
add dst-address=Host2 gateway=GW2 scope=10
add distance=1 gateway=GW1 routing-mark=ISP1 check-gateway=ping
add distance=2 gateway=GW2 routing-mark=ISP1 check-gateway=ping
add distance=1 gateway=GW2 routing-mark=ISP2 check-gateway=ping
add distance=2 gateway=GW1 routing-mark=ISP2 check-gateway=ping
 
forne
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Feb 15, 2011 3:18 pm

Re: ISP failover

Thu Mar 10, 2011 3:09 pm

acim, the configuration in wiki is correct. Read how recursive nexthop lookup works:

http://wiki.mikrotik.com/wiki/Manual:IP ... hop_lookup
 
User avatar
acim
Member
Member
Posts: 424
Joined: Mon Sep 12, 2005 12:26 am
Location: Serbia
Contact:

Re: ISP failover

Thu Mar 10, 2011 3:14 pm

Thank you very much!
 
el berto
Member Candidate
Member Candidate
Posts: 211
Joined: Wed Sep 26, 2007 10:53 am

Re: ISP failover

Fri Apr 08, 2011 3:15 pm

Hi, I don't know if it's the same (or similar) problem: I have a PC (IP=158.110.30.56) that can access to internet with gateway=158.110.30.2.
Now I would make a second connection (through a GPRS modem) when first connection is not available.

So I made this:
PC
ip address=158.110.30.56
gateway=158.110.30.57

router GPRS
ip address=192.168.33.1

Mikrotik Router:
eth1 = 158.110.30.58 (to connect to main router with gateway 158.110.30.2)
eth2 = 158.110.30.57 (to connect to PC)
eth3 = 192.168.33.2 (to connect to GPRS router)
Then i made this:
/ip route add dst-address=74.125.232.113 gateway=158.110.30.2 scope=10
/ip route add dst-address=69.147.125.65 gateway=192.168.33.1 scope=10
/ip route add distance=1 gateway=74.125.232.113 routing-mark=ISP1 check-gateway=ping
/ip route add distance=2 gateway=69.147.125.65 routing-mark=ISP1 check-gateway=ping
/ip route add distance=1 gateway=69.147.125.65 routing-mark=ISP2 check-gateway=ping
/ip route add distance=2 gateway=74.125.232.113 routing-mark=ISP2 check-gateway=ping
where 74.125.232.113 and 69.147.125.65 are addresses of www.google.com and www.yahoo.com

Is it right?

Who is online

Users browsing this forum: No registered users and 125 guests