Hi Guys,
I hope somebody can point me in the right direction.
I have a Mikrotik Router with a cable modem attached to it which has been working flawlessly for some time. Now I bought myself a TP-Link LTE Router (that I actually just want to use as a modem) and configure WAN failover.
The “Wan” Port (ether1-gateway) is connected to my cable modem. What do I have to configure to make WAN failover (and automatic reverting to “ISP1”) possible. I have seen a couple of scripts, but to be honest I don’t quite get it. Maybe somebody can give me a helping hand?
Thanks in advance.
Christian
Hi Chris, I have a remote setup that has 2 providers, one is a lte connection from a cradlepoint. I want my system to fail over in the event that my primary goes down so we are on the same track. Here is my working failover setup, you will need to adjust interface names and gateway addresses and then paste into a terminal or ssh session.
My interfaces are ether1-WAN and ether2-WAN and the gateways are 10.0.0.1 and 172.16.0.1 for this example.
The only caveat is that it doesn’t move back to the primary when that interface becomes available. You will need to got to IP > Routes and set the distance back to 1 for your primary connection. I was on here searching for help when I ran across your question. I will be making a post about my problem and hopefully someone can help me and then I can pass it on.
/ip firewall mangle
add action=mark-connection chain=input in-interface=ether1-WAN
new-connection-mark=isp1-in
add action=mark-routing chain=output connection-mark=isp1-in
new-routing-mark=isp1-out passthrough=no
add action=mark-connection chain=input in-interface=ether2-WAN
new-connection-mark=isp2-in
add action=mark-routing chain=output connection-mark=isp2-in
new-routing-mark=isp2-out passthrough=no
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether1-WAN
add action=masquerade chain=srcnat out-interface=ether2-WAN
/ip route
add distance=1 gateway=10.0.0.1 routing-mark=isp1-out
add distance=2 gateway=172.16.0.1 routing-mark=isp2-out
add distance=2 gateway=172.16.0.1
add distance=1 gateway=10.0.0.1
/system scheduler
add interval=10s name=DualWanFailover on-event=DualWanFailover policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=
nov/18/2015 start-time=21:51:02
/system script
add name=DualWanFailover owner=admin policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive source=“# ----
--------------- header -------------------
\n# Script by Tomas Kirnak, version 1.0.7
\n# If you use this script, or edit and
\n# re-use it, please keep the header intact.
\n#
\n# For more information and details about
\n# this script please visit the wiki page at
\n# http://wiki.mikrotik.com/wiki/Failover_Scripting\
\n# ------------------- header -------------------
\n
\n
\n
\n# ------------- start editing here -------------
\n# Edit the variables below to suit your needs
\n
\n# Please fill the WAN interface names
\n:local InterfaceISP1 ether1-WAN
\n:local InterfaceISP2 ether2-WAN
\n
\n# Please fill the gateway IPs (or interface names in case of PPP)
\n:local GatewayISP1 10.0.0.1
\n:local GatewayISP2 172.16.0.1
\n
\n# Please fill the ping check host - currently: resolver1.opendns.com
\n:local PingTarget 208.67.222.222
\n
\n# Please fill how many ping failures are allowed before fail-over happe
nds
\n:local FailTreshold 20
\n
\n# Define the distance increase of a route when it fails
\n:local DistanceIncrease 2
\n
\n# Editing the script after this point may break it
\n# -------------- stop editing here --------------
\n
\n
\n
\n# Declare the global variables
\n:global PingFailCountISP1
\n:global PingFailCountISP2
\n
\n# This inicializes the PingFailCount variables, in case this is the 1st
_time the script has ran
\n:if ([:typeof $PingFailCountISP1] = "nothing") do={:set PingFailCoun
tISP1 0}
\n:if ([:typeof $PingFailCountISP2] = "nothing") do={:set PingFailCoun
tISP2 0}
\n
\n# This variable will be used to keep results of individual ping attempt
s
\n:local PingResult
\n
\n
\n
\n# Check ISP1
\n:set PingResult [ping $PingTarget count=1 interface=$InterfaceISP1]
\n:put $PingResult
\n
\n:if ($PingResult = 0) do={
\n\t:if ($PingFailCountISP1 < ($FailTreshold+2)) do={
\n\t\t:set PingFailCountISP1 ($PingFailCountISP1 + 1)
\n\t\t
\n\t\t:if ($PingFailCountISP1 = $FailTreshold) do={
\n\t\t\t:log warning "ISP1 has a problem en route to $PingTarget - incr
easing distance of routes."
\n\t\t\t:foreach i in=[/ip route find gateway=$GatewayISP1 && static] do
=\
\n\t\t\t\t{/ip route set $i distance=([/ip route get $i distance] + $D
istanceIncrease)}
\n\t\t\t:log warning "Route distance increase finished."
\n\t\t}
\n\t}
\n}
\n:if ($PingResult = 1) do={
\n\t:if ($PingFailCountISP1 > 0) do={
\n\t\t:set PingFailCountISP1 ($PingFailCountISP1 - 1)
\n\t\t
\n\t\t:if ($PingFailCountISP1 = ($FailTreshold -1)) do={
\n\t\t\t:log warning "ISP1 can reach $PingTarget again - bringing back
original distance of routes."
\n\t\t\t:foreach i in=[/ip route find gateway=$GatewayISP1 && static] do
=\
\n\t\t\t\t{/ip route set $i distance=([/ip route get $i distance] - $D
istanceIncrease)}
\n\t\t\t:log warning "Route distance decrease finished."
\n\t\t}
\n\t}
\n}
\n
\n
\n
\n# Check ISP2
\n:set PingResult [ping $PingTarget count=1 interface=$InterfaceISP2]
\n:put $PingResult
\n
\n:if ($PingResult = 0) do={
\n\t:if ($PingFailCountISP2 < ($FailTreshold+2)) do={
\n\t\t:set PingFailCountISP2 ($PingFailCountISP2 + 1)
\n\t\t
\n\t\t:if ($PingFailCountISP2 = $FailTreshold) do={
\n\t\t\t:log warning "ISP2 has a problem en route to $PingTarget - incr
easing distance of routes."
\n\t\t\t:foreach i in=[/ip route find gateway=$GatewayISP2 && static] do
=\
\n\t\t\t\t{/ip route set $i distance=([/ip route get $i distance] + $D
istanceIncrease)}
\n\t\t\t:log warning "Route distance increase finished."
\n\t\t}
\n\t}
\n}
\n:if ($PingResult = 1) do={
\n\t:if ($PingFailCountISP2 > 0) do={
\n\t\t:set PingFailCountISP2 ($PingFailCountISP2 - 1)
\n\t\t
\n\t\t:if ($PingFailCountISP2 = ($FailTreshold -1)) do={
\n\t\t\t:log warning "ISP2 can reach $PingTarget again - bringing back
original distance of routes."
\n\t\t\t:foreach i in=[/ip route find gateway=$GatewayISP2 && static] do
=\
\n\t\t\t\t{/ip route set $i distance=([/ip route get $i distance] - $D
istanceIncrease)}
\n\t\t\t:log warning "Route distance decrease finished."
\n\t\t}
\n\t}
\n}”
/
Thanks a lot! I will try the script you posted!
Chris just fyi its not mine… I got it from http://wiki.mikrotik.com/wiki/Failover_Scripting and it half way works.