Mikrotik WAN Failover / Bonding

powermzii

Expert Member
Joined
Jun 4, 2007
Messages
3,025
I've moved away from the Netwatch script for failover.

On the weekend I encountered an interesting edge-case where an ISP allowed ICMP traffic even though I was capped. I've moved to use "Detected Internet" within Interfaces. https://wiki.mikrotik.com/wiki/Manual:Detect_internet

View attachment 845581

I added a scheduled script to check the INTERNET interface list and enable/disable accordingly.

Code:
{
:global Wan1CurrentState ([:len [/ip route find where comment="WAN1_ROUTE" and !disabled]] > 0)
:global Wan2CurrentState ([:len [/ip route find where comment="WAN2_ROUTE" and !disabled]] > 0)
:global Wan1State [:len [/interface list member find where list=INTERNET and interface=WAN1]];
:global Wan2State [:len [/interface list member find where list=INTERNET and interface=WAN2]];

:if ($Wan1State = 1 and $Wan1CurrentState = false) do={:log warning "WAN1 up, enabling WAN1_ROUTE";/ip route enable [find comment=WAN1_ROUTE];} 
:if ($Wan1State = 0 and $Wan1CurrentState = true) do={:log warning "WAN1 down, disabling WAN1_ROUTE";/ip route disable [find comment=WAN1_ROUTE];}

:if ($Wan2State = 1 and $Wan2CurrentState = false) do={:log warning "WAN2 up, enabling WAN2_ROUTE";/ip route enable [find comment=WAN2_ROUTE];} 
:if ($Wan2State = 0 and $Wan2CurrentState = true) do={:log warning "WAN2 down, disabling WAN2_ROUTE";/ip route disable [find comment=WAN2_ROUTE];}
}
Thanks for this script, have also implemented it on my router since my Rain connection has decided to start dropping every now and then
 
Top