1

I have a Dell server with Ubuntu 11.10 Server installed on it. The server has 3 Ethernet cards eth0, eth1 and eth2.

I have two ISPs say ISP1, ISP2

eth0 has a public IP (provided by ISP1 - we require to access this service from outside our LAN) eth1 is connected to the LAN (via switch) with 192.168.X.X subnet eth2 gets a dynamic IP (via DHCP provided by ISP2) with 172.16.x.x subnet

I want to load balance (making it fault-tolerant at the same time) the two internet connections. I found the following script online to help my cause:

#!/bin/bash -v
#IPs of device connected to the internet
IP1=119.my.pub.ip #Public IP provided by ISP1
#dynamically alloted IP provided by ISP2
IP2=`ifconfig | awk -F: '/172.16./ {print $2}' | awk '{ORS=" "; print $1}' | awk '{print $2}'`

#Your Gateways (type route in terminal it should be in the same line as default)
P1=119.my.pu.gat #gateway provided by ISP1
P2=172.16.1.1 #gateway provided by ISP2

#Your Subnets
P0_NET=192.168.0.0/16 #local network subnet,
P1_NET=119.82.90.0/28 # Part of your gateway
P2_NET=172.16.1.0/24 #Part of your gateway
# NICs your internet interfaces
IF1=eth0
IF2=eth2
IF0=eth1

ip route add $P1_NET dev $IF1 src $IP1 table T1
ip route add default via $P1 table T1
ip route add $P2_NET dev $IF2 src $IP2 table T2
ip route add default via $P2 table T2
ip route add $P1_NET dev $IF1 src $IP1
ip route add $P2_NET dev $IF2 src $IP2

ip rule add from $IP1 table T1
ip rule add from $IP2 table T2
ip route add $P0_NET dev $IF0 table T1
ip route add $P2_NET dev $IF2 table T1
ip route add 127.0.0.0/8 dev lo table T1
ip route add $P0_NET dev $IF0 table T2
ip route add $P1_NET dev $IF1 table T2
ip route add 127.0.0.0/8 dev lo table T2

ip route add default scope global nexthop via $P1 dev $IF1 weight 1 nexthop via $P2 dev $IF2 weight 1

I do not fully understand the script. Hence, in case the above code does not work, what is the best way to restore the machine to its original configuration ? What files need to be backed up prior to running this script?

1 Answer 1

2

I believe the script you found was created by following/amalgamating the various pieces of information from the Linux Advanced Routing & Traffic Control HOWTO. Specifically the section on load balancing separate ISP links. I suggest you read that page to help understand what that script is doing. Keep in mind that that How To references old Kernels though I don't think the principle would have changed much and the ip commands are probably still valid.

That script would need to be run each time the machine boots to set the routes etc. so you don't need to backup files (it doesn't touch any). Once you reboot the machine the rules will be forgotten and the machine's default network setup will be used.

If you don't want to reboot then, depending on the distro, you may be able to restart the networking i.e. on Red Hat a service network restart should clear the routes for you and add the default route again (this is based on my quick scan of the network scripts). I believe Ubuntu will have a similar system (I haven't used it for some time and they use Upstart nowadays which I have no knowledge of). Otherwise you'd have to manually remove the rules that that script creates (or write a script that does it) using the ip command.

1
  • Thnx for "o you don't need to backup files (it doesn't touch any)". Now I can experiment without fear.
    – chochim
    May 25, 2012 at 8:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .