TechInfoDepot:DD-WRT/Dual WAN with failover

This was tested on WRT54GL 1.1 with DD-WRT 2.4 mini.

What this setup will do
Create a second WAN port, so you can hook up another provider for backup, and will change the active provider to the secondary, if ping fails to the provider's gateway. It will ping in a predefined interval. If this is not what you need, then you might try:
 * Dual-WAN for simple round-robin load equalization - explains how you can load balance between two WAN connections
 * Dual WAN with one as standby backup - Explains how to set up a secondary WAN connection for backup

Creating a second VLAN
You'll need to create a new VLAN, called vlan2. Enter in the web interface, Settings/VLANs. Set Port 4 to a new VLAN. Enter in the console, and do the following commands

Commands to set VLANs
On a WRT54GL this will be port 4, if you want port 1 for vlan2 then set vlan2ports to "3 5".

Setting up the scripts
We'll have some scripts, which will go in /jffs/etc/config.

wan2up.startup
Now this is for static IP, but you can change this situation by modifying the script for udhcpc

Setting up the scripts responsible for switching to a specific WAN
This file makes the changes necessary to activate WAN1. Change the nameservers to your provider's DNS servers or OpenDNS's.

wan1.up
As you probably already figured out, this will make the changes necessary to activate WAN2 :)

Setting up the actual failover script
Now, this is the core of our goal, this script will monitor the active connection, and if connection fails, it will call one of wan1.up or wan2.up to change the active connection.

Optionally add automatic switching back to WAN1 once it becomes available
When WAN2 is in use as the active WAN port the script will check the status of WAN1 at the regular interval and switch back to it when it becomes available. Useful if WAN2 is a slower or paid-use connection. Add these lines to failover.startup just before the last line (done;).

Setting up the script responsible for the Easy Setup button
Optionally, if you want to be able to switch the active WAN port with the Easy Setup button, you can add:

Final polishing
Create above files in /jffs/etc/config and then do a

If you made everything as written above right, you should reboot the router and enjoy!