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!

Thank you.
Because I have moved the logs via syslog-ng, I guess monitoring have this output:
Bash:
/tmp/home/root#:/jffs/scripts/wan-failover.sh monitor
wan-failover.sh - Monitor Mode
tail: /tmp/syslog.log has been replaced; following end of new file
tail: /tmp/syslog.log has been replaced; following end of new file

I monitored my messages log for wan-failover.sh while being in monitor mode:

Code:
Jun 19 19:25:42 src@B88X wan-failover.sh: WAN Status - wan1 enabled
Jun 19 19:25:42 src@B88X wan-failover.sh: WAN Status - Route already exists for 1.0.0.1 via 192.168.7.1 dev eth8
Jun 19 19:25:44 src@B88X wan-failover.sh: WAN Status - wan1 has 0% packet loss
Jun 19 19:25:44 src@B88X wan-failover.sh: WAN1 Active - Verifying WAN1
Jun 19 19:25:44 src@B88X wan-failover.sh: WAN0 Failback Monitor - Monitoring WAN0 via 1.1.1.1 for Failback
Jun 19 19:25:44 src@B88X wan-failover.sh: WAN Status - wan0 enabled
Jun 19 19:25:44 src@B88X wan-failover.sh: WAN Status - wan0 is disconnected.  IP Address: 0.0.0.0 Gateway: 0.0.0.0
Jun 19 19:25:44 src@B88X wan-failover.sh: WAN Status - wan1 enabled
Jun 19 19:25:44 src@B88X wan-failover.sh: WAN Status - Route already exists for 1.0.0.1 via 192.168.7.1 dev eth8
Jun 19 19:25:46 src@B88X wan-failover.sh: WAN Status - wan1 has 0% packet loss
Jun 19 19:25:46 src@B88X wan-failover.sh: WAN1 Active - Verifying WAN1
Jun 19 19:25:46 src@B88X wan-failover.sh: WAN0 Failback Monitor - Monitoring WAN0 via 1.1.1.1 for Failback
Jun 19 19:25:46 src@B88X wan-failover.sh: WAN Status - wan0 enabled
Jun 19 19:25:46 src@B88X wan-failover.sh: WAN Status - Creating route 1.1.1.1 via 10.0.0.1 dev eth0
Jun 19 19:26:00 src@B88X wan-failover.sh: WAN Status - wan0 enabled
Jun 19 19:26:01 src@B88X wan-failover.sh: WAN Status - Creating route 1.1.1.1 via 10.0.0.1 dev eth0
Jun 19 19:27:00 src@B88X wan-failover.sh: WAN Status - wan0 enabled
Jun 19 19:27:00 src@B88X wan-failover.sh: WAN Status - Creating route 1.1.1.1 via 10.0.0.1 dev eth0

PS: wan0 = PPPoE, wan1 = USB Dongle
During this time:
wan0 remains stucked in Hot-Standby with public IP stored in wan0_ipaddr and wan_ipaddr.
wan1 connected with IP stored in wan1_ipaddr


Thank you!

Yea I see the problem, wan0_gateway is 0.0.0.0 it would seem. Do you know why that would be the case? It may be that it is 0.0.0.0 when the script is running status checks and then it populates properly post script execution? Let me know if that is the case, I can see where that condition can cause issues and can resolve it with an update.
 
Last edited:
Yea I see the problem, wan0_gateway is 0.0.0.0 it would seem. Do you know why that would be the case? It may be that it is 0.0.0.0 when the script is running status checks and then it populates properly post script execution? Let me know if that is the case, I can see where that condition can cause issues and can resolve it with an update.
I pasted below the nvram changed values while on wan0 (left) and right on wan1.
I unplugged the wan0 while I have active the Allow Failback from GUI:

Code:
ddns_cache=165xxxx945,82.x.x.x                  |    ddns_cache=165xxxx477,213.x.x.x
ddns_ipaddr=82.x.x.x                      |    ddns_ipaddr=213.x.x.x
ddns_last_wan_unit=0                          |    ddns_last_wan_unit=1
ddns_update_by_wdog=                          |    ddns_update_by_wdog=1
igmp_ifname=eth0                          |    igmp_ifname=eth8
link_wan=1                              |    link_wan=0
login_ip=                              |    login_ip=2394549258
login_ip_str=                              |    login_ip_str=10.10.10.142
login_timestamp=                          |    login_timestamp=2611
rc_service=                              |    rc_service_pid=989
rc_service_pid=                              |    rc_service=restart_wan_line 1
wan0_auxstate_t=0                          |    wan0_auxstate_t=1
wan0_gateway=10.0.0.1                          |    wan0_gateway=0.0.0.0
wan0_ipaddr=82.x.x.x                      |    wan0_ipaddr=0.0.0.0
wan0_netmask=255.255.255.255                      |    wan0_netmask=0.0.0.0
wan0_pppoe_ifname=ppp0                          |    wan0_pppoe_ifname=
wan0_primary=1                              |    wan0_primary=0
wan0_realip_ip=82.x.x.x                      |    wan0_realip_ip=
wan0_realip_state=2                          |    wan0_realip_state=0
wan0_state_t=2                              |    wan0_state_t=1
wan1_primary=0                              |    wan1_primary=1
wan1_realip_ip=                              |    wan1_realip_ip=213.x.x.x
wan1_realip_state=0                          |    wan1_realip_state=2
wan_primary=0                              |    wan_primary=1

I am still trying to understand. Please help if you have ideas.

Later edit:
I might have 0.0.0.0 for wan0_gateway only for few moments.
I can see that while on wan0:
Code:
/tmp/home/root#:nvser wan0_gateway
wan0_gateway=10.0.0.1
wan0_gateway_x=0.0.0.0
Only wan0_gateway_x remain 0.0.0.0


Thank you!
amplatfus
 
Last edited:
I pasted below the nvram changed values while on wan0 (left) and right on wan1.
I unplugged the wan0 while I have active the Allow Failback from GUI:

Code:
ddns_cache=165xxxx945,82.x.x.x                  |    ddns_cache=165xxxx477,213.x.x.x
ddns_ipaddr=82.x.x.x                      |    ddns_ipaddr=213.x.x.x
ddns_last_wan_unit=0                          |    ddns_last_wan_unit=1
ddns_update_by_wdog=                          |    ddns_update_by_wdog=1
igmp_ifname=eth0                          |    igmp_ifname=eth8
link_wan=1                              |    link_wan=0
login_ip=                              |    login_ip=2394549258
login_ip_str=                              |    login_ip_str=10.10.10.142
login_timestamp=                          |    login_timestamp=2611
rc_service=                              |    rc_service_pid=989
rc_service_pid=                              |    rc_service=restart_wan_line 1
wan0_auxstate_t=0                          |    wan0_auxstate_t=1
wan0_gateway=10.0.0.1                          |    wan0_gateway=0.0.0.0
wan0_ipaddr=82.x.x.x                      |    wan0_ipaddr=0.0.0.0
wan0_netmask=255.255.255.255                      |    wan0_netmask=0.0.0.0
wan0_pppoe_ifname=ppp0                          |    wan0_pppoe_ifname=
wan0_primary=1                              |    wan0_primary=0
wan0_realip_ip=82.x.x.x                      |    wan0_realip_ip=
wan0_realip_state=2                          |    wan0_realip_state=0
wan0_state_t=2                              |    wan0_state_t=1
wan1_primary=0                              |    wan1_primary=1
wan1_realip_ip=                              |    wan1_realip_ip=213.x.x.x
wan1_realip_state=0                          |    wan1_realip_state=2
wan_primary=0                              |    wan_primary=1

I am still trying to understand. Please help if you have ideas.

Later edit:
I might have 0.0.0.0 for wan0_gateway only for few moments.
I can see that while on wan0:
Code:
/tmp/home/root#:nvser wan0_gateway
wan0_gateway=10.0.0.1
wan0_gateway_x=0.0.0.0
Only wan0_gateway_x remain 0.0.0.0


Thank you!
amplatfus
You can confirm that it doesn't stay 0.0.0.0 and populates the Gateway IP shortly after? If so I have a couple ways I can resolve this just need confirmation before I start "fixing" it. The main reason for this check is it won't properly create the route for monitoring the interface if the Gateway IP returns as 0.0.0.0.
 
You can confirm that it doesn't stay 0.0.0.0 and populates the Gateway IP shortly after? If so I have a couple ways I can resolve this just need confirmation before I start "fixing" it. The main reason for this check is it won't properly create the route for monitoring the interface if the Gateway IP returns as 0.0.0.0.
Good news: Yes, I can confirm that after about 30 seconds it is populated.
Tested while Allow failback unchecked in Asus Dual WAN tab.

10x,
amplatfus
 
Good news: Yes, I can confirm that after about 30 seconds it is populated.
Tested while Allow failback unchecked in Asus Dual WAN tab.

10x,
amplatfus
Ok I will come up with a solution, in the meantime if you want to use the script you can manually create the route for your WAN0 target.

EDIT: On further review of the logs it seems to be correcting itself for this but when it tries to create the route for WAN0 Target it is getting stuck in a loop of trying to create the route.
 
Last edited:
Thank you very much. I will monitor this thread and next releases.
Thank you,
amplatfus
 
Thank you very much. I will monitor this thread and next releases.
Thank you,
amplatfus
Well…we have to figure out why your router is failing to create the route. Can you get it in the stuck loop again and look at your route table and send the output?
Code:
ip route show table main
 
Well…we have to figure out why your router is failing to create the route. Can you get it in the stuck loop again and look at your route table and send the output?
Code:
ip route show table main
Hi,

I saved 3 situation:

(a) wan0 activ, after reboot (OK)
Code:
/tmp/home/root#:ip route show table main
default via 10.0.0.1 dev ppp0
1.0.0.1 via 10.0.0.1 dev ppp0 metric 1
1.1.1.1 via 10.0.0.1 dev ppp0 metric 1
1.2.3.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.4.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.8.8 via 10.36.185.1 dev br0 scope link metric 3
10.0.0.0/8 dev br0 proto kernel scope link src 10.36.185.2
10.0.0.1 dev ppp0 proto kernel scope link
10.50.1.0/24 dev wg21 proto kernel scope link src 10.50.1.1
10.50.1.2 dev wg21 scope link
10.80.0.13 dev tun15 proto kernel scope link src 10.80.0.14
10.90.0.5 dev tun11 proto kernel scope link src 10.90.0.6
10.180.220.0/24 dev tun21 proto kernel scope link src 10.180.220.1
10.36.174.0/24 dev br1 proto kernel scope link src 10.36.174.1
10.36.185.0/24 dev br0 proto kernel scope link src 10.36.185.1
127.0.0.0/8 dev lo scope link
169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.32.32
192.168.7.0/24 dev eth8 proto kernel scope link src 192.168.7.122
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.2

(b) failover to secondary wan (OK)
Code:
/tmp/home/root#:ip route show table main
default via 192.168.7.1 dev eth8
1.0.0.1 via 192.168.7.1 dev eth8
1.2.3.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.4.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.8.8 via 10.36.185.1 dev br0 scope link metric 3
10.0.0.0/8 dev br0 proto kernel scope link src 10.36.185.2
10.50.1.0/24 dev wg21 proto kernel scope link src 10.50.1.1
10.50.1.2 dev wg21 scope link
10.80.0.17 dev tun15 proto kernel scope link src 10.80.0.18
10.90.0.5 dev tun11 proto kernel scope link src 10.90.0.6
10.180.220.0/24 dev tun21 proto kernel scope link src 10.180.220.1
10.36.174.0/24 dev br1 proto kernel scope link src 10.36.174.1
10.36.185.0/24 dev br0 proto kernel scope link src 10.36.185.1
127.0.0.0/8 dev lo scope link
169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.32.32
192.168.7.0/24 dev eth8 proto kernel scope link src 192.168.7.122
192.168.7.1 dev eth8 proto kernel scope link
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.2

(c) while stuck on secondary wan, even wan0_gateway was populated after about 20-30 seconds
Code:
/tmp/home/root#:ip route show table main
default via 192.168.7.1 dev eth8
1.0.0.1 via 192.168.7.1 dev eth8
1.0.0.1 via 10.0.0.1 dev ppp0 metric 1
1.1.1.1 via 10.0.0.1 dev ppp0 metric 1
1.2.3.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.4.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.8.8 via 10.36.185.1 dev br0 scope link metric 3
10.0.0.0/8 dev br0 proto kernel scope link src 10.36.185.2
10.0.0.1 dev ppp0 proto kernel scope link src 82.77.97.142
10.50.1.0/24 dev wg21 proto kernel scope link src 10.50.1.1
10.50.1.2 dev wg21 scope link
10.80.0.13 dev tun15 proto kernel scope link src 10.80.0.14
10.90.0.9 dev tun11 proto kernel scope link src 10.90.0.10
10.180.220.0/24 dev tun21 proto kernel scope link src 10.180.220.1
10.36.174.0/24 dev br1 proto kernel scope link src 10.36.174.1
10.36.185.0/24 dev br0 proto kernel scope link src 10.36.185.1
127.0.0.0/8 dev lo scope link
169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.32.32
192.168.7.0/24 dev eth8 proto kernel scope link src 192.168.7.122
192.168.7.1 dev eth8 proto kernel scope link
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.2

/tmp/home/root#:nvser wan0_gateway
size: 77493 bytes (53579 left)
wan0_gateway=10.0.0.1
wan0_gateway_x=0.0.0.0

Later edit:
After wan0_gateway is populated if I do:
/jffs/scripts/wan-failover.sh kill +
/jffs/scripts/wan-failover.sh switchwan = doesn't help, the wan1 remain connected while wan0 in Hot-Standby.

Thank you!
 
Last edited:
Hi,

I saved 3 situation:

(a) wan0 activ, after reboot (OK)
Code:
/tmp/home/root#:ip route show table main
default via 10.0.0.1 dev ppp0
1.0.0.1 via 10.0.0.1 dev ppp0 metric 1
1.1.1.1 via 10.0.0.1 dev ppp0 metric 1
1.2.3.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.4.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.8.8 via 10.36.185.1 dev br0 scope link metric 3
10.0.0.0/8 dev br0 proto kernel scope link src 10.36.185.2
10.0.0.1 dev ppp0 proto kernel scope link
10.50.1.0/24 dev wg21 proto kernel scope link src 10.50.1.1
10.50.1.2 dev wg21 scope link
10.80.0.13 dev tun15 proto kernel scope link src 10.80.0.14
10.90.0.5 dev tun11 proto kernel scope link src 10.90.0.6
10.180.220.0/24 dev tun21 proto kernel scope link src 10.180.220.1
10.36.174.0/24 dev br1 proto kernel scope link src 10.36.174.1
10.36.185.0/24 dev br0 proto kernel scope link src 10.36.185.1
127.0.0.0/8 dev lo scope link
169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.32.32
192.168.7.0/24 dev eth8 proto kernel scope link src 192.168.7.122
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.2

(b) failover to secondary wan (OK)
Code:
/tmp/home/root#:ip route show table main
default via 192.168.7.1 dev eth8
1.0.0.1 via 192.168.7.1 dev eth8
1.2.3.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.4.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.8.8 via 10.36.185.1 dev br0 scope link metric 3
10.0.0.0/8 dev br0 proto kernel scope link src 10.36.185.2
10.50.1.0/24 dev wg21 proto kernel scope link src 10.50.1.1
10.50.1.2 dev wg21 scope link
10.80.0.17 dev tun15 proto kernel scope link src 10.80.0.18
10.90.0.5 dev tun11 proto kernel scope link src 10.90.0.6
10.180.220.0/24 dev tun21 proto kernel scope link src 10.180.220.1
10.36.174.0/24 dev br1 proto kernel scope link src 10.36.174.1
10.36.185.0/24 dev br0 proto kernel scope link src 10.36.185.1
127.0.0.0/8 dev lo scope link
169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.32.32
192.168.7.0/24 dev eth8 proto kernel scope link src 192.168.7.122
192.168.7.1 dev eth8 proto kernel scope link
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.2

(c) while stuck on secondary wan, even wan0_gateway was populated after about 20-30 seconds
Code:
/tmp/home/root#:ip route show table main
default via 192.168.7.1 dev eth8
1.0.0.1 via 192.168.7.1 dev eth8
1.0.0.1 via 10.0.0.1 dev ppp0 metric 1
1.1.1.1 via 10.0.0.1 dev ppp0 metric 1
1.2.3.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.4.4 via 10.36.185.1 dev br0 scope link metric 3
8.8.8.8 via 10.36.185.1 dev br0 scope link metric 3
10.0.0.0/8 dev br0 proto kernel scope link src 10.36.185.2
10.0.0.1 dev ppp0 proto kernel scope link src 82.77.97.142
10.50.1.0/24 dev wg21 proto kernel scope link src 10.50.1.1
10.50.1.2 dev wg21 scope link
10.80.0.13 dev tun15 proto kernel scope link src 10.80.0.14
10.90.0.9 dev tun11 proto kernel scope link src 10.90.0.10
10.180.220.0/24 dev tun21 proto kernel scope link src 10.180.220.1
10.36.174.0/24 dev br1 proto kernel scope link src 10.36.174.1
10.36.185.0/24 dev br0 proto kernel scope link src 10.36.185.1
127.0.0.0/8 dev lo scope link
169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.32.32
192.168.7.0/24 dev eth8 proto kernel scope link src 192.168.7.122
192.168.7.1 dev eth8 proto kernel scope link
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.2

/tmp/home/root#:nvser wan0_gateway
size: 77493 bytes (53579 left)
wan0_gateway=10.0.0.1
wan0_gateway_x=0.0.0.0

Later edit:
After wan0_gateway is populated if I do:
/jffs/scripts/wan-failover.sh kill +
/jffs/scripts/wan-failover.sh switchwan = doesn't help, the wan1 remain connected while wan0 in Hot-Standby.

Thank you!

Your target is a DNS server for 1 of your WAN interfaces, try and change it to something different. I’ll put in some logic for this in a future release.
 
@Ranger802004 Id like to be able to access my secondarys modem stats page while connected to primary. Its ip is 192.168.254.254 , is there a route command i could add that would do this?
I tried
ip route add 192.168.254.254 via 192.168.10.1 dev eth5
but does nothing
 
@Ranger802004 Id like to be able to access my secondarys modem stats page while connected to primary. Its ip is 192.168.254.254 , is there a route command i could add that would do this?
I tried
ip route add 192.168.254.254 via 192.168.10.1 dev eth5
but does nothing
Hi,

I have for access the ONT modem from LAN:
Code:
ifconfig $(nvram get wan0_ifname):0 192.168.1.2 netmask 255.255.255.0
 
Your target is a DNS server for 1 of your WAN interfaces, try and change it to something different. I’ll put in some logic for this in a future release.
I tried with WAN0TARGET=9.9.9.9 and nothing changed.
 
Hi,

I have for access the ONT modem from LAN:
Code:
ifconfig $(nvram get wan0_ifname):0 192.168.1.2 netmask 255.255.255.0
is 192.168.1.2 your modem stats?
 
is 192.168.1.2 your modem stats?
No, the IP of my modem is: 192.168.1.1 but is accessible with what I replied.
 
No, the IP of my modem is: 192.168.1.1 but is accessible with what I replied.
hrm, still no luck for me. maybe my secondary wan1s gateway ips are 192.168.10.1.. but to access the modem while on that sub net is 192.168.254.254
 
@Ranger802004 Id like to be able to access my secondarys modem stats page while connected to primary. Its ip is 192.168.254.254 , is there a route command i could add that would do this?
I tried
ip route add 192.168.254.254 via 192.168.10.1 dev eth5
but does nothing

Just create a route without the gateway.
Code:
ip route add 192.168.254.254 dev eth5
 
Did you kill the script and let it restart?
I did a restart of the router.

For every test I did like this:
1) disabled Allow failback from Asus GUI and the implicit restart.
2) unplug ONT (go to secondary wan)
3) wait
4) plug the ONT (while secondary wan stuck to connected)

When I am not testing I activate Allow failback from Asus GUI (because only using it I am not stuck to secondary).

Thanks,
amplatfus
 
Just create a route without the gateway.
Code:
ip route add 192.168.254.254 dev eth5
doesnt work
Just create a route without the gateway.
Code:
ip route add 192.168.254.254 dev eth5
doesnt work
if i switch to wan1, 192.168.254.254 in a browser takes me straight to the dsl modem url

Code:
estination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         100.64.0.1      0.0.0.0         UG    0      0        0 eth0
1.1.1.1         100.64.0.1      255.255.255.255 UGH   1      0        0 eth0
8.8.4.4         192.168.10.1    255.255.255.255 UGH   0      0        0 eth5
8.8.8.8         100.64.0.1      255.255.255.255 UGH   1      0        0 eth0
34.120.255.244  *               255.255.255.255 UH    0      0        0 eth0
100.64.0.0      *               255.192.0.0     U     0      0        0 eth0
100.64.0.1      *               255.255.255.255 UH    0      0        0 eth0
127.0.0.0       *               255.0.0.0       U     0      0        0 lo
192.168.10.0    *               255.255.255.0   U     0      0        0 eth5
192.168.50.0    *               255.255.255.0   U     0      0        0 br0
192.168.100.1   *               255.255.255.255 UH    0      0        0 eth0
192.168.254.254 *               255.255.255.255 UH    0      0        0 eth5
239.0.0.0       *               255.0.0.0       U     0      0        0 br0
 
Last edited:
I did a restart of the router.

For every test I did like this:
1) disabled Allow failback from Asus GUI and the implicit restart.
2) unplug ONT (go to secondary wan)
3) wait
4) plug the ONT (while secondary wan stuck to connected)

When I am not testing I activate Allow failback from Asus GUI (because only using it I am not stuck to secondary).

Thanks,
amplatfus
Can you send me updated logs when it is not working after changing the IP
 

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