This is an old revision of the document!


Dual WAN with netifd

  • Implement dual WAN based on PBR with netifd.
  • Perform connectivity check with ICMP and ICMPv6.
  • Provide a simple failover method.
  • Support dual-stack setups.

Assuming pre-configured upstream interfaces wana and wanb. Set up PBR with netifd using PBR extras. Save the failover script and assign the main and fallback interfaces. Configure cron to run the failover script.

# Failover script
cat << "EOF" > /root/2wan.sh
NET_IF="wana"
NET_FIF="wanb"
NET_IF6="${NET_IF}6"
. /lib/functions/network.sh
network_flush_cache
network_get_device NET_DEV "${NET_IF}"
network_get_device NET_DEV6 "${NET_IF6}"
network_get_gateway NET_GW "${NET_IF}"
network_get_gateway6 NET_GW6 "${NET_IF6}"
for IPV in 4 6
do if ping -q -c 3 -w 5 -I \
"$(eval echo \${NET_DEV${IPV%4}})" \
"$(eval echo \${NET_GW${IPV%4}})" &> /dev/null
then NET_RT="${NET_IF}"
else NET_RT="${NET_FIF}"
fi
NET_CRT="$(uci -q get network.default${IPV%4}.lookup)"
if [ "${NET_RT}" != "${NET_CRT}" ]
then logger -t 2wan "Switching to ${NET_RT}"
uci set network.default${IPV%4}.lookup="${NET_RT}"
service network reload
fi
done
EOF
cat << "EOF" >> /etc/sysupgrade.conf
/root/2wan.sh
EOF
 
# Configure cron
cat << "EOF" >> /etc/crontabs/root
* * * * * . /root/2wan.sh
EOF
uci set system.@system[0].cronloglevel="9"
uci commit system
service cron restart
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2023/10/14 05:34
  • by vgaetera