There appears to be many, many ways to implement fail over between two ISP WAN connections on a hEX. Most of them are a combination of netwatch, script and scheduled scripts.
I have a urgent job where the client wants to fail over to a mobile phone hot spot if the main VDSL2 line goes down. I solved the “How do you connect to a mobile phone hot spot into the network” using a hAP ac lite configured as a Wi-Fi repeater. But that’s almost an aside.
This article talks about fail over without scripting:
https://wiki.mikrotik.com/wiki/Advanced_Routing_Failover_without_Scripting
There is an immediate gotcha with the first bit of code:
/ip route
add dst-address=Host1 gateway=GW1 scope=10
add dst-address=Host2 gateway=GW2 scope=10
This kind of assumes that the gateways are static. Common maybe in a bigger business but not so in this scenario where the WAN links are via DHCP clients - esp. mobile hot spots. So I had to put together a small scheduled script that queries the DHCP client for the current gateway and updates the route table. This is the code for one of the WAN ISP connections:
:if ([:len [/ip dhcp-client find comment=ISP1]] > 0) do={
:put "Updating ISP1 gateway"
:local ISP1Gateway
:set $ISP1Gateway [/ip dhcp-client get [find comment="ISP1"] gateway]
/ip route set gateway=$ISP1Gateway [find comment="Host1"]
}
This script linked in with the article above works a treat but my reason for this post is that I haven’t a clue how it works!! Unplug ISP1/WAN1 and it magically starts routing traffic via ISP2 (mobile hot spot). Reconnect ISP1 and it switches back.
Anyone fancy having a bash of explaining the process that’s going on here? I’m guessing that it’s sort of dynamically changing the distance values depending upon which routes to the two hosts are working. If it’s pinging Host1, then GW1 gets distance 1 & GW2 = distance 2 but if it’s getting through to Host2, then these are swapped over.
But I always like to understand what exactly is going on. What’s the route marking all about?
The more I get to know RouterOS, the more I appreciate it’s awesome power. And in a box costing just £54! Amazing