Dual WAN with one as standby backup
From DD-WRT Wiki
Revision as of 13:43, 30 November 2006 (edit) Akmits (Talk | contribs) (→Ctreate scripts to do the connection switch) ← Previous diff |
Current revision (17:57, 18 March 2018) (edit) (undo) Ian5142 (Talk | contribs) (Changed Category to Dual WAN) |
||
(13 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
- | + | article need of major revision - one with dual wan as backup another simple round equalization | |
This tutorial explains how you can assign one (or more) of the LAN ports | This tutorial explains how you can assign one (or more) of the LAN ports | ||
as an extra WAN port. There is another tutorial | as an extra WAN port. There is another tutorial | ||
- | [[Dual- | + | [[Dual-WAN for simple round-robin load equalization]] |
which explains how you can load balance between the two WAN connections. | which explains how you can load balance between the two WAN connections. | ||
In this case I did not want to load balance; but rather create a standby WAN | In this case I did not want to load balance; but rather create a standby WAN | ||
connection. | connection. | ||
- | + | == Justification == | |
I needed to configure backup WAN as standby as it is not an unlimited | I needed to configure backup WAN as standby as it is not an unlimited | ||
connection. I pay for the backup connections by Giga-Bytes used. My primary | connection. I pay for the backup connections by Giga-Bytes used. My primary | ||
Line 14: | Line 14: | ||
the primary one goes down. | the primary one goes down. | ||
- | + | == Assumptions == | |
I have assumed static IP addresses for both the WAN interfaces. Making them | I have assumed static IP addresses for both the WAN interfaces. Making them | ||
- | dynamic will require some changes (hint nvram set wan2_proto=dynamic) | + | dynamic will require some changes (hint: <code>nvram set wan2_proto=dynamic</code>) |
Also, I am assuming DNSMasq is used for DHCP and DNS. JFFS should be enabled | Also, I am assuming DNSMasq is used for DHCP and DNS. JFFS should be enabled | ||
if you want to save the WAN-connection switch scripts. Also, I am assuming that you | if you want to save the WAN-connection switch scripts. Also, I am assuming that you | ||
Line 23: | Line 23: | ||
or web interface. | or web interface. | ||
- | + | == Create an extra VLAN == | |
First you need to create an extra VLAN. In this case we want to to remove | First you need to create an extra VLAN. In this case we want to to remove | ||
the port 4 from vlan0 and add it to the new vlan2 | the port 4 from vlan0 and add it to the new vlan2 | ||
- | nvram set vlan0ports="1 2 3 5*" | + | nvram set vlan0ports="1 2 3 5*" |
- | nvram set vlan2ports="4 5" | + | nvram set vlan2ports="4 5" |
- | nvram set vlan2hwname=et0 | + | nvram set vlan2hwname=et0 |
- | nvram set wan2_ifnames=vlan2 | + | nvram set wan2_ifnames=vlan2 |
- | nvram set wan2_ifname=vlan2 | + | nvram set wan2_ifname=vlan2 |
- | nvram set wan2_mtu=1500 | + | nvram set wan2_mtu=1500 |
- | nvram commit | + | nvram commit |
You can confirm or perform the setting using the dd-wrt web interface | You can confirm or perform the setting using the dd-wrt web interface | ||
Line 41: | Line 41: | ||
Now you have created an extra VLAN (vlan2). | Now you have created an extra VLAN (vlan2). | ||
- | + | == Bring up the vlan2 interface == | |
I found it easier to configure the interface using ifconfig in the startup script. | I found it easier to configure the interface using ifconfig in the startup script. | ||
Somehow nvram bindings for backup WAN interface IP address did not work. ifconfig | Somehow nvram bindings for backup WAN interface IP address did not work. ifconfig | ||
Line 62: | Line 62: | ||
http://your_router_ip/Diagnostics.asp | http://your_router_ip/Diagnostics.asp | ||
- | + | Of course you will need a reboot for this to be effective. | |
- | + | == Configure NAT on vlan2 == | |
We want to make sure packets leaving vlan2 are NATed | We want to make sure packets leaving vlan2 are NATed | ||
Line 72: | Line 72: | ||
' | ' | ||
</pre> | </pre> | ||
- | Again the same Diagnostics.asp page can be used on the web interface | ||
+ | Again, the same Diagnostics.asp page can be used on the web interface. | ||
- | == | + | == Create scripts to do the connection switch == |
We switch the internet connection by switching the default route and DNS servers. | We switch the internet connection by switching the default route and DNS servers. | ||
- | Here we will create | + | Here we will create two scripts in /jffs to switch from one WAN connection to the other. |
- | to the other | + | |
- | + | === Script to switch to wan1 === | |
- | + | Put this in <code>/jffs/activate.wan1</code>: | |
<pre> | <pre> | ||
#!/bin/ash | #!/bin/ash | ||
Line 92: | Line 91: | ||
echo "nameserver 10.10.1.10" > /tmp/resolv.dnsmasq | echo "nameserver 10.10.1.10" > /tmp/resolv.dnsmasq | ||
echo "nameserver 10.10.1.11" >> /tmp/resolv.dnsmasq | echo "nameserver 10.10.1.11" >> /tmp/resolv.dnsmasq | ||
- | pr="$(ps | + | pr="$(ps | awk '/dnsmasq/ {print $1}')" |
kill -9 $pr | kill -9 $pr | ||
- | dnsmasq --conf-file /tmp/dnsmasq.conf | + | dnsmasq --conf-file /tmp/dnsmasq.conf |
</pre> | </pre> | ||
+ | |||
Used kill -9; because not sure why -1 (HUP) didnt work. | Used kill -9; because not sure why -1 (HUP) didnt work. | ||
- | Obviously 10.10.1.10 and 10.10.1.11 are DNS servers for WAN1 and 10.10.1.1 is the default gateway. Replace these values with your own settings for WAN1 | + | Obviously 10.10.1.10 and 10.10.1.11 are DNS servers for WAN1 and 10.10.1.1 is the default gateway. Replace these values with your own settings for WAN1. |
- | + | === Script to switch to wan2 === | |
- | < | + | And put this in <code>/jffs/activate.wan2</code>: |
- | #!/bin/ash | + | |
+ | <pre>#!/bin/ash | ||
nvram set wan_dns="10.10.2.10 10.10.2.11" | nvram set wan_dns="10.10.2.10 10.10.2.11" | ||
route delete default | route delete default | ||
Line 114: | Line 115: | ||
dnsmasq --conf-file /tmp/dnsmasq.conf & | dnsmasq --conf-file /tmp/dnsmasq.conf & | ||
</pre> | </pre> | ||
- | Obviously 10.10.2.10 and 10.10.2.11 are DNS servers for WAN1 and 10.10.2.1 is the default gateway. Replace these values with your own settings for WAN1 | ||
- | + | Obviously 10.10.2.10 and 10.10.2.11 are DNS servers for WAN2 and 10.10.2.1 is the default gateway. Replace these values with your own settings for WAN2. | |
- | + | You can switch connection by running the respective script. | |
- | # Automation of connection | + | |
+ | Connect the cable | ||
+ | |||
+ | Connect the backup WAN cable to the ethernet port marked as "4" and reboot. | ||
+ | == More to come == | ||
+ | |||
+ | # Automation of connection switching with email notification | ||
# Web interface to monitor and switch connection | # Web interface to monitor and switch connection | ||
+ | |||
+ | == See also == | ||
+ | * [[Dual-WAN for simple round-robin load equalization]] | ||
+ | * [[Dual WAN with failover]] | ||
+ | |||
+ | [[Category:Dual WAN]] |
Current revision
article need of major revision - one with dual wan as backup another simple round equalization
This tutorial explains how you can assign one (or more) of the LAN ports as an extra WAN port. There is another tutorial Dual-WAN for simple round-robin load equalization which explains how you can load balance between the two WAN connections. In this case I did not want to load balance; but rather create a standby WAN connection.
Contents |
[edit] Justification
I needed to configure backup WAN as standby as it is not an unlimited connection. I pay for the backup connections by Giga-Bytes used. My primary WAN connection is of unlimited type. I intend to switch to backup only when the primary one goes down.
[edit] Assumptions
I have assumed static IP addresses for both the WAN interfaces. Making them
dynamic will require some changes (hint: nvram set wan2_proto=dynamic
)
Also, I am assuming DNSMasq is used for DHCP and DNS. JFFS should be enabled
if you want to save the WAN-connection switch scripts. Also, I am assuming that you
have already configured the first WAN connection (tied to vlan1) using nvram
or web interface.
[edit] Create an extra VLAN
First you need to create an extra VLAN. In this case we want to to remove the port 4 from vlan0 and add it to the new vlan2
nvram set vlan0ports="1 2 3 5*" nvram set vlan2ports="4 5" nvram set vlan2hwname=et0 nvram set wan2_ifnames=vlan2 nvram set wan2_ifname=vlan2 nvram set wan2_mtu=1500 nvram commit
You can confirm or perform the setting using the dd-wrt web interface
http://your_router_ip/Vlan.asp
Now you have created an extra VLAN (vlan2).
[edit] Bring up the vlan2 interface
I found it easier to configure the interface using ifconfig in the startup script. Somehow nvram bindings for backup WAN interface IP address did not work. ifconfig does the job though.
nvram set rc_startup=' #!/bin/ash PATH="/sbin:/usr/sbin:/bin:/usr/bin:${PATH}" ifconfig vlan2 10.10.2.209 netmask 255.255.255.0 ifconfig vlan2 up '
Replace 10.10.2.209 with your WAN2 IP address
You can also perform this operation via the web interface
http://your_router_ip/Diagnostics.asp
Of course you will need a reboot for this to be effective.
[edit] Configure NAT on vlan2
We want to make sure packets leaving vlan2 are NATed
nvram set rc_firewall=' iptables -t nat -A POSTROUTING -o vlan2 -j MASQUERADE '
Again, the same Diagnostics.asp page can be used on the web interface.
[edit] Create scripts to do the connection switch
We switch the internet connection by switching the default route and DNS servers.
Here we will create two scripts in /jffs to switch from one WAN connection to the other.
[edit] Script to switch to wan1
Put this in /jffs/activate.wan1
:
#!/bin/ash nvram set wan_dns="10.10.1.10 10.10.1.11" route delete default route delete default route add default gw 10.10.1.1 vlan1 echo "nameserver 10.10.1.10" > /tmp/resolv.dnsmasq echo "nameserver 10.10.1.11" >> /tmp/resolv.dnsmasq pr="$(ps | awk '/dnsmasq/ {print $1}')" kill -9 $pr dnsmasq --conf-file /tmp/dnsmasq.conf
Used kill -9; because not sure why -1 (HUP) didnt work.
Obviously 10.10.1.10 and 10.10.1.11 are DNS servers for WAN1 and 10.10.1.1 is the default gateway. Replace these values with your own settings for WAN1.
[edit] Script to switch to wan2
And put this in /jffs/activate.wan2
:
#!/bin/ash nvram set wan_dns="10.10.2.10 10.10.2.11" route delete default route delete default route add default gw 10.10.2.1 vlan2 echo "nameserver 10.10.2.10" > /tmp/resolv.dnsmasq echo "nameserver 10.10.2.11" >> /tmp/resolv.dnsmasq pr="$(ps | grep dnsmasq | grep -v grep| awk '{print $1}')" kill -9 $pr dnsmasq --conf-file /tmp/dnsmasq.conf &
Obviously 10.10.2.10 and 10.10.2.11 are DNS servers for WAN2 and 10.10.2.1 is the default gateway. Replace these values with your own settings for WAN2.
You can switch connection by running the respective script.
Connect the cable
Connect the backup WAN cable to the ethernet port marked as "4" and reboot.
[edit] More to come
- Automation of connection switching with email notification
- Web interface to monitor and switch connection