Скрипт переключения
#Main interface name
:global MainIf ether1
#Failover interface name
:global RsrvIf ether2
:local PingCount 1
:local PingTargets {
213.180.193.3;
77.88.8.8;
8.8.8.8;
217.69.139.202}
:local host
:local MainIfInetOk false
:local RsrvIfInetOk false
:local MainPings 0
:local RsrvPings 0
foreach host in=$PingTargets do={
:local res [/ping $host count=$PingCount interface=$MainIf]
:set MainPings ($MainPings + $res)
:local res [/ping $host count=$PingCount interface=$RsrvIf]
:set RsrvPings ($RsrvPings + $res)
:delay 1
}
:set MainIfInetOk ($MainPings >= 1)
:set RsrvIfInetOk ($RsrvPings >= 1)
:put "MainIfInetOk=$MainIfInetOk"
:put "RsrvIfInetOk=$RsrvIfInetOk"
:local MainGWDistance [/ip route get [find comment="WAN1"] distance]
:local RsrvGWDistance [/ip route get [find comment="WAN2"] distance]
:put "MainGWDistance=$MainGWDistance"
:put "RsrvGWDistance=$RsrvGWDistance"
if ($MainIfInetOk && ($MainGWDistance >= $RsrvGWDistance)) do={
/ip route set [find comment="WAN1"] distance=1
/ip route set [find comment="WAN2"] distance=2
:put "switched to main internet connection"
/log info "switched to main internet connection"
}
if (!$MainIfInetOk && $RsrvIfInetOk && ($MainGWDistance <=>
}
Рекурсивные маршруты
/ip route
add dst-address=
8.8.8.8 gateway=
1.1.1.1 scope=10
add dst-address=
78.88.8.1 gateway=
1.1.1.1 scope=10
add dst-address=
78.88.8.8 gateway=
2.2.2.2 scope=10
add dst-address=
8.8.4.4 gateway=
2.2.2.2 scope=10
/ip route
add dst-address=
10.1.1.1 gateway=
8.8.8.8 scope=10 target-scope=10 check-gateway=ping
add dst-address=
10.1.1.1 gateway=
78.88.8.1 scope=10 target-scope=10 check-gateway=ping
add dst-address=
10.2.2.2 gateway=
78.88.8.8 scope=10 target-scope=10 check-gateway=ping
add dst-address=
10.2.2.2 gateway=
8.8.4.4 scope=10 target-scope=10 check-gateway=ping
/ip route
add distance=1 gateway=
10.1.1.1 add distance=2 gateway=
10.2.2.2 add distance=1 gateway=
10.2.2.2 add distance=2 gateway=
10.1.1.1