What's new

WANFailover Dual WAN Failover Script

  • 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!

Ranger802004

Very Senior Member
WAN Failover is designed to replace the factory ASUS WAN Failover functionality, this script will monitor the WAN Interfaces using a Target IP Address and pinging these targets to determine when a failure occurs. When a failure is detected in Failover Mode, the script will switch to the Secondary WAN interface automatically and then monitor for failback conditions. When the Primary WAN interface connection is restored based on the Target IP Address, the script will perform the failback condition and switch back to Primary WAN. When a failure is detected in Load Balancing Mode, the script will remove the down WAN interface from Load Balancing and restore it when it is active again.

Requirements:
- ASUS Merlin Firmware v386.5 or higher
- JFFS custom scripts and configs Enabled
- Dual WAN Enabled
- ASUS Factory Failover Disabled (Network Monitoring Options, Allow Failback Option under WAN > Dual WAN)

Installation:
Code:
/usr/sbin/curl -s "https://raw.githubusercontent.com/Ranger802004/asusmerlin/main/wan-failover.sh" -o "/jffs/scripts/wan-failover.sh" && chmod 755 /jffs/scripts/wan-failover.sh && sh /jffs/scripts/wan-failover.sh install

Updating:
Code:
/jffs/scripts/wan-failover.sh update

Uninstallation:
Code:
/jffs/scripts/wan-failover.sh uninstall

Link to Script:
https://raw.githubusercontent.com/Ranger802004/asusmerlin/main/wan-failover.sh

Readme:
https://raw.githubusercontent.com/Ranger802004/asusmerlin/main/wan-failover-readme.txt

Release Notes:
***View the Readme***
 
Last edited:
Hello guys, I have attached a script I wrote to replace the built in Failover function from ASUS that is awful. Please let me know if you have any suggestions or questions, thank you. You can set this to run in the background with a cron job or let another script start it like wan-event, also you will see there are several variables you can set from within the script.
 
Ill mess with this later, but apparently its failing with the ping command, probably this though
wan0_dns=1.1.1.1 8.8.8.8
wan0_dns1_x=
wan0_dns2_x=


admin@RT-AX86U-D7D0:/jffs/scripts# ./wanup
Checking if ./wanup is already running...
BusyBox v1.25.1 (2022-03-25 10:23:25 EDT) multi-call binary.

Usage: ping [OPTIONS] HOST

Send ICMP ECHO_REQUEST packets to network hosts

-4,-6 Force IP or IPv6 name resolution
-c CNT Send only CNT pings
-s SIZE Send SIZE data bytes in packets (default:56)
-t TTL Set TTL
-I IFACE/IP Use interface or IP address as source
-M hint Path MTU Discovery strategy [do|want|dont]
-W SEC Seconds to wait for the first response (default:10)
(after all -c CNT packets are sent)
-w SEC Seconds until ping exits (default:infinite)
(can exit earlier with -c CNT)
-q Quiet, only display output at start
and when finished
-p Pattern to use for payload
 
Last edited:
Ill mess with this later, but apparently its failing with the ping command, probably this though
wan0_dns=1.1.1.1 8.8.8.8
wan0_dns1_x=
wan0_dns2_x=


admin@RT-AX86U-D7D0:/jffs/scripts# ./wanup
Checking if ./wanup is already running...
BusyBox v1.25.1 (2022-03-25 10:23:25 EDT) multi-call binary.

Usage: ping [OPTIONS] HOST

Send ICMP ECHO_REQUEST packets to network hosts

-4,-6 Force IP or IPv6 name resolution
-c CNT Send only CNT pings
-s SIZE Send SIZE data bytes in packets (default:56)
-t TTL Set TTL
-I IFACE/IP Use interface or IP address as source
-M hint Path MTU Discovery strategy [do|want|dont]
-W SEC Seconds to wait for the first response (default:10)
(after all -c CNT packets are sent)
-w SEC Seconds until ping exits (default:infinite)
(can exit earlier with -c CNT)
-q Quiet, only display output at start
and when finished
-p Pattern to use for payload
You can change those but whatever IP you pick for each WAN you will need to have a route made for it. DNS servers and gateway already are routed for you over each WAN interface. Also the variables to set are…
WAN0TARGET=
WAN1TARGET=
 
You can change those but whatever IP you pick for each WAN you will need to have a route made for it. DNS servers and gateway already are routed for you over each WAN interface. Also the variables to set are…
WAN0TARGET=
WAN1TARGET=
Guess I dont understand, your pinging wan0_dns1_x= for the check, but mine is empty, for wan0 and wan1, so these need set outsite the script?
 
Last edited:
Guess I dont understand, your pinging wan0_dns1_x= for the check, but mine is empty, for wan0 and wan1, so these need set outsite the script?
In the script there is a section for variables to change which you will want to do for your QoS Settings as well.

Look for :
Code:
WAN0TARGET="$(nvram get wan0_dns1_x)"
Change to:
Code:
WAN0TARGET="$(nvram get wan0_dns | awk '{print $1}')"
 
In the script there is a section for variables to change which you will want to do for your QoS Settings as well.

Look for :
Code:
WAN0TARGET="$(nvram get wan0_dns1_x)"
Change to:
Code:
WAN0TARGET="$(nvram get wan0_dns | awk '{print $1}')"
Played with it some this mornign, once I made it check the right dns, seems to be working. Fyi, my secondary wan always comes up in Cold Standby. The script doesnt seem to make it go into to hot
standby. I just added service "restart_wan_if 1" to beginning, which makes it hot.
 
Played with it some this mornign, once I made it check the right dns, seems to be working. Fyi, my secondary wan always comes up in Cold Standby. The script doesnt seem to make it go into to hot
standby. I just added service "restart_wan_if 1" to beginning, which makes it hot.
Interesting, I’ll look into that as a check and adding a function for next version.
 
Interesting, I’ll look into that as a check and adding a function for next version.
We must have something different on our routers, I have a AX86u running latest merlin version. I just switched the wc from 5 to 1, and then it always thinks the script is running. I had it pop up a grep error also while running, but havent been able to mess with it since. Just giving you my issues, not complaining at all. ty
 
We must have something different on our routers, I have a AX86u running latest merlin version. I just switched the wc from 5 to 1, and then it always thinks the script is running. I had it pop up a grep error also while running, but havent been able to mess with it since. Just giving you my issues, not complaining at all. ty
Yea it will do that if you try and run it manually in console unless you increase that number. What was the grep error you received? No worries, I figured other models would have various things come up differently than my environment.
 
Yea it will do that if you try and run it manually in console unless you increase that number. What was the grep error you received? No worries, I figured other models would have various things come up differently than my environment.
 
This is when it was switching after I killed my primary line. i fixed the wan-event issue.

##############

Checking if ./wanup is already running...
Switching to wan1
grep: option requires an argument -- 'e'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.

Done.

Done.

Done.

Done.
./wanup: line 310: /jffs/scripts/wan-event: not found
 
This is when it was switching after I killed my primary line. i fixed the wan-event issue.

##############

Checking if ./wanup is already running...
Switching to wan1
grep: option requires an argument -- 'e'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.

Done.

Done.

Done.

Done.
./wanup: line 310: /jffs/scripts/wan-event: not found
Ah yes, if you don’t have a wan-event script made it will error out, I will make a check for that on next release, a little oversight.
 
Ah yes, if you don’t have a wan-event script made it will error out, I will make a check for that on next release, a little oversight.
You think thats what the grep issue was also? Something I can add, but if your working on this. Something handy sending a email when failover kicks in would be nice, somewhere on this forum I wrote a uptime script
that would email, but you can also email your cellular provider and it will send you a text.
 
You think thats what the grep issue was also? Something I can add, but if your working on this. Something handy sending a email when failover kicks in would be nice, somewhere on this forum I wrote a uptime script
that would email, but you can also email your cellular provider and it will send you a text.
I actually have my custom version emailing me, but I didn’t include that in my public version. The grep error is coming from trying to grep without a - parameter, did you add or edit any of the grep commands?
 
I actually have my custom version emailing me, but I didn’t include that in my public version. The grep error is coming from trying to grep without a - parameter, did you add or edit any of the grep commands?
I did not change anything but the WAN0TARGET= , and added the
service "restart_wan_if 1", I will probably add a option to change qos or not to variable. But thats when Im bored.
If you already have the email version, mind sending it? Save me having to add it.
 
I did not change anything but the WAN0TARGET= , and added the
service "restart_wan_if 1", I will probably add a option to change qos or not to variable. But thats when Im bored.
If you already have the email version, mind sending it? Save me having to add it.
Send me a copy of your modified script and let me take a look, yea when I get home I’ll send it over, it’s a separate script and my failover script just has a function that calls to send email whenever a switch happens.
 
I did not change anything but the WAN0TARGET= , and added the
service "restart_wan_if 1", I will probably add a option to change qos or not to variable. But thats when Im bored.
If you already have the email version, mind sending it? Save me having to add it.
That happened when it switched to wan1, I bet I have another blank nvram setting that needs changed on Wan1. My script is literally exactly yours, I changed the WAN0Target to what you pasted here.
and just commented out wan-event.
 
That happened when it switched to wan1, I bet I have another blank nvram setting that needs changed on Wan1. My script is literally exactly yours, I changed the WAN0Target to what you pasted here.
and just commented out wan-event.
Did you lowercase the variable? It has to match how it is called in the script. WAN0TARGET is how I wrote it.
 
Did you lowercase the variable? It has to match how it is called in the script. WAN0TARGET is how I wrote it.
WAN0TARGET="$(nvram get wan0_dns | awk '{print $1}')"
WAN1TARGET="$(nvram get wan1_gateway)"
 

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!
Top