by March 3, 2011 0 comments



Seeing your Internet connection dead at 3 am in the morning, just when the last section of the Torrent download is left, is extremely frustrating. Additionally, if you do not want to re-wire your network, setting up a second Internet connection is almost impossible. The only way you achive this is by buying expensive routers, which have 2 WAN ports and 3-4 LAN ports. Well the good news is, that most of the routers that we purchase, Buffalo, Linksys, and D-Link, already have the desired hardware to do so and this article shows how to use the Rs. 2,000 – Rs. 5,000 router and get the functionality of costlier routers in the range of Rs. 50,000 to Rs. 1,50,000.

Check your router for dd-wrt software support at http://ld2.in/1a6.

Loading the firmware

The stock firmware that comes bundled on these home routers, are not capable of doing any of this — the hardware swapping etc. So as a first step, one needs to replace the existing firmware of your router to a firmware that supports it. DD-wrt, Tomato, Open-wrt are some of the popular known firmware that help you achieve this. The actual loading of the firmware on your router is beyond the scope of this article but, you can find some excellent tutorials on the link pointed above, to install a new firmware for your router. For our discussion sake, we will assume that we are using DD-WRT latest firmware. It is also a good time to share with you that, by uploading a different firmware than your normal stock firmware, you will most likely void any warranty that the manufacturer may provide you. Hence pause and think, before you proceed to load the new firmware. If you ‘brick’ your router, chances are you will not be able to recover it.
Learn to install dd-wrt firmware on your router at http://ld2.in/1a7.




To-dos, before you get to dual-WAN

For our discussion let us assume that your LAN subnet is 192.168.1.x, and the router itself is configured for 192.168.1.1, with a subnet mask of 255.255.255.0. Rather rhetorical, but one needs to have two WAN links atleast to make this work. Once again, for the current discussion, we will assume that both these networks acquire their IP address through DHCP on the Internet link. One important gotcha that you need to be careful about is that these two networks cannot be on the same sub-net. So, just to be sure, ideal condition would be to use two DSL links from two different service providers.

A router should have atleast some free memory to be used for storing the code. Some of the routers that we tested like Buffalo WHR-HP-G54 and its family or Linksys 310N, 610N, 150N, are good candidates for this work. We shall be using Linksys 610N for our purposes. The next step is to identify which firmware pack would you be using as there are several types of firmware packs available, each optimised to fit into the size of free RAM available on your router.

We chose to use v24-sp2 std-usb.ftp. The advantage of using this hardware and firmware pack is the ability to mount the USB port (yes 610N comes with a USB port) as external disk — with virtually unlimited disk available. Choose the one that has CIFS support built in. Go to the admin page and enable jffs support. This will mount the available free RAM in the router as /jffs directory on the router. You can check, your available RAM on the router by going to the status page — in our case, http://192.168.1.1/ Status_ Router. asp.

Converting LAN port to WAN port

Using the webfrontend, go to the Setup/Vlans, and select WAN port (also known as port 5 and port 4 as a part of vlan2 port. Next, telnet into the router (yes DD-WRT actually allows you to telnet and/or ssh into it) and give the following commands.




The ‘nvram set’ directive sets the variables that define the port functionality. All we need to do is to tell this variable, which ports to use for LAN and which for WAN. The nvram commit command will write the configuration followed by a reboot to make the new setting effective.

At this point of time, you have actually converted your original WAN port and LAN port number 4, into WAN ports. However, the next step is to configure the same and make them usable.

Getting IP addresses for the WAN port

As a first step, we need to make sure, that both the interfaces, take dynamic IP address from the Internet connectivity. To achieve this, use the webfrontend to setup the WAN port to collect the dynamic IP. (Setup –> Basic setup –> WAN Connection type — Automatic Configuration — DHCP)

However for the second port, we will need to write a small script that collects the DHCP data from the Internet provider. A simplistic code snippet would look something like this:

This — and a bit of other things need to be saved in a file — on the /jffs directory. You can find a very detailed discussion on the above scripts at http://ld2.in/1a2 .

Follow the instructions there, and save the file in file /jffs/scripts/ uDHCPc-vlan2.script — change the permissions to execute by giving the command: chmod 755 /jffs/scripts/ uDHCPc-vlan2.script

Also, you would want add second line as backup to first to set this up, where you have a primary low cost link and a secondary link that is perhaps high cost, however, required to provide a backup to the first one. In this situation, you would use the first link normally and you would need to use the other link ONLY in case the first link is not usable, not otherwise. The steps required to do these tasks are:




1. Setting up your primary WAN port — you can use the web front-end or use the script as pointed to by the wikipedia page.
2. Setting up the secondary WAN port — if you have dynamic DHCP, you need to ue the script shown above, for permanent IP on secondary port use the script as referenced in the wikepedia page.
3. Actual fail-over script.
4. Optional — linking the failover script to a ses-button on your router. Many routers come with a switch and you can link, a script to be run, as soon as that switch is pressed. This is mighty useful, when you want make a switch from one WAN provider to another, by mere pressing of a switch on the router.

All of the above steps, with complete code is available at http://ld2.in/1a3 . Please also note, in our case, since we are not using any both-end concentrators, but a poor little home router, we DO NOT do a PACKET level load balancing but only a SESSION) level load balancing.

As explained, you will get combined bandwidth of both the links for torrent downloads and even web surfing and or mail flow. But may not get actual benefits on ftp download, or Youtube play, or a single session downloads. Given the fact that most of your bandwidth requirement is from websurfing, mail flow or torrents, this is a real powerful solution. Using two links of 2Mbps and 1.0Mbps, we were easily able to achieve a download speed upwards of 3.0Mbps on torrent downloads. At the core of the magic is the IP tables, command equalize. This single line is at the heart of all our load balancing steps.

In the above code snippet, you are adding a command that setsup the default route. However, in addition to this, it also instructs the router to use two links. It extracts the device name, by the nvram “get wan2_gateway” command and populates the other variables.

The interesting option in this is weight. Using load-balancing technique, you can not only load balance between the two links, but also instruct the script to use the weightage of each link — anywhere between 1-255. This is useful when you have two WAN links of different bandwidth — a 2Mbps and 1Mbps, then you would want to set the weights as above.




Download the code given at link http://ld2.in/1a8 and save the section on load balancing in a file /jffs/scripts/routes.firewall. Change mode to be executable for the file ‘routes.firewall’ using chmod 755 /jffs/scripts/routes.firewall

Setting firewall rules

Once the above setup is done, it will be imperative to define the firewall rules that allow you to set the right ports open for incoming and outgoing port.

This is achieved by a more general type of script, however you can once again download the script from this URL: http://ld2.in/1a8 under section firewall and name the script as advised to /jffs/scripts/firewall.firewall. Change the mode to executable chmod 755 /jffs/scripts/firewall.firewall.

Now that you have the three scripts ready. We need to find a way to make them run at the right time. For this DD-WRT offers inbuilt functionality. Use the web frontend, go to Administration –> Commands, and put the following in for startup (after you put the code, press on SAVE STARTUP):

Next do a similar thing for firewall

Click on save firewall and reboot your router to make the changes effective.

If you have done, everything correctly, you can now peacefully enjoy both the WAN link being utilized in a load balanced mode. As explained earlier try a few torrents, to check the net throughput you are achieving.

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

<