0,0 → 1,76 |
#!/bin/bash |
# $Id$ |
# alcasar-load_balancing.sh Load-balance internet connection over two or more local links |
# |
# Version: 0.8.0 - Wed, Sep 01, 2010 |
# |
# by Author: BOUIJOUX Franck (3abTux) <3abtux@free.fr> |
# en cours d'expérimentation et d 'écriture |
# |
|
# Définion des poids des routes |
WEIGHT1=1 |
WEIGHT2=1 |
WEIGHT3=3 |
|
# Set devices: |
DEV1=${1-eth0} # defaut eth0 |
DEV2=${2-eth0} # defaut eth0 mais peut être autre chose :-) |
DEV3=${3-eth0} # defaut eth0 mais peut être autre chose :-) |
|
# Trouver les adresses pour chaque interface |
IP1=`ifconfig $DEV1 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'` |
IP2=`ifconfig $DEV2 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'` |
#IP3=`ifconfig $DEV3 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'` |
|
# iTrouver les passerelles pour chaque interface |
#GW1=`route -n | grep $DEV1 | grep '^0.0.0.0' | awk '{ print $2 }'` |
#GW2=`route -n | grep $DEV2 | grep '^0.0.0.0' | awk '{ print $2 }'` |
GW1=192.168.1.6 |
GW2=192.168.1.1 |
#GW3=192.168.1.6 |
|
echo "Acces internet depuis $DEV1: IP=$IP1 par la GW=$GW1" |
echo " et depuis $DEV2: IP=$IP2 par la GW=$GW2" |
#echo " et depuis $DEV3: IP=$IP3 par la GW=$GW3" |
|
# Definition des routes |
|
# Tester si les tables existent sinon les créer |
if [ -z "`cat /etc/iproute2/rt_tables | grep '^252'`" ] ; then |
echo "252 rt_dev1" >> /etc/iproute2/rt_tables |
fi |
|
if [ -z "`cat /etc/iproute2/rt_tables | grep '^251'`" ] ; then |
echo "251 rt_dev2" >> /etc/iproute2/rt_tables |
fi |
#if [ -z "`cat /etc/iproute2/rt_tables | grep '^250'`" ] ; then |
# echo "250 rt_dev3" >> /etc/iproute2/rt_tables |
#fi |
|
|
# Tables de routage |
ip route add default via $GW1 table rt_dev1 |
ip route add default via $GW2 table rt_dev2 |
#ip route add default via $GW3 table rt_dev3 |
|
# Créatin des règles |
ip rule add from $IP1 table rt_dev1 |
ip rule add from $IP2 table rt_dev2 |
#ip rule add from $IP3 table rt_dev3 |
|
# Effacer la route par défaut existante |
if [ ! -z "`ip route show table main | grep 'nexthop'`" ] ; then |
ip route del default scope global |
fi |
|
# Alterne les liens basés sur chauqe route |
ip route add default scope global nexthop via $GW1 dev $DEV1 weight $WEIGHT1 \ |
nexthop via $GW2 dev $DEV2 weight $WEIGHT2 |
# nexthop via $GW3 dev $DEV3 weight $WEIGHT3 |
|
|
# Purge le cache |
ip route flush cache |
|
# Fin de alcasar-load_balancing.sh |
Property changes: |
Added: svn:eol-style |
+LF |
\ No newline at end of property |
Added: svn:executable |
+* |
\ No newline at end of property |
Added: svn:keywords |
+Id Author Date |
\ No newline at end of property |