Load Balancing multiple Internet Connections

This is a topic much discussed in forums but leading to no solutions. The main problem with load balancing Internet connections is that every internet comes with its own ip address. This unique ip address is provided by your ISP. Your ip address is the unique distinguishing factor which is the reason why the request you sent is served back to you and not to anybody else. When you think of load balancing, the thought comes to your mind that both your internet link will be equally used to give redundancy and increased throughput. This can happen if half of the requests are sent through one link and the rest half through the other. This should cause the return traffic to be load balanced between your 2 internet connections.

Issues with Load balancing

The problem here lies with your ip address. Since you are having two internet connections, you are having 2 unique ip addresses. Whenever you will initiate a request towards the internet, a session between you and the destination host is formed. When you load balance, the next packet will have a source address of your other internet connection towards the destination host but now the destination host will not recognize you since you are coming from a different ip address. So technically “the only way” to load balance your internet would be to take 2 internet connections from a single ISP in which case your unique ip address will be the same. The closest way around it would be to use a concept of load sharing which shares your internet load across multiple internet connections session-wise but the load distribution will not be equal.

Techniques to Load Share

Appliance Based

This technique uses an appliance to do load sharing. The appliance can be as simple as a broadband router or as complex as a Link Proof which is meant for Data Centers and is meant for high availability.

1) Multi WAN RouterImage

These are SOHO Broadband routers which have multiple WAN ports which connect to multiple internet connections. The Internet is load shared based on sessions such that few sessions are sent through first internet connection and few sessions are sent through the other internet connections. This results in download traffic coming through both the internet connections. There are limitations to such devices such that not all devices are capable of load sharing. They merely act in active/failover modes which means not both the internet connections will be used at the same time, thus defeating the purpose.

2) Link Proof

Image

These appliances are not meant for the home users as these are very expensive and can get very granular with the configuration. These devices are used in Data Centers with high availability requirements. This appliance works similar to the multi WAN router except that it is not a router. The responsibility of this device is to send and receive traffic via the best path over the multiple links. This means the traffic will go over the link which will give low latency, low jitter and high throughput. The free bandwidth and cost of bandwidth will also be taken into consideration for deciding which link to use. There will be internet redundancy for the servers as well redundancy based on DNS as these devices act as DNS servers.

Host Based

This technique involves a setup on the host device like Laptop or Desktop. There are several ways Load Sharing can be enabled.

Windows 7 system: Load Sharing can be done through a VB Script. This technique involves changing the default gateway of the system so that when the load on the interface goes beyond 80%, the default gateway is automatically changed to the other so that the load is shifted to the other internet link. The caveat to this technique is that you must have the 2 internet on 2 different interfaces of the Laptop/Desktop.

This technique can be learnt from this youtube video

Mac OS X: Load sharing can be done through a paid software called ipnetrouterx. What this software does is distributes the sessions of the multiple internet links and also checks the reachability of the gateway so as to stop forwarding traffic over a failed link.

This technique can be learnt from the softwares website

In this blog, we will look into distributing the internet load over multiple broadband routers but through a very simple technique.

Implementation

The Basics

An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing. Its role has been characterized as follows: “A name indicates what we seek. An address indicates where it is. A route indicates how to get there.” The ip address scheme is divided into various classes for easy administration of networks. Three classes (A, B, and C) were defined for universal unicast addressing.

Classful network architecture

Class Leading bits in address (binary) Range of first octet (decimal)
A 0 0–127
B 10 128–191
C 110 192–223

According to this table, the whole ip address scheme can be roughly divided into 2 halves. The first half which has the first octet from 1-127 and the second half from 128-223. Beyond 223, multicast starts which has a range from 224-239 and in the end, there is a class E which is meant for experimental purposes. Our technique involves sending traffic to one half of the internet through one internet link and traffic for the other half of the internet through the other internet link.

The Setup

1) Cascading the Broadband RoutersImage

We must begin with setting up the routers so that one coherent LAN network is formed out of the 2 routers. This is done by making changes in the router so that the DHCP gives ip address in the same range from both the routers.ImageImage

First the Router ip address has to be changed to 192.168.1.1 for the first router and to 192.168.1.2 for the second router. After this, the DHCP pool on the first router has to be setup in the same ip range as set for the router ip address. This should be done automatically but must be confirmed nonetheless. After confirming the changes of the router ip address, an ethernet cable has to be connected to both the routers on the LAN ports.

The advantage of making a coherent LAN is that now you can connect to hosts which are connected to the other router without having to replug the cable into another router or join the same wifi network as the host you want to connect to. You can access other PCs, printers, NAS, stream through DLNA, etc without having to do any changes.

2) Routing on the router for appliance based Load Sharing

This technique involves making changes on the broadband router and no changes will be required on the hosts i.e. laptops, Desktops, Tablets, etc. Routes will have to be put on the router. You cannot put the route of 0.0.0.0/1 because most routers will not allow you to put a destination entry of all zeroes. The work around would be to put routes for the other half of the internet. These routes are 128.0.0.0/2 and 192.0.0.0/2.

Static routing on a Broadband router

The principle here is that we route the traffic for the second half of the internet (ip range from 128.X.X.X-223.X.X.X) towards the other router. This will send outgoing traffic through that router and thus the returning traffic will come through the other internet link. As far as traffic destined towards first half of the internet is concerned, it will by default go towards the internet link of the same router. Thus the return traffic will come through the same internet link. Eventually Internet Load can be shared over the multiple links.

 First router
first router
Second Router
second router

2) Routing on the host for host based Load Sharing

This is the most important aspect of the whole technique yet very simple. Assuming the default gateway obtained through DHCP is 192.168.1.1, the route for the first half of the internet should be towards the other router i.e. towards 192.168.1.2. So when you access a site which has an ip address in the range of 1.X.X.X to 126.X.X.X, the traffic will go to the second router. When your traffic will go to the second router, the return traffic will also come from the second router. Similarly, when you access a site which has an ip address in the range of 128.X.X.X to 223.X.X.X, the traffic will go to the first router. When your traffic will go to the first router, the return traffic will also come from the first router. This will result in traffic being shared over both the internet connections.Image

Routing on Windows

If you have detected your default gateway to be 192.168.1.1, add the following route

route -p add 0.0.0.0 mask 128.0.0.0 192.168.1.2

If you have detected your default gateway to be 192.168.1.2, add the following route

route -p add 0.0.0.0 mask 128.0.0.0 192.168.1.1

Just in case you have to remove the route, enter the following command

route delete 0.0.0.0 mask 128.0.0.0

Routing on Mac

If you have detected your default gateway to be 192.168.1.1, add the following route

sudo route -n add -net 0.0.0.0/1 192.168.1.2

If you have detected your default gateway to be 192.168.1.2, add the following route

sudo route -n add -net 0.0.0.0/1 192.168.1.1

Just in case you have to remove the route, enter the following command

sudo route -n add -net 0.0.0.0/1 192.168.1.1    OR

sudo route -n delete -net 0.0.0.0/1 192.168.1.2

I hope my post has been helpful in your life but the only guide which can help you in the hereafter is the Qur’an. You can download the English translation of the Qur’an here.

Advertisements

2 thoughts on “Load Balancing multiple Internet Connections

  1. Hi,
    Thank you for sharing this. Have you tried looking to multiwan on openwrt for example? i am OK with your way but it could be inefficient based on LAN users behavior. If they end up hitting the same popular websites, then it make no sense.

    What do you think?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s