Thursday, November 7, 2019

Mikrotik FailOver Example without Netwatch

- For example you have 2 internet lines, one for main route and another for backup. First you have to make route to the host that will be used to check whether the line have connection or not. For this example we'll use Google DNS as the host (8.8.8.8).
The main route gateway is 172.16.0.1 on interface ether1
The Backup route gateway is 172.16.1.1 on interface ether2

/ip route
add check-gateway=ping distance=1 dst-address=8.8.8.8/32 gateway=172.16.0.1
add check-gateway=ping distance=1 gateway=172.16.0.1 comment=MainRoute
add check-gateway=ping distance=2 gateway=172.16.1.1 comment=BackupRoute

- Then we make a script, click Sytem then Scripts in winbox. Click plus sign (+) to make new script. For this example we just leave the name as script1, copy paste these scripts below into the source box :

:if ([/ping 8.8.8.8 interface=ether1 interval=1 count=10] = 0) do={
:log error "Host 8.8.8.8 is not responding to ping request, Change Route Distance ..."
/ip route set distance=3 [find comment="MainRoute"]
} else {
:log warning "Host 8.8.8.8 is responding to ping request, no action required "
/ip route set distance=1 [find comment="MainRoute"]
}

- Finally make schedule for the script to run every 30 seconds, like picture below :


No comments:

Post a Comment