LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Linux Answers > Networking
User Name
Password

Notices


By michaelsanford at 2005-06-01 13:57
Noticing that I wasn't the only person wanting to take advantage of multiple IP gateways on my system, I thought I'd post our findings. This is the result of many headaches on the part of myself and my colleague Mr. Mirotchnick.

Our equipment--and this Answer--are arranged thusly:
- 2 Cisco DSL modems each connected to separate ISPs, First_ISP and Second_ISP
- A Cisco 24-port unmanaged switch, though any switch or no switch at all will do.
- A RHEL9 linux box (kernel 2.6.5-1.358) but any Linux above kernel 2.6 should be OK.

There is no reason you need the switch in your setup though, since you can just as easily have PCI DSL modems in your gateway or have external modems connect directly to your NICs; our office setup, however, requires it for reasons not relevant here.

If you have directly-connected modems you will need to adjust the numbers here to reflect that, since a directly-connected DSL modem won't have a LAN IP address--you would have to replace 192.168.0.1 and 192.168.1.1 by their WAN equivalents. To keep the Tylenol bill down, you would also need static IP addressing from your ISP ;)

The Commands
The two Cisco modems have LAN ip addresses of 192.168.0.1 and 192.168.1.1 and subnet masks of 255.255.255.0. The two (Linux gateway) ethernet interfaces are configured thusly:
Code:
eth0      Link encap:Ethernet  HWaddr 00:0A:E6:77:50:C0
          inet addr:192.168.1.200  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20a:e6ff:fe77:50c0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth2      Link encap:Ethernet  HWaddr 00:40:F4:6B:70:5C
          inet addr:192.168.0.200  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::240:f4ff:fe6b:705c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
I recommend using two physical interfaces instead of interface aliases for two reasons. Firstly, you have the redundancy of having two devices, so if one of your NICs gets fried you won't lose your connection. Secondly, in our situation, we could not get device aliases to bind properly for routing.

Now, we need to create two new routing tables:
Code:
echo "1 First_ISP" >> /etc/iproute2/rt_tables
echo "2 Second_ISP" >> /etc/iproute2/rt_tables
That has created two new routing tables, now we have to add something to them:
Code:
ip route add 192.168.1.0/24 dev eth0 src 192.168.1.200 table First_ISP
ip route add default via 192.168.1.1 table First_ISP
ip route add 192.168.0.0/24 dev eth2 src 192.168.0.200 table Second_ISP
ip route add default via 192.168.0.1 table Second_ISP
Now we add the rules that allow us to use the two routes from the two interfaces
Code:
ip rule add from 192.168.1.200 table First_ISP
ip rule add from 192.168.0.200 table Second_ISP
This last bit of network magic is the keystone of this setup; it directs the kernel to use the routing tables in a round-robin, each with a certain weight (preference) that you can alter to prefer one route (i.e., ISP) over the other. You can also reduce the weight to 0 if that ISP goes down.
Code:
ip route add default scope global nexthop via 192.168.1.1 dev eth0 weight 1 \
nexthop via 192.168.0.1 dev eth2 weight 1
To test, traceroute two different domains (IPs)--you should see them going out the different interfaces. However. since routes are cached by the kernel, when you test it you will see that, for a short period (the route caching period) a domain will use the same route. This is normal; once the route cache expires it will be free to use whichever route is next in the round-robin.

What this will do
We use this type of multiplexing in a wireless ISP environment to break up traffic of our users across multiple lines both for redundancy and for bandwidth conservation. It was never designed to increase transfer speed (beyond what is not lost by having all our users on a single line).

What this will not do
This type of spanning will not aggregate bandwidth for a single user. By this I mean that if you have two 5 meg DSLs you won't magically have a single 10 meg connection. This is because it routes destination IPs via one of the two ISP connections, so if you're downloading a single file from freshmeat.com all requests for freshmeat.com will go in and out one of the two interfaces (until the kernel's routing cache expires). It will not try to open two connections to the IP using both lines at the same time.

N.B.,
A primary reference for this Answer is the Linux Advanced Routing & Traffic Control Howto by messers Graf, Maxwell, von Mook, van Oosterhout, Spaans, Schroeder and Larroy found at http://lartc.org/howto/ ; I recommend anyone interested in serious traffic routing read this.

by Brazen on Mon, 2005-10-17 10:20
What if one isp goes down? Will the router automatically try the other route when that one fails? Or will users be getting errors half the time until someone MANUALLY sets the weight to 0 for that route?

by Brazen on Wed, 2005-10-19 15:41
I followed the instructions, but if the network service restarts (eg with "service network restart") then the settings are lost!


  



All times are GMT -5. The time now is 03:12 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration