This is an old revision of the document!
Dual WAN with netifd
Introduction
- This instruction configures dual WAN with netifd on OpenWrt.
- Enable IPv6 NAT or NPT and disable IPv6 source filter if necessary.
- Follow PBR with netifd for setting up PBR.
Features
- Implement dual WAN based on PBR with netifd.
- Perform connectivity check with ICMP and ICMPv6.
- Provide a simple failover method.
- Support dual-stack setups.
Command-line instructions
Assuming pre-configured upstream interfaces wana and wanb.
Set up PBR with netifd.
Save the failover script.
Configure cron to run the failover script.
# Configure network cat << EOF >> /etc/iproute2/rt_tables 1 wana 2 wanb EOF for IPV in 4 6 do uci set network.wana${IPV%4}.ip${IPV}table="wana" uci set network.wanb${IPV%4}.ip${IPV}table="wanb" uci -q delete network.default${IPV%4} uci set network.default${IPV%4}="rule${IPV%4}" uci set network.default${IPV%4}.lookup="wana" uci set network.default${IPV%4}.priority="80000" done uci commit network /etc/init.d/network restart # 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}" /etc/init.d/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 /etc/init.d/cron restart