I found this post. So I try all commands (I'm not sure I understand everything) :
Quote:
swconfig dev switch0 set reset 1
swconfig dev switch0 set enable_vlan 1
swconfig dev switch0 vlan 1 set ports "5t 0 1 2 3"
swconfig dev switch0 vlan 2 set ports "5t 4"
swconfig dev switch0 set apply
ifconfig eth0 up
ifconfig eth1 up
vconfig set_name_type VLAN_PLUS_VID_NO_PAD
vconfig add eth0 1
vconfig add eth0 2
# Set nvram values
nvram set wan_ifname=$WAN1_IFNAME
nvram set wan_ipaddr=$WAN1_IPADDR
nvram set wan_gateway=$WAN1_GATEWAY
nvram set wan_netmask=$WAN1_NETMASK
nvram set wan2_ifname=$WAN2_IFNAME
nvram set wan2_ipaddr=$WAN2_IPADDR
nvram set wan2_gateway=$WAN2_GATEWAY
nvram set wan2_netmask=$WAN2_NETMASK
nvram commit
# Source https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1003853#1003853
# and https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=317199
swconfig dev switch0 set reset 1
swconfig dev switch0 set enable_vlan 1
swconfig dev switch0 vlan 1 set ports "5t 4"
swconfig dev switch0 vlan 2 set ports "5t 3"
swconfig dev switch0 vlan 3 set ports "6t 0 1 2"
swconfig dev switch0 set apply
vconfig set_name_type VLAN_PLUS_VID_NO_PAD
vconfig add eth0 1
vconfig add eth0 2
vconfig add eth1 3
ifconfig $WAN1_IFNAME up $WAN1_IPADDR netmask $WAN1_NETMASK
ifconfig $WAN2_IFNAME up $WAN2_IPADDR netmask $WAN2_NETMASK
ifconfig $LAN_IFNAME up $LAN_IPADDR netmask $LAN_NETMASK
iptables -t nat -A POSTROUTING -o $WAN1_IFNAME -j MASQUERADE
iptables -t nat -A POSTROUTING -o $WAN2_IFNAME -j MASQUERADE
# Failover
logger "failover : active WAN1"
/jffs/etc/config/wan1.up
while sleep $INTERVAL
do
# Try to figure out the current route
TARGET=`ip route | awk '/default via/ {print $3}'`
# Set the variable, so let the script now which connection is it dealing with
if [ "$WAN1_GATEWAY" = "$TARGET" ]; then
USINGWAN=1
elif [ "$WAN2_GATEWAY" = "$TARGET" ]; then
USINGWAN=2
fi
# We'll ping as many times the $PACKETS variable tells, and test if we have connection:
RET=`ping -c $PACKETS $TARGET 2>/dev/null | awk '/packets received/ {print $4}'`
# If we don't have connection, change the active WAN port (If there is any loss with multiple packets, it should change either)
if [ "$RET" -ne "$PACKETS" ]; then
if [ "$USINGWAN" = "1" ]; then
logger "failover : change active WAN port to 2"
/jffs/etc/config/wan2.up
else
logger "failover : change active WAN port to 1"
/jffs/etc/config/wan1.up
fi
fi
# Automatic switching back to WAN1 once it becomes available
if [ "$USINGWAN" = "2" ]; then
RET=`ping -c $PACKETS $WAN1_GATEWAY 2>/dev/null | awk '/packets received/ {print $4}'`
if [ "$RET" -eq "$PACKETS" ]; then
logger "failover : switch back to WAN1"
/jffs/etc/config/wan1.up
fi
fi
done
/jffs/etc/config/wan1.up
Code:
#!/bin/sh
# WAN1
DEV=`nvram get wan_ifname`
GATEWAY=`nvram get wan_gateway`
DNS1=192.168.1.1
ip route delete default
ip route add default via $GATEWAY dev $DEV