I am currently looking into 4G failover with a simple script, no load-balancing,
I was able to get the below working if I removed the dynamic default route for pppoe and set a static route referenced with “ISP1” routing-mark.
This is also a lot more reliable than recursive routes which is why I prefer this option.
Ran into some problems with a static default route and have come up with a solution, but don’t know how to script it.
Current script (Works perfectly, but this specific site stalled after 24 hours when using a static default route):
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=0))};
:if ($i=5 && [/ip route get [find routing-mark=“ISP1”] distance]=1) do={:log info “Main Gateway down”;
/ip route set [find routing-mark=“ISP1”] distance=3}
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=1))};
:if ($i=5 && [/ip route get [find routing-mark=“ISP1”] distance]=3) do={:log info “Main Gateway up”;
/ip route set [find routing-mark=“ISP1”] distance=1}
Functionality required for new script (Setting default-route-distance works by itself, but the query/if statement does not):
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=0))};
:if ($i=5 && [/interface pppoe-client get [find “GATEWAY” default-route-distance] default-route-distance]=1) do={:log info “Main Gateway down”;
/interface pppoe-client set [find “GATEWAY” default-route-distance] distance=3}
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=1))};
:if ($i=5 && [/interface pppoe-client get [find “GATEWAY” default-route-distance] default-route-distance=3) do={:log info “Main Gateway up”;
/interface pppoe-client set [find “GATEWAY” default-route-distance] default-route-distance=1}
Please let me know if you need any further information.
Sorry Adahi,
This is in regards to failover, different distance only fails over if the port on the physical Mikrotik goes down. Which is unlikely to happen.
I have tried every option on the Mikrotik forums, and would prefer not to use a script, but the other options do not work.
This is the only script I have found which meets all criteria we have had problems with:
Physical cable down on Mikrotik
Physical DSL cable on modem down
Ping stops working to specific device
Gateway down
There were some other cases which I cannot remember either.
Routes will not help you solve my original question.
I posted this in the scripting section as I just want to know how to reference pppoe-client with a “Find default-route-distance” command.
This line is incorrect and I do not know how to reference the pppoe-client default-route-distance via script: [/interface pppoe-client get [find “GATEWAY” default-route-distance] default-route-distance]=1)
I do not want any other failover solution etc as the below is the only out of the four failover solutions that worked perfectly, I would like to complete the script though.
I want this:
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=0))};
:if ($i=5 && [/ip route get [find routing-mark=“ISP1”] distance]=1) do={:log info “Main Gateway down”;
/ip route set [find routing-mark=“ISP1”] distance=3}
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=1))};
:if ($i=5 && [/ip route get [find routing-mark=“ISP1”] distance]=3) do={:log info “Main Gateway up”;
/ip route set [find routing-mark=“ISP1”] distance=1}
To become something like this:
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=0))};
:if ($i=5 && [/interface pppoe-client get [find “GATEWAY” default-route-distance] default-route-distance]=1) do={:log info “Main Gateway down”;
/interface pppoe-client set [find “GATEWAY” default-route-distance] distance=3}
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.4.4 interval=3 count=1]=1))};
:if ($i=5 && [/interface pppoe-client get [find “GATEWAY” default-route-distance] default-route-distance=3) do={:log info “Main Gateway up”;
/interface pppoe-client set [find “GATEWAY” default-route-distance] default-route-distance=1}
I was able to resolve and now have a completed and functional script which works perfectly for all failover scenarios.
This changes the pppoe-client which is much more reliable than modifying a static route in the routing table.
Please see below if you are interested, note that your Primary link must be called “WAN” with a default-route distance of “1”, your secondary link should have a default-route-distance of “2”:
“check-primary-link” script =
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping interface=WAN 8.8.4.4 interval=3 count=1]=0))};
:if ($i=5 && [/interface pppoe-client get WAN default-route-distance]=1) do={:log info “Main Gateway down”;
/interface pppoe-client set WAN default-route-distance=3}
“fallback-to-primary-link” script =
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping interface=WAN 8.8.4.4 interval=3 count=1]=1))};
:if ($i=5 && [/interface pppoe-client get WAN default-route-distance]=3) do={:log info “Main Gateway Up”;
/interface pppoe-client set WAN default-route-distance=1}
add interval=1m name=schedule1 on-event=“/system script run check-primary-link\r
\n/system script run fallback-to-primary-link” policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
start-date=jan/03/2018 start-time=22:18:02