Skip to content

Instantly share code, notes, and snippets.

@mcspx
Forked from heri16/Netwatch.rsc
Created December 21, 2020 18:01
Show Gist options
  • Select an option

  • Save mcspx/b99a83090def2e85067672b6fc456318 to your computer and use it in GitHub Desktop.

Select an option

Save mcspx/b99a83090def2e85067672b6fc456318 to your computer and use it in GitHub Desktop.
Mikrotik RouterOS script for Ping-based Fast Failover with PPPoE uplinks.
/interface pppoe-client
set [find name="internet-speedy"] comment="PROVIDER1"
set [find name="internet-biznet"] comment="PROVIDER2"
/ip route
add comment="Force test pings through PROVIDER1" distance=1 dst-address=4.2.2.4/32 gateway=internet-speedy
add comment="Block test pings through other providers" distance=20 dst-address=4.2.2.4/32 type=blackhole
/tool netwatch
add comment=CheckCon down-script=":local \"p1\" [/interface pppoe-client find c\
omment=\"PROVIDER1\" default-route-distance!=20];\r\
\n/interface pppoe-client disable \$p1;\r\
\n:delay 500ms;\r\
\n/interface disable [find name=[/interface pppoe-client get \$p1 interface]\
];\r\
\n/interface enable [find name=[/interface pppoe-client get \$p1 interface]]\
;\r\
\n/interface pppoe-client set \$p1 default-route-distance=20 disabled=no;\r\
\n/interface pppoe-client set [find comment=\"PROVIDER2\" disabled=yes] disa\
bled=no;\r\
\n/tool e-mail send to=\"YourEmailAddress\" body=\"Uplink with PROVIDER1 Los\
t, Switched to PROVIDER2\" subject=\"Lost uplink with PROVIDER1\";\r\
\n#/ip firewall connection remove [find dst-address!=\"10.0.0.0/8\"];\r\
\n" host=4.2.2.4 interval=5s timeout=2s up-script=":local \"p1\" [/interfac\
e pppoe-client find comment=\"PROVIDER1\" default-route-distance!=1];\r\
\n:if ([:len \$p1] > 0) do={\r\
\n :local \"p1Status\";\r\
\n /tool netwatch disable [find comment=\"CheckCon\"];\r\
\n /interface pppoe-client disable \$p1;\r\
\n :delay 500ms;\r\
\n /interface disable [find name=[/interface pppoe-client get \$p1 interfac\
e]];\r\
\n /interface enable [find name=[/interface pppoe-client get \$p1 interface\
]];\r\
\n /interface pppoe-client set \$p1 default-route-distance=1 disabled=no;\r\
\n :do {\r\
\n :delay 500ms;\r\
\n /interface pppoe-client monitor \$p1 once do={ :set \"p1Status\" \$sta\
tus };\r\
\n } while=(\$p1Status != \"connected\");\r\
\n\r\
\n :local \"pingResult\";\r\
\n do {\r\
\n :set \"pingResult\" [/ping address=4.2.2.4 count=1 interval=5s];\r\
\n } while=(\$pingResult != 1);\r\
\n /tool netwatch enable [find comment=\"CheckCon\"];\r\
\n\r\
\n /interface pppoe-client set [find comment=\"PROVIDER2\" disabled=yes] di\
sabled=no;\r\
\n /tool e-mail send to=\"YourEmailAddress\" body=\"Uplink with PROVIDER1 R\
egained, Switched back to PROVIDER1\" subject=\"Regained uplink with PROVIDE\
R1\";\r\
\n #/ip firewall connection remove [find dst-address!=\"10.0.0.0/8\"];\r\
\n}\r\
\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment