Automatic switching between backup channels on MikroTik (RouterOS)

Suppose there are two Internet channels, from different or one provider, the gateway can be the same, it does not matter. They are connected to the first and second ports.

We add scripts with the names “ISP1DOWN” and “ISP2DOWN” that will ping some host, for example, the Google DNS address is used, if it becomes unavailable, the port with the active channel will turn off and turn on with the secondary one.
An example of adding a script through the terminal:

system script add name=ISP1DOWN policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source="script text"

Script ISP1DOWN:

:if ([/ping count=5] = 0) do={/interface disable ether1 ;/interface enable ether2 ;/system scheduler disable ISP1 ;/system scheduler enable ISP2}

Script ISP2DOWN:

:if ([/ping count=5] = 0) do={/interface disable ether2 ;/interface enable ether1 ;/system scheduler disable ISP2 ;/system scheduler enable ISP1}

Add to task scheduler:

system scheduler add comment="" disabled=no interval=25s name=ISP1 on-event="ISP1DOWN" policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/01/1970 start-time=00:00:00
system scheduler add comment="" disabled=no interval=25s name=ISP2 on-event="ISP2DOWN" policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/01/1970 start-time=00:00:00

Naturally, ports 1 and 2 are excluded from the standard bridge, if DHCP client is enabled on them.
And also masquerading is configured for both ports:

ip firewall nat add chain=srcnat action=masquerade out-interface=ether2


See also my article:
Configuring MikroTik in half as a router and a switch

Leave a comment

Leave a Reply