Automatic Failover using check-ping url without set public IP on mikrotik

Dear Mikrotik Geeks; Hi! I have a question that maybe many of you know about its answer, but i really could not find it. so i go here for asking it:
Consider we have 2 WAN and 1 LAN Interface in our Mikrotik as the bellow:
Int name Mikrotik IP Address Modem IP

WAN#1 (To-ISP 1): 192.168.1.1/24 -------> 192.168.1.254/24 (Modem PPOE) ISP#1 *(Public IP also Automatically Assigned by DHCP From ISP1)
WAN#2 (To-ISP 2): 192.168.2.1/24 -------> 192.168.2.254/24 (Modem PPOE) ISP#2 *(Public IP also Automatically Assigned by DHCP From ISP2)
LAN :192.168.10.1/24
what we want is to prepare a method for routing through main and backup ISP interface as act Fail-Over Automatically base on specific condition.
For example: Set Default route to ISP#1, Check ping “www.yahoo.com”, IF it is not reachable through ISP#1, Then switch default route through the next (ISP#2).
I also read Mikrotik simple fail-over article but it seems that this is not useful much in this case in fact. because check-gateway using ping in this method always answer successfully but maybe without any internet access. also it seems that’s because of all of our IP is internal and we didn’t put any public IP directly in our interface. (if we put public IP, the solution is completely OK)
Thanks for your attention.

http://wiki.mikrotik.com/wiki/Advanced_Routing_Failover_without_Scripting ?

Thanks Black VS. Actually i have read it many before. but i couldn’t understand some of lines. i would appreciate if anyone explain me more. These method consist 3 parts the same as bellow:

Part1)


/ip route
add dst-address=> Host1> gateway=GW1 scope=> 10
add dst-address=> Host2> gateway=GW2 scope=> 10

OK, Consider we want to do check for yahoo.com and google.com so Host1=www.Yahoo.com & Host2=www.google.com. Then we replace these values.
But there is a problem. we are check Host1 using GW1 and Host2 using GW2!

  • Consider the situation that ping request for Yahoo.com answered successful through ISP1, but google.com throgh ISP2 not!
    Let me show it bellow:
    | Int1 → (Modem 1) ISP 1 -------> Yahoo ping is OK, Google ping is not!
    Mikrotik ----
    | Int2 → (Modem 2) ISP 2 -------> Yahoo ping is OK, Google ping is not!

can we conclude that ISP1 is UP and ISP2 is Down at this senario? definitely Not. Because both of them are up now. It seems that we should check Unique conidtion for both GWs (ISPs) not two different. Of course two conditions method is useful more in case of we can define special operator like “AND” for ecah of two GWS. So let’s take it simple for now and use HOST1=HOST2=www.Yahoo.com for test the same condition for both Gateways (GWs).
Also can the scope be something different rather than ‘10’ but equal? does putting it necessary for checking at the same situation too?

Part 2)


Now we create rules for > ISP1> routing mark (one for main gateway, and another one for failover):
/ip route
add distance=1 gateway=> Host1 > routing-mark=ISP1 check-gateway=ping
add distance=2 gateway=> Host2 > routing-mark=ISP1 check-gateway=ping

How can Mikrotik find which out which ISP was used as gateway in case of seting Host1 as gateway?

  • It seems this part is going to mark outgoing traffic. its really good. but why we didn’t set Host1 as ‘dst-address’ and GW1 as ‘gaeway’ the same as bellow for marking its traffic:
    add dst-address=Host1 gateway=GW1 routing-mark=ISP1

Part 3)

Then the same rules for > ISP2> mark:
/ip route
add distance=1 gateway=> Host2 > routing-mark=ISP2 check-gateway=ping
add distance=2 gateway=> Host1 > routing-mark=ISP2 check-gateway=ping

  • what does it mean changing distance in priority of routing mark? we didn’t change gateway order for marking ISP1 too.

Thanks in advance.

Anybody for help me to be clarified more through this method?

You have misunderstood that article completely.
What is achieved through that method is using an external, not on your network, as gateway through recursive routing. By doing this, you can rely on check gateway by ping to see if gateway is up or not.
Basically, if your gateway is 192.168.1.1, using this method you use as gateway 4.2.2.2

/ip route
add dst-address=4.2.2.2 gateway=192.168.1.1 scope=10 
add dst-address=0.0.0.0/0 gateway=4.2.2.2 check-gateway=ping

So now, you are using 4.2.2.2 as gateway, a host which is always up, and checking with it ping. If ping fails, it means that your gateway is down.