Backgound: A remote site of mine has two connections
Connection 1: Att Uverse DSL
Connection 2: Verizon LTE service on cradlepoint in bridge mode.
IP’s have been change for privacy reasons.
Because the uverse can’t be put into bridge mode we had to configure it with the public statics on it’s lan side and turn on cascading router. This option gives is our /29 to use but also breaks the check gateway because the gateway is always up even if we have a provider cut. The lte gateways is far off the device so it would work as expected but I don’t want it to be a provider unless the primary has gone down.
I have setup mangle rules to tag traffic so the come in and out on the same provider and found a wan failover script on the wiki that sorta works.
If I am on the primary I can select ping and choose an interface and pings are normal times, if I select the secondary interface the pings are long like they should be on a lte connection.
Script runs every 10 seconds and will fail over to the secondary when it fails but will not bring up the primary once its restored. Once it’s failed over I can no longer ping out the primary interface so the ping are not restored and the script doesn’t return the distance on the gateways.
Can someone help me correct this issue?
/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}”