GUIDE: DHCP Dual-WAN with Failover for Linksys WRT310N v2

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
JMVS
DD-WRT Novice


Joined: 27 Nov 2009
Posts: 18

PostPosted: Thu May 03, 2012 1:00    Post subject: GUIDE: DHCP Dual-WAN with Failover for Linksys WRT310N v2 Reply with quote
Hello Everyone,

I spent a few weeks reading all the Dual-Wan wikis and threads and finally came up with a working solution for my Linksys WRT310N v2. I wanted to have my main 30Mbit connection always online and fallback to my 1Mbit when something goes wrong and back to main as soon as it becomes available again. The wiki guide Dual WAN with failover was a good place to start but I needed DHCP for the second WAN (Dynamic IP).

In this guide I'm assuming you already have JFFS up and running. The version of DD-WRT I'm using is DD-WRT v24-sp2 (12/18/10) mini (SVN revision 15940). Make sure is the mini version as is the only one that will let you create some JFFS space.

To simplify the process I did not use the DNSes provided by the ISPs but public instead. This way I do not have to worry about changing the DNSes everytime the connection is changed. To be able to do this you only need to go to Configuration > Basic in the WebGUI and fill in the three Static DNS 1/2/3. In my case I used:
  • Static DNS 1: 8.8.8.8 (Google Public DNS)
  • Static DNS 2: 8.8.4.4 (Google Public DNS)
  • Static DNS 3: 208.67.222.222 (OpenDNS)

Here are the steps I used:

  1. Telnet/SSH into the router and issue these commands:
    Code:
    nvram set vlan2ports="0 8"
    nvram set vlan3ports="1 8"
    nvram set vlan3hwname=et0
    nvram commit

    This will turn port 4 (port 1 internally) into a WAN connection.
  2. Go to the /jffs dir and create new "scripts" dir:
    Code:
    cd /jffs
    mkdir scripts
    cd scripts

  3. Download the scripts:
    Code:
    wget -O failover.dw http://pastebin.com/download.php?i=vRMe4LtS
    wget -O udhcpc-wan2.script http://pastebin.com/download.php?i=vRHgGdNH

    You can obviously see the source code for failover.dw here and for udhcpc-wan2.script here.
  4. Set the execute permissions for the scripts:
    Code:
    chmod +x /jffs/scripts/*

  5. Create the appropiate entries in the WebGUI for the scripts to run at startup:
    Go to Administration > Diagnostics and copy & pase in the Commands box:
    Code:
    sleep 5
    udhcpc -i vlan3 -p /var/run/udhcpc-wan2.pid -s /jffs/scripts/udhcpc-wan2.script
    sleep 10
    /jffs/scripts/failover.dw

    Click "Save Startup"
    Then copy & paste the following into the same Commands box:
    Code:
    iptables -t nat -A POSTROUTING -o vlan3 -j MASQUERADE

    Now click "Save Firewall"
  6. That's it! Plug in the 2nd WAN into Port 4, reboot the router and everything should be working.

A couple of notes:
  • If you have syslogd running you'll see that the script outputs it state there (useful to see if everything is working as it should)

  • Another way of checking if the WAN switching is working is looking at the small LED (I think is called WPS status led) in the center of the router. It will be off whilst the router is starting up and then orange when the router finished loading. Then after checking which conection is running it will turn blue for WAN 1 or violet for WAN 2 (this only works for the WRT310N v2)

  • Please be aware that in this router we use vlan2 and vlan3 (useful if you're testing other scripts uwing vlan1 and vlan2)

  • If you edit the scripts in Windows, please make sure you save the scripts in Unix mode (if you don't know how to do this, you should probably don't try to edit the scripts)

  • Port Forwarding will not work on WAN 2 (if anyone knows how to do it, please let me know)

  • DDNS will not refresh on WAN 2 (if anyone knows how to do it, please let me know. I think I have to use INADYN but not sure how and I don't want to abuse the service and get banned)


That's all. Please note that I'm no expert in this so I won't be able to provide much support if this does not work for you. Please understand.

Bye.
Sponsor
Patrice Tremblay
DD-WRT Novice


Joined: 09 Apr 2009
Posts: 16

PostPosted: Sat May 11, 2013 12:22    Post subject: Reply with quote
Nice job. Thanks for sharing!

About ddns, i think it's not really a problem if you run the client on a device in your network, it will update it probably faster again than using ddwrt delay that is hours if i remember well.

About port forwarding, it could be really nice if someone have a solution for it because my goal is to have a backup connection for a server. without port forwarding it's impossible.


Thanks again for sharing and i hope someone will bring a solution for that port forwarding on wan2.
mrenglishman
DD-WRT Novice


Joined: 19 Oct 2012
Posts: 16

PostPosted: Tue Dec 01, 2015 20:50    Post subject: Reply with quote
Stumbled upon this thread as I was investigating for a similar solution. Many thanks JMVS for this!

I have one particular question though that I would kindly like to request some help on:

Let's assume that it is not possible to plug in the second WAN DIRECTLY to port 4 of the DD-WRT router, due to the location that the secondary "source" needs to be placed (think of a 3G/4G router that needs to be close to a window for optimum reception).

The second WAN device will be in bridge mode and have a local IP. It will be hooked up on a switch, meaning that it will "exist" in the LAN, but again NOT directly plugged in the DD-WRT router.

Is there a way to tweak the suggested config to "seek" the secondary WAN (through port 4) in the network by the 3G router's local IP or MAC address?

Thanks in advance!
JMVS
DD-WRT Novice


Joined: 27 Nov 2009
Posts: 18

PostPosted: Wed Dec 02, 2015 0:04    Post subject: Reply with quote
mrenglishman wrote:
Stumbled upon this thread as I was investigating for a similar solution. Many thanks JMVS for this!

I have one particular question though that I would kindly like to request some help on:

Let's assume that it is not possible to plug in the second WAN DIRECTLY to port 4 of the DD-WRT router, due to the location that the secondary "source" needs to be placed (think of a 3G/4G router that needs to be close to a window for optimum reception).

The second WAN device will be in bridge mode and have a local IP. It will be hooked up on a switch, meaning that it will "exist" in the LAN, but again NOT directly plugged in the DD-WRT router.

Is there a way to tweak the suggested config to "seek" the secondary WAN (through port 4) in the network by the 3G router's local IP or MAC address?

Thanks in advance!


It's been a long time since I posted this...

To try to answer your question, I believe if the switch/router does deliver an IP address through DHCP this config should work (given that the switch/router combo works correctly).

As long as the device hooked up to the "WAN2" can deliver it's own IP address via DHCP and get a connection from the Internet you should be fine.

Hope this helps.
mrenglishman
DD-WRT Novice


Joined: 19 Oct 2012
Posts: 16

PostPosted: Wed Dec 02, 2015 0:15    Post subject: Reply with quote
Thanks for the fast reply!

What if I want to keep the main ddwrt router to do dhcp on the entire network? What I'm basically looking to do is change the default route that the main ddwrt router has to point to the secondary router in order to distribute internet access to the entire LAN. When the main WAN connection is back up, switch back to that.

Example:

ISP Modem: 192.168.1.1
DDWRT Router: 192.168.1.2 with WAN connecting through PPPoE to the modem
Secondary 3G Router: 192.168.1.10

Once the PPPoE WAN connection to 192.168.1.1 fails, then the DDWRT router should switch to using 192.168.1.10 as its gateway -- then switch back when the WAN connection is back up.
JMVS
DD-WRT Novice


Joined: 27 Nov 2009
Posts: 18

PostPosted: Thu Dec 03, 2015 1:10    Post subject: Reply with quote
mrenglishman wrote:
Thanks for the fast reply!

What if I want to keep the main ddwrt router to do dhcp on the entire network? What I'm basically looking to do is change the default route that the main ddwrt router has to point to the secondary router in order to distribute internet access to the entire LAN. When the main WAN connection is back up, switch back to that.

Example:

ISP Modem: 192.168.1.1
DDWRT Router: 192.168.1.2 with WAN connecting through PPPoE to the modem
Secondary 3G Router: 192.168.1.10

Once the PPPoE WAN connection to 192.168.1.1 fails, then the DDWRT router should switch to using 192.168.1.10 as its gateway -- then switch back when the WAN connection is back up.


If what you need is static IP then it gets easier, I think you should look in the Wiki to see example scripts then modify or directly use those.
mrenglishman
DD-WRT Novice


Joined: 19 Oct 2012
Posts: 16

PostPosted: Thu Dec 03, 2015 16:18    Post subject: Reply with quote
So how do I ensure that the main router (192.168.1.1) will continue doing the dhcp for all the clients in the LAN? Is this unaffected? The secondary router will of course have a static IP.

I think my questions boils down to "is the secondary WAN port "assignment" tied to the PHYSICAL port and ONLY the device connected DIRECTLY to that port, or is it a combination of physical port on primary router + IP address of secondary router" ?
Steef
DD-WRT Novice


Joined: 15 Apr 2021
Posts: 2

PostPosted: Thu Apr 15, 2021 18:14    Post subject: Reply with quote
Hello everyone,
Thank you ver much JMVS and others for sharing your experience with us. Good to know that there is a lot possible.

I have a few questions however.
Let me make clear my situation.
I own a Linksys E4200 router with DD-WRT firmware. I live abroad and internet here is not very stable. Therefor I have a 4G internetrouter and a WiMax receiver. The latter is connected to the E4200. Since WiMax stops quite a few times a day I would like to add de 4G Vodafone router as a Wan as well.
I consider myself a little bit a noob (but not that much). However it is very difficult to 'let it all work'. I have tried a few times, but everything stops working and I have to return to my basic config. For that I saved nvram.bak. That leads me to my first question:
1. For me loading nvram.bak does NOTHING. It does not take me back to my saved config. Is there something I do wrong. Is there more to it than save and restore? I lose almost all of my settings. All Macs with static IP-adresses and Wifi settings is quite some work since I have more or less 40 devices connected.

2. Is there some sort of standard config for dual-wan ready to use? A complete nvram.bak to restore to for standard DUAL-WAN where only little settings have to be set?

I really hope someone can help me and lots of other people as well with an answer of both questions above.

Thanks very much in advance!
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14125
Location: Texas, USA

PostPosted: Thu Apr 15, 2021 18:45    Post subject: Reply with quote
https://wiki.dd-wrt.com/wiki/index.php/Category:Dual_WAN

Also, dependent on browser, etc. and which build you're running, nvram backup may not work as expected. I personally have not had issue with it, but my magic crystal ball has not one clue what build your running on your E4200 or what browser you're using.

Please read all the announcements and stickies, forum rules and guidelines.

_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
Steef
DD-WRT Novice


Joined: 15 Apr 2021
Posts: 2

PostPosted: Fri Apr 16, 2021 8:10    Post subject: Reply with quote
kernel-panic69 wrote:
https://wiki.dd-wrt.com/wiki/index.php/Category:Dual_WAN

Also, dependent on browser, etc. and which build you're running, nvram backup may not work as expected. I personally have not had issue with it, but my magic crystal ball has not one clue what build your running on your E4200 or what browser you're using.

Please read all the announcements and stickies, forum rules and guidelines.


Thank you kernel-panic69 for going into my first question.
I am sorry for being incomplete.
I'm normally using Firefox v87.0 at the time, usually periodic updated.
My Firmware is: DD-WRT v3.0-r30880 mega (11/14/16). Furthermore, I am not 100% sure, but I think I used at the time this file:
dd-wrt.v24-30880_NEWD-2_K2.6_mega-nv60k.bin

Of course I have read the wiki, but it is of course not specifically written for E4200 so I am not sure if there would be a difference.
Furthermore I see there is a fixed WAN IP where 4G does not have one.
What my question is would there at any time be a GUI where dual WAN could be implemented or if not is there somebody out there who for me (and maybe a lot others) is able to put the scripts in a nvram.bak or sort of autoconfig file, which I can 'restore' to? I would really appreciate that (more than) a lot!
And if that would not be possible, maybe it is possible to have an even more specific wiki to it, where every, for pro's maybe logical steps are pointed out.
Thank you so much for reading my post.
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14125
Location: Texas, USA

PostPosted: Fri Apr 16, 2021 14:04    Post subject: Reply with quote
I believe the webUI feature was requested some time ago, but it's never happened, thus the wikis and processes to enable it. I can only guess why you're still on 30880 K2.6 (outdated information thanks to Steve Jenkins). You can either upgrade to the most recent K2.6 release or cross over to K3.x. Best bet is to search the forum for my post(s) about the upgrade process as K3.x is now K4.x and I doubt any wikis have been updated.
_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum