What's new

Dual WAN failover - network monitoring option checkbox

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Simon W

Regular Contributor
Playing around the Dual WAN failover for the first time.. seems confusing the two network monitoring options are checkboxes - I'd expect it to be one or the other?

Either neither are checked (default) = how does failover ever work? Is there something else?
If one is checked = seems to work
If both are checked = would both need to fail to invoke failover? (hard to test without quite a bit of setup)
 
Don't waste your time, doesn't work reliably with WAN + LAN. May or may not failover/failback, unless you physically unplug the cables.
 
The built in failover options are not worth a crap, I enabled Dual WAN and created a couple scripts that execute every minute via cronjob and will monitor for a failure event and switch WAN if necessary. May require some tweaking in your set up but it works for me.

WAN Failover script to monitor and switch to secondary.
Code:
#!/bin/sh

# Cause the script to exit if errors are encountered
set -e
set -u

# Checking if script is already running
  echo "Checking if $0 is already running..."
if [[ "$(echo $(ps | grep -v "grep" | grep -e "$0" | wc -l))" -gt "5" ]] >/dev/null; then
  echo "$0 is already running..."
else

# Checking if Secondary WAN is active connection
  echo "Checking if Secondary WAN is active connection..."
if [[ "$(nvram get wan0_primary)" == "0" ]] & [[ "$(nvram get wan1_primary)" == "1" ]] >/dev/null;then
  echo "Secondary WAN is active connection."
else
  echo "Monitoring Primary WAN for failure..."
until [[ "$(echo $(nvram get wan0_gateway))" == "192.168.1.254" ]] || [[ "$(echo $(nvram get wan0_gateway))" == "0.0.0.0" ]] || [[ "$(echo $(ping $(nvram get wan0_gateway) -c 4) | grep -o "4 packets transmitted, 4 packets received")" != "4 packets transmitted, 4 packets received" ]] >/dev/null;do
  echo "$(echo $(date | awk '{print $2} {print $3} {print $6} {print $4}')) - Primary WAN Online..." >/dev/null
sleep 3
done
  echo "Switching Secondary WAN to active connection..."
until [[ "$(echo $(nvram get wan0_primary))" == "0" ]] & [[ "$(echo $(nvram get wan1_primary))" == "1" ]] & [[ "$(echo $(ip route show default | awk '{print $3}'))" == "$(echo $(nvram get wan1_gateway))" ]] >/dev/null;do
nvram set wan1_primary=1 && nvram set wan0_primary=0
ip route del default
ip route add default via $(nvram get wan1_gateway) dev $(nvram get wan1_gw_ifname)
done
  echo "Secondary WAN is now active connection."
fi
fi

WAN Failback script to monitor when Primary WAN comes back online and switches back.
Code:
#!/bin/sh

# Cause the script to exit if errors are encountered
set -e
set -u

# Checking if script is already running
  echo "Checking if $0 is already running..."
if [[ "$(echo $(ps | grep -v "grep" | grep -o "$0" | wc -l))" -gt "5" ]] >/dev/null; then
  echo "$0 is already running..."
else

# Checking if Primary WAN is active connection
  echo "Checking if Primary WAN is active connection..."
if [[ "$(nvram get wan0_primary)" == "1" ]] >/dev/null;then
  echo "Primary WAN is active connection."
else
  echo "Monitoring Primary WAN for restoration..."
while [[ "$(echo $(ping $(nvram get wan0_gateway) -c 4) | grep -o "4 packets transmitted, 4 packets received")" != "4 packets transmitted, 4 packets received" ]] || [[ "$(echo $(nvram get wan0_gateway))" == "192.168.1.254" ]] || [[ "$(echo $(nvram get wan0_gateway))" == "0.0.0.0" ]] >/dev/null;do
  echo "$(echo $(date | awk '{print $2} {print $3} {print $6} {print $4}')) - Primary WAN Offline..." >/dev/null
sleep 3
done
if [[ "$(echo $(ping $(nvram get wan0_gateway) -c 4) | grep -o "4 packets transmitted, 4 packets received")" = "4 packets transmitted, 4 packets received" ]] >/dev/null;then
  echo "Primary WAN is online..."
  echo "Switching Primary WAN to active connection..."
until [[ "$(echo $(nvram get wan0_primary))" == "1" ]] & [[ "$(echo $(nvram get wan1_primary))" == "0" ]] & [[ "$(echo $(ip route show default | awk '{print $3}'))" == "$(echo $(nvram get wan0_gateway))" ]] >/dev/null;do
nvram set wan0_primary=1 && nvram set wan1_primary=0
ip route del default
ip route add default via $(nvram get wan0_gateway) dev $(nvram get wan0_gw_ifname)
done
  echo "Primary WAN is now active connection."
else
  echo "Primary WAN is not online..."
fi
fi
fi
 
Last edited:
Playing around the Dual WAN failover for the first time.. seems confusing the two network monitoring options are checkboxes - I'd expect it to be one or the other?

Either neither are checked (default) = how does failover ever work? Is there something else?
If one is checked = seems to work
If both are checked = would both need to fail to invoke failover? (hard to test without quite a bi
The built in failover options are not worth a crap, I enabled Dual WAN and created a couple scripts that execute every minute via cronjob and will monitor for a failure event and switch WAN if necessary. May require some tweaking in your set up but it works for me.

WAN Failover script to monitor and switch to secondary.
Code:
#!/bin/sh

# Cause the script to exit if errors are encountered
set -e
set -u

# Checking if script is already running
  echo "Checking if $0 is already running..."
if [[ "$(echo $(ps | grep -v "grep" | grep -e "$0" | wc -l))" -gt "5" ]] >/dev/null; then
  echo "$0 is already running..."
else

# Checking if Secondary WAN is active connection
  echo "Checking if Secondary WAN is active connection..."
if [[ "$(nvram get wan0_primary)" == "0" ]] & [[ "$(nvram get wan1_primary)" == "1" ]] >/dev/null;then
  echo "Secondary WAN is active connection."
else
  echo "Monitoring Primary WAN for failure..."
until [[ "$(echo $(nvram get wan0_gateway))" == "192.168.1.254" ]] || [[ "$(echo $(nvram get wan0_gateway))" == "0.0.0.0" ]] || [[ "$(echo $(ping $(nvram get wan0_gateway) -c 4) | grep -o "4 packets transmitted, 4 packets received")" != "4 packets transmitted, 4 packets received" ]] >/dev/null;do
  echo "$(echo $(date | awk '{print $2} {print $3} {print $6} {print $4}')) - Primary WAN Online..." >/dev/null
sleep 3
done
  echo "Switching Secondary WAN to active connection..."
until [[ "$(echo $(nvram get wan0_primary))" == "0" ]] & [[ "$(echo $(nvram get wan1_primary))" == "1" ]] & [[ "$(echo $(ip route show default | awk '{print $3}'))" == "$(echo $(nvram get wan1_gateway))" ]] >/dev/null;do
nvram set wan1_primary=1 && nvram set wan0_primary=0
ip route del default
ip route add default via $(nvram get wan1_gateway) dev $(nvram get wan1_gw_ifname)
done
  echo "Secondary WAN is now active connection."
fi
fi

WAN Failback script to monitor when Primary WAN comes back online and switches back.
Code:
#!/bin/sh

# Cause the script to exit if errors are encountered
set -e
set -u

# Checking if script is already running
  echo "Checking if $0 is already running..."
if [[ "$(echo $(ps | grep -v "grep" | grep -o "$0" | wc -l))" -gt "5" ]] >/dev/null; then
  echo "$0 is already running..."
else

# Checking if Primary WAN is active connection
  echo "Checking if Primary WAN is active connection..."
if [[ "$(nvram get wan0_primary)" == "1" ]] >/dev/null;then
  echo "Primary WAN is active connection."
else
  echo "Monitoring Primary WAN for restoration..."
while [[ "$(echo $(ping $(nvram get wan0_gateway) -c 4) | grep -o "4 packets transmitted, 4 packets received")" != "4 packets transmitted, 4 packets received" ]] || [[ "$(echo $(nvram get wan0_gateway))" == "192.168.1.254" ]] || [[ "$(echo $(nvram get wan0_gateway))" == "0.0.0.0" ]] >/dev/null;do
  echo "$(echo $(date | awk '{print $2} {print $3} {print $6} {print $4}')) - Primary WAN Offline..." >/dev/null
sleep 3
done
if [[ "$(echo $(ping $(nvram get wan0_gateway) -c 4) | grep -o "4 packets transmitted, 4 packets received")" = "4 packets transmitted, 4 packets received" ]] >/dev/null;then
  echo "Primary WAN is online..."
  echo "Switching Primary WAN to active connection..."
until [[ "$(echo $(nvram get wan0_primary))" == "1" ]] & [[ "$(echo $(nvram get wan1_primary))" == "0" ]] & [[ "$(echo $(ip route show default | awk '{print $3}'))" == "$(echo $(nvram get wan0_gateway))" ]] >/dev/null;do
nvram set wan0_primary=1 && nvram set wan1_primary=0
ip route del default
ip route add default via $(nvram get wan0_gateway) dev $(nvram get wan0_gw_ifname)
done
  echo "Primary WAN is now active connection."
else
  echo "Primary WAN is not online..."
fi
fi
fi

I created an all new script and posted here: https://www.snbforums.com/threads/dual-wan-failover-script.78978/
 
See updated post about my script here:

 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top