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"
. /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}"
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}" "${NET_GW}" &> /dev/null
then NET_RT="${NET_IF%6}"
else NET_RT="${NET_FIF%6}"
fi
uci set network.default${IPV%4}.lookup="${NET_RT}"
service network reload
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/11/10 08:31
  • by vgaetera