Help me tweak my LoadBalancing Script for Linux: AKA: I don't know what I'm doing

Stanley Pain

2[H]4U
Joined
Apr 5, 2001
Messages
2,510
Well after much debate, I decided to NOT go with a hardware based load balancing router. Instead I've taken it upon myself to use my current Linux router (running ClarkConnect 2.1 sp1) and try to load balance 2 DSL connections over it.

here's the linky to my other thread for the specs of the network.

here's a script that I've been trying to modify for my current settings:

#!/bin/bash
#This is slightly modified load balance
#script for cc2.1 with 3 external NIC's
#You'll also need to modify firewall
#eth0 is first WAN
#eth1 is LAN
#eth2 is second WAN
#eth3 is third WAN
#Ignore (or comment out) echos, they are for testing puproses
#[email protected]


echo "Setting variables"
LANIP="10.1.1.100"
LANNET="255.255.0.0" #examples: 10.0.0.0/8 192.168.1.0/24
LANIF="eth1" #Your LAN interface, usually eth1
FIRSTWANIP="65.95.210.166"
FIRSTWANNET="255.255.255.255"
FIRSTWANGW="64.230.245.65"
FIRSTWANIF="ppp0"
SECWANIP="192.168.0.250"
SECWANNET="255.255.255.0"
SECWANGW="192.168.0.1"
SECWANIF="eth2"



#No modifications after this line.


echo "Flushing tables..."
ip route flush cache
ip route flush all
ip route flush table 10
ip route flush table 11
ip route flush table 12

echo "Adding routes to default table..."
ip route add $SECWANNET dev $SECWANIF src $SECWANIP
ip route add $THIRDWANNET dev $THIRDWANIF src $THIRDWANIP
ip route add LANNET dev $LANIF src $LANIP
ip route add $FIRSTWANNET dev $FIRSTWANIF src $FIRSTWANIP
ip route add 127.0.0.0/8 dev lo src 127.0.0.1


echo "Adding 1st WAN ip rules..."
ip rule add from $FIRSTWANNET lookup 11
echo "Adding routes to 1st WAN table..."
ip route add $LANNET dev $LANIF table 11
ip route add 0/0 via $FIRSTWANGW table 11

echo "Adding 2nd WAN ip rules..."
ip rule add from $SECWANNET lookup 10
echo "Adding routes to 2nd WAN table..."
ip route add $LANNET dev $LANIF table 10
ip route add 0/0 via $SECWANGW table 10

echo "Adding 3rd WAN ip rules..."
ip rule add from $THIRDWANNET lookup 12
echo "Adding routes to 3rd WAN table..."
ip route add $LANNET dev $LANIF table 12
ip route add 0/0 via $THIRDWANGW table 12

echo "Adding balanced default route."
ip route add default equalize nexthop via $FIRSTWANGW dev $FIRSTWANIF weight 1 \
nexthop via $SECWANGW dev $SECWANIF weight 1

echo "Done!"

Script spews out a bunch of errors , some host cannot be reached, etc.

Currently the box is setup that eth0 is ppp0 and connects to my DSL and routes the data accordingly to 10.1.1.100 (and my windows box can access the internet). It can also access the interent from 192.168.0.250 if I disable ppp0.

Please help :)


Cheers,

Mr. Pain
 
Back
Top