Answer the question
In order to leave comments, you need to log in
two providers. How to check a previously dropped channel with a script?
Hello.
For some reason, the failover implementation is needed through a script. I saw several scripts, I took one of them, slightly modifying it:
:local MainIf "ether1";
:local RsrvIf "ether5";
:local PingCount 5;
:local PingTargets {78.88.8.8; 87.250.250.203; 8.8.8.8};
:local MainIfInetOk false;
:local RsrvIfInetOk false;
:local MainPings 0;
:local RsrvPings 0;
:local mikroName [/system identity get name];
:local mikroDate [/system clock get date];
:local mikroTime [/system clock get time];
:log info ("== START PING to $PingTargets ==");
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);
}
:log info ("== Main pings success: $MainPings ==");
:log info ("== Rsrv pings success: $RsrvPings ==");
:set MainIfInetOk ($MainPings >= 10);
:set RsrvIfInetOk ($RsrvPings >= 10);
:local MainGWDistance [/ip route get [find comment="ISP1"] distance];
:local RsrvGWDistance [/ip route get [find comment="ISP2"] distance];
if ($MainIfInetOk && ($MainGWDistance >= $RsrvGWDistance)) do={
/ip route set [find comment="ISP1"] distance=1;
/ip route set [find comment="ISP2"] distance=2;
foreach i in=[/ip firewall connection find dst-address~":1723"] do={/ip firewall connection remove $i};
/tool e-mail send from="[email protected]" server=10.10.10.10 to="[email protected]" \
body=("$mikroName switched to _PRIMARY_ ISP at ($mikroDate in $mikroTime)") subject="Mikrotik: $mikroName INTERNET MAIN UP";
/log info ">>> Switched to main internet connection";
}
if (!$MainIfInetOk && $RsrvIfInetOk && ($MainGWDistance <= $RsrvGWDistance)) do={
/ip route set [find comment="ISP1"] distance=2;
/ip route set [find comment="ISP2"] distance=1;
foreach i in=[/ip firewall connection find dst-address~":1723"] do={/ip firewall connection remove $i};
/tool e-mail send from="[email protected]" server=10.10.10.10 to="[email protected]" \
body=("$mikroName switched to _SECONDARY_ ISP at ($mikroDate in $mikroTime)") subject="Mikrotik: $mikroName INTERNET MAIN DOWN";
/log info ">>> Switched to reserved internet connection";
}
:log info ("== DUAL ISP script end ==");
/ip route
add comment=ISP1 distance=1 gateway=IP_GW1
add comment=ISP2 distance=2 gateway=IP_GW2
interface (string; Default: ) Which interface to use (required when pinging IPv6 address)
Answer the question
In order to leave comments, you need to log in
The interface option does not work with ipv4. And with ipv6 it doesn't do what you want.
As a parameter to ping, you must specify a routing-table and have routes through gateways 1 and 2 of the provider, respectively, marked with the corresponding route labels.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question