What's new

Dual WAN Failover ***v2 Release***

  • 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.9 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:
Use Menu Option 6 or Run the Following Command
Code:
/jffs/scripts/wan-failover.sh update

Uninstallation:
Use Menu Option 4 or Run the Following Command
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:
v2.0.6 Release Notes:
Enhancements:
- Added 388.4 to Support List
- General Optimization
- WireGuard clients will restart during failover to recreate the default routes in each WireGuard Route Table.

Fixes:
- Corrected issue where having no OpenVPN Server Instances configured caused WAN Failover to hang.

v2.0.5 Release Notes:
Fixes:
- Corrected minor issue when retrieving WAN NVRAM Parameters
- Corrected issue if WAN Failover would be stuck in a continuous loop if a router didn't have WAN USB capability.
- Corrected issue that causes WAN Failover to exit in Load Balance mode during failover events.
- Corrected issue where DDNS Hostname being blank would cause the script to hang in a loop while collecting System Settings.
- Corrected issue during install where the existing monitor target value was a domain and being used as the WAN0 Target IP default value.

v2.0.4 Release Notes:
Enhancements:
- Added 3rd DNS Server from Automatic Settings to be factored into WAN Failover events.
- The checkiprules function will now be checked at the beginning of WAN Status checks to ensure NAT rules are created if necessary prior to performing packet loss checks.
- Added 386.10 and 386.11 to supported firmware list
- Removed 386.5 and 386.7 from supported firmware list.

Fixes:
- Corrected issue during uninstall when logic was reversed for retaining configuration file or to delete.

v2.0.3 Release Notes:
Fixes:
- Corrected syntax bug in Debug Logging function.

v2.0.2 Release Notes:
Fixes:
- Fixed minor issue with install mode getting stuck on WANDOGTARGET variable.

v2.0.1 Release Notes:
Enhancements:
- Added Process Priority (Real Time, High, Normal, Low, Lowest) for WAN Failover. Configuration Option: Process Priority
- General Optimization.
- CHECKNVRAM is Enabled by Default for the RT-AC86U and GT-AC2900 models on new installations.
- Status Console now shows more descriptions for each WAN interface status.
- Status Console will now passively check for updates every 4 hours while running.
- Status Console will now show WAN Failover status as "Initializing" for start up of the script.
- Added new option to block IPv6 in Failover Mode from traversing Secondary WAN. Configuration Option: Failover Block IPv6

Fixes:
- Corrected issues preventing Failback in v2.0.0.
- Corrected issues with acquiring WAN Interface MAC Addresses.
- Corrected issues with Email Notifications not properly disabling.
- Restart WAN functions will now start interface if already stopped instead of executing restart command.

v2.0.0 Release Notes:
Installation:
- Uninstallation will prompt if configuration file should be deleted or retained.
- During uninstallation, the script will now delete the script file. This change was necessary for AMTM integration
- Installation will automatically create default configuration that can be modified in the Config Menu.
- Installation will alert and log if Router is not properly configured for WAN Failover to being operation.

Enhancements:
- Added 388.2 to supported Firmware list
- Added 386.9 to supported Firmware list
- switchwan argument can now be ran in an unattended mode to passively allow failover that doesn't require User Verification to failover.
- Added new Configuration Option: SCHEDULECRONJON. Enabled by default, this will control whether the Cron Job is scheduled or not for WAN Failover to run.
This is configurable in the Config Menu under Option 23: Configure Cron Job
- Added Load Balance Mode Settings to GUI Config Menu for WAN0 FWMark, WAN0 Mask, WAN1 FWMark, and WAN1 Mask.
- Changed CHECKNVRAM Default to Disabled for performance optimization. This feature should only be enabled on routers with issues accessing nvram.
Existing installations of WAN Failover will need this setting manually changed under Configuration Menu Option 12.
- Added initiate command argument to only create Routing Table Rules, IP Rules, and IPTables Rules.
- Load Balance Monitor will now check IP Rules by default of every 15 minutes to make sure all rules are properly configured. This will help resolve issues where the router adds improperly configured IPTables MANGLE rules.
- Visual Enhancements with prompts.
- Optimization of script including reducing the number of NVRAM calls during script execution.
- New Enhanced Status Console
- Access from Menu or Command Argument "status"
- Built in Refresh Interval Added
- Additional information included (Failover Status, Primary WAN, Gateway MAC Address, Ping Time, etc).
- Added new configuration items PINGTIMEMIN (Ping Time will show green in Console), PINGTIMEMAX (Ping Time will show red in console), STATUSCHECK (Default interval between Status Console refreshes).
- System Log Events will now show as "wan-failover" instead of "wan-failover.sh"
- System Log Events for Failover Mode WAN Switches will dynamically be listed under "Failover" or "Failback" instead of "WAN Switch"
- System Log Events will now log if Ping Time Maximum is reached for WAN0 or WAN1.
- System Log Events will now log if an NVRAM Check Failure occured with CHECKNVRAM Enabled.
- Email Notifications will now display if QoS ATM is enabled.
- Configuration Menu will now allow configuration of all QoS Settings.
- Configuration Mode will now go straight to Configuration Menu when using command argument "config".
- Restart Services will now restart all processes consecutively without waiting for them to complete to reduce failover/failback time.
- Improvements to Update Mode for version checks
- Update Mode will now check checksum to ensure integrity of WAN Failover.

Fixes:
- Removed VPNMON-R2 integration. VPNMON-R2 is now capable of detecting failover events and resetting itself without WAN Failover.
- Resolved issue where some Failback emails were not being generated
- Resolved issue where WAN Failover was logging that QoS settings were being applied and restarting services if the non-Primary WAN failed during monitoring
- Various fixes to improve reliability and integrity of script.
- Monitor and Capture Mode will no longer show messages from tail command stating the file path has changed.
- Fixed Restart Mode not killing all PIDs.
- Added a check if WAN was changed by router firmware before making it to Failover function so it doesn't attempt to switch back Primary WAN to a down WAN interface.
- Fixed an issue where Installation would not create the WAN0_QOS_OBW configuration setting.

Deprecated:
- Removed Email Configuration Mode, use Configuration Menu to change Email Notification Settings.

New Status Console Example:
Note: To change the refresh interval, go to the Configuration Menu and modify the Status Check Setting

1678927485093.png
 
Last edited:
Upgraded from V1.6.0 Final to V2.0.0-beta1 with no problems in FAILOVER mode.

I did get this syntax error when upgrading, not sure if it is just cosmetic:

Code:
/jffs/scripts/wan-failover.sh: line 3646: syntax error: unexpected "&&"
 
Upgraded from V1.6.0 Final to V2.0.0-beta1 with no problems in FAILOVER mode.

I did get this syntax error when upgrading, not sure if it is just cosmetic:

Code:
/jffs/scripts/wan-failover.sh: line 3646: syntax error: unexpected "&&"
I believe I identified the issue and I uploaded a minor revision, please do an update and let the script reinstall. I added in a Checksum check for reinstalls just now that will tell you if your local copy is different than the remote copy.
 
I believe I identified the issue and I uploaded a minor revision, please do an update and let the script reinstall.
Just did my own 2.0.0b1 update after your minor revision and no syntax error seen for me. New version appears to be running ok, will report further when I've tested a failover/fall back, hopefully later today.
 
@Ranger802004 any chance the status display could also be called as a command line option, as in "wan-failover status" ???
I could but not in this cycle as that would require a major change to allow it to call just that function part of a command argument. What are your thoughts on having this shortcut?
 
What are your thoughts on having this shortcut?
I guess to be able to quickly display it in its own SSH session directly, similar to what you can do with "wan-failover monitor" now?
 
I guess to be able to quickly display it in its own SSH session directly, similar to what you can do with "wan-failover monitor" now?
Let me see what I can do and I'll get back with you.
 
v2.0.0-beta2 has been published with the following changes, you can run the update command to update to the latest beta version if you have Dev Mode enabled.

Changes from v2.0.0-beta1:
- Added a check if WAN was changed by router firmware before making it to Failover function so it doesn't attempt to switch back Primary WAN to a down WAN interface.
- Fixed Debug Log function for run and manual mode
- Added "status" command argument to call status console.
- Added log events if ping times reach PINGTIMEMAX setting.
- Fixed Restart Mode not killing all PIDs.
- Removed references to config and email command arguments.
- Fixed QoS Overhead values using QOS Inbound Bandwidth value in NVRAM.
- Finished changing references from wan-failover.sh to wan-failover for logging and on-screen messages.
- If QoS ATM is enabled, it will show as Enabled in email notifications.
- Status Page will show DDNS Hostname if DDNS is Enabled and has a DDNS Hostname.
 
Last edited:
v2.0.0-beta3 has been published with the following changes, you can run the update command to update to the latest beta version if you have Dev Mode enabled.

Changes from v2.0.0-beta2:
- Fixed Restart Mode not killing all PIDs.
- Restore Config Mode and now loads same menu as Menu Option 5
- Fixed Config Options for Load Balancing mapping to the wrong settings.
- Added All QoS Configuration Options to Config Menu.
- Load Balance Configuration Settings will only show while in Load Balance Mode or if Dev Mode is Enabled.
- Finished moving debuglog function from directly accessing NVRAM Values when logging values.
 
Hello @Ranger802004
I tested your script. The install hang after entering "Y".
Tested on :
RT-AC88U
Firmware:386.9
Let me take a look into this, I did modify this section during this beta cycle.
 
v2.0.0-beta4 has been published with the following changes, you can run the update command to update to the latest beta version if you have Dev Mode enabled.

Changes from v2.0.0-beta3:
Added debug logging to WAN Interface Restart functions.
Added a sleep timer for WAN Interface Restart loops.
Removed echo command from Restart Mode loop that kills PIDs, this was used for testing.
Optimizations to Get WAN Parameters Mode 1
Removed WANUSB to use DUALWANDEV parameter
Improvements to Update Mode for version checks
Update Mode will now check checksum to ensure integrity of WAN Failover.
Send stderr for curl commands to /dev/null
Add full color code chart
Re-color coded Status Console
Added logging messages during installation
Corrected issue with Installation not creating WAN0_QOS_OBW Configuration Option
 
Update from V2.0.0 beta3 to V2.0.0 beta4:

- timeout counted down on SSH terminal from 120 seconds to 0, per line, for wan-failover restart
- line 47: pstree: not found

Code:
wan-failover - Update Mode
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  298k  100  298k    0     0   487k      0 --:--:-- --:--:-- --:--:--  509k
***Dev Mode is Enabled***
Script is out of date - Current Version: v2.0.0-beta3 Available Version: v2.0.0-beta4
Do you want to update to the latest beta version? v2.0.0-beta4 ***Enter Y for Yes or N for No***
> y
/jffs/scripts/wan-failover.sh: line 47: pstree: not found
wan-failover: Restart - ***wan-failover is not running*** No Process ID Detected
wan-failover: Restart - Waiting for wan-failover to restart from Cron Job
/jffs/scripts/wan-failover.sh: line 47: pstree: not found
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 120 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 119 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 118 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 117 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 116 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 115 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 114 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 113 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 112 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 111 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 110 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 109 Seconds

/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 10 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 9 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 8 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 7 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 6 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 5 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 4 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 3 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 2 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 1 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 0 Seconds
wan-failover: Restart - Failed to restart wan-failover ***Check Logs***
wan-failover: Update - wan-failover has been updated to version: v2.0.0-beta4
/jffs/scripts/wan-failover.sh: line 5440: syntax error: unexpected "("
 
Update from V2.0.0 beta3 to V2.0.0 beta4:

- timeout counted down on SSH terminal from 120 seconds to 0, per line, for wan-failover restart
- line 47: pstree: not found

Code:
wan-failover - Update Mode
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  298k  100  298k    0     0   487k      0 --:--:-- --:--:-- --:--:--  509k
***Dev Mode is Enabled***
Script is out of date - Current Version: v2.0.0-beta3 Available Version: v2.0.0-beta4
Do you want to update to the latest beta version? v2.0.0-beta4 ***Enter Y for Yes or N for No***
> y
/jffs/scripts/wan-failover.sh: line 47: pstree: not found
wan-failover: Restart - ***wan-failover is not running*** No Process ID Detected
wan-failover: Restart - Waiting for wan-failover to restart from Cron Job
/jffs/scripts/wan-failover.sh: line 47: pstree: not found
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 120 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 119 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 118 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 117 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 116 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 115 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 114 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 113 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 112 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 111 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 110 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 109 Seconds

/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 10 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 9 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 8 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 7 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 6 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 5 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 4 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 3 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 2 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 1 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 0 Seconds
wan-failover: Restart - Failed to restart wan-failover ***Check Logs***
wan-failover: Update - wan-failover has been updated to version: v2.0.0-beta4
/jffs/scripts/wan-failover.sh: line 5440: syntax error: unexpected "("
Ah I see pstree is not on every router, I’ll have to expand on that logic.
 
tell me i'm dumb. or ******* asking stupid questions...

i'm trying to figure out what is the advantage of using your script for 'dual wan' - against built-in features... i'm a bit lame. i need dual-wan to assure persistence of internet connection (some cable internet, plus gsm modem for backup) for 'work-from-home' way of working. And i need a really flexible and swift solution (so if cable goes down - gsm takes over, and only and if cable goes back and works stable- i can turn off gsm) - whatever happens - I need to be 'connected'...

I really appreciate some feedback. Please.


Thank you!
Asceta
 
Update from V2.0.0 beta3 to V2.0.0 beta4:

- timeout counted down on SSH terminal from 120 seconds to 0, per line, for wan-failover restart
- line 47: pstree: not found

Code:
wan-failover - Update Mode
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  298k  100  298k    0     0   487k      0 --:--:-- --:--:-- --:--:--  509k
***Dev Mode is Enabled***
Script is out of date - Current Version: v2.0.0-beta3 Available Version: v2.0.0-beta4
Do you want to update to the latest beta version? v2.0.0-beta4 ***Enter Y for Yes or N for No***
> y
/jffs/scripts/wan-failover.sh: line 47: pstree: not found
wan-failover: Restart - ***wan-failover is not running*** No Process ID Detected
wan-failover: Restart - Waiting for wan-failover to restart from Cron Job
/jffs/scripts/wan-failover.sh: line 47: pstree: not found
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 120 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 119 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 118 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 117 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 116 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 115 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 114 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 113 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 112 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 111 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 110 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 109 Seconds

/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 10 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 9 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 8 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 7 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 6 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 5 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 4 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 3 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 2 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 1 Seconds
/jffs/scripts/wan-failover.sh: line 47: pstree: not foundimeout: 0 Seconds
wan-failover: Restart - Failed to restart wan-failover ***Check Logs***
wan-failover: Update - wan-failover has been updated to version: v2.0.0-beta4
/jffs/scripts/wan-failover.sh: line 5440: syntax error: unexpected "("
Published a fix for this, update again.
 
tell me i'm dumb. or ******* asking stupid questions...

i'm trying to figure out what is the advantage of using your script for 'dual wan' - against built-in features... i'm a bit lame. i need dual-wan to assure persistence of internet connection (some cable internet, plus gsm modem for backup) for 'work-from-home' way of working. And i need a really flexible and swift solution (so if cable goes down - gsm takes over, and only and if cable goes back and works stable- i can turn off gsm) - whatever happens - I need to be 'connected'...

I really appreciate some feedback. Please.


Thank you!
Asceta
The main problem is the failback condition is only detecting if a cable is plugged in for the WAN0 interface, this doesn't necessarily mean WAN0 is active and has a connection. My script actively monitors both interfaces to perform proper failover monitoring as well as logging and email notifications for failover/failback events.
 
ay ay Sir!

thanks. And then I would test it, for sure. And i really mean it... for me - it sucks that I see 'flapping' conditions (switching between cable and GSM) for the 'stock' solution. I always thought that built-in feature has some issues with detecting conditions for stable connection. And now I see that i could test something that could improve something, really...

Thank you!
Asceta
 
v2.0.0-beta4 has been published with the following changes, you can run the update command to update to the latest beta version if you have Dev Mode enabled.

Changes from v2.0.0-beta3:
Added debug logging to WAN Interface Restart functions.
Added a sleep timer for WAN Interface Restart loops.
Removed echo command from Restart Mode loop that kills PIDs, this was used for testing.
Optimizations to Get WAN Parameters Mode 1
Removed WANUSB to use DUALWANDEV parameter
Improvements to Update Mode for version checks
Update Mode will now check checksum to ensure integrity of WAN Failover.
Send stderr for curl commands to /dev/null
Add full color code chart
Re-color coded Status Console
Added logging messages during installation
Corrected issue with Installation not creating WAN0_QOS_OBW Configuration Option
Published some minor revisions to v2.0.0-beta4
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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