I already did that. Below is the backup link script for your reference.
NET_IF="wan2"
PING_IP_IF="8.8.8.8"
NET_FIF="wan"
PING_IP_FIF="8.8.8.8"
. /lib/functions/network.sh
network_flush_cache
for IPV in 4 6
do
NET_IF="${NET_IF}${IPV%4}"
NET_FIF="${NET_FIF}${IPV%4}"
NET_FIF_1="${NET_FIF_1}${IPV%4}"
eval network_get_device NET_DEV "${NET_IF}"
eval network_get_gateway${IPV%4} NET_GW "${NET_IF}"
if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_IF}" &> /dev/null
then
NET_RT="${NET_IF}"
else
# If 'wan' fails, check 'wan2'
eval network_get_device NET_DEV "${NET_FIF}"
eval network_get_gateway${IPV%4} NET_GW "${NET_FIF}"
if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_FIF}" &> /dev/null
then
NET_RT="${NET_FIF}"
else
echo "All WAN interfaces have failed"
# You can add further handling here if all WAN interfaces fail.
# For now, NET_RT will stay as 'wan3' since that's the last option.
fi
fi
echo "'${NET_RT}'"
echo "uci set network.default${IPV%4}.lookup='${NET_RT}'"
uci set network.default${IPV%4}.lookup="${NET_RT}"
/etc/init.d/network reload
done
the metric affects the speed, so set 0 and 1 in the interface settings, 0 is the highest priority.
no need to set 10 or 20, may reduce connection speed
To be clear (and for anyone else viewing this thread later) setting a metric doesn't directly affect connection speeds at all. Giving a lower speed connection at lower metric (i.e. higher priority) will lead to you having a 'slower' connection, but that is an indirect effect. You can freely use 10, 20, 30, (or higher numbers) as metric scores without any impact on the connection itself.
1.WiFi will take highest priority from eth1 and USB0 when wifi client will connect in between dual WAN fail over script will run.
2. I am using OPENWRT 17.01 LEDE. So, can i use mwan3 latest package?
Please let me know.
my dual wan backup script...
NET_IF="wan2"
PING_IP_IF="8.8.8.8"
NET_FIF="wan"
PING_IP_FIF="8.8.8.8"
. /lib/functions/network.sh
network_flush_cache
for IPV in 4 6
do
NET_IF="${NET_IF}${IPV%4}"
NET_FIF="${NET_FIF}${IPV%4}"
NET_FIF_1="${NET_FIF_1}${IPV%4}"
eval network_get_device NET_DEV "${NET_IF}"
eval network_get_gateway${IPV%4} NET_GW "${NET_IF}"
if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_IF}" &> /dev/null
then
NET_RT="${NET_IF}"
else
# If 'wan' fails, check 'wan2'
eval network_get_device NET_DEV "${NET_FIF}"
eval network_get_gateway${IPV%4} NET_GW "${NET_FIF}"
if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_FIF}" &> /dev/null
then
NET_RT="${NET_FIF}"
else
echo "All WAN interfaces have failed"
# You can add further handling here if all WAN interfaces fail.
# For now, NET_RT will stay as 'wan3' since that's the last option.
fi
fi
echo "'${NET_RT}'"
echo "uci set network.default${IPV%4}.lookup='${NET_RT}'"
uci set network.default${IPV%4}.lookup="${NET_RT}"
/etc/init.d/network reload
done
The current MWAN with netifd implementation loops trough the list of interfaces specified in the relevant network config section and checks connectivity to their gateways.
When it receives a positive reply, the respective interface is used for default routing and the rest of the list is ignored, so the higher the position in the list, the higher the routing priority.