Line 1... |
Line 1... |
1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
# $Id: alcasar-load_balancing.sh 900 2012-06-21 16:15:27Z franck $
|
2 |
# $Id: alcasar-load_balancing.sh 904 2012-06-23 11:35:25Z franck $
|
3 |
|
3 |
|
4 |
# alcasar-load_balancing.sh
|
4 |
# alcasar-load_balancing.sh
|
5 |
# by BOUIJOUX Franck (3abTux) <3abtux@free.fr>
|
5 |
# by BOUIJOUX Franck (3abTux) <3abtux@free.fr>
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
7 |
|
7 |
|
8 |
# Équilibrage de charge sur 2 ou plusieurs liens internet (en cours d'expérimentation)
|
8 |
# Équilibrage de charge sur 2 ou plusieurs liens internet (en cours d'expérimentation)
|
9 |
# Définion des poids des routes : même poids --> alternance des connexions. Sinon le poids le plus faible est prioritaire
|
9 |
# Définion des poids des routes : même poids --> alternance des connexions. Sinon le poids le plus faible est prioritaire
|
10 |
# Load balancing with 2 or more Internet links (experimental)
|
10 |
# Load balancing with 2 or more Internet links (experimental)
|
11 |
# Weitght of routes : same --> switch between link. The lowest weight gain the priority.
|
11 |
# Weitght of routes : same --> switch between link. The lowest weight gain the priority.
|
12 |
|
12 |
|
- |
|
13 |
EXTIF="eth0"
|
- |
|
14 |
IPADDR1="192.168.2.10/24"
|
- |
|
15 |
NETMASK1=`ipcalc -m 192.168.182.2 | cut -d"=" -f2`
|
- |
|
16 |
GW1="192.168.2.1"
|
- |
|
17 |
WEIGHT1=1
|
- |
|
18 |
|
- |
|
19 |
echo $IPADDR1
|
- |
|
20 |
echo $NETMASK1
|
- |
|
21 |
echo $GW1
|
- |
|
22 |
exit 0
|
- |
|
23 |
|
- |
|
24 |
create_new_interface() {
|
- |
|
25 |
if [ "$response" = "n" ] || [ "$response" = "N" ]
|
- |
|
26 |
then
|
- |
|
27 |
PRIVATE_IP_MASK="0"
|
- |
|
28 |
PTN='^\([01]\?[[:digit:]][[:digit:]]\?\|2[0-4][[:digit:]]\|25[0-5]\).\([01]\?[[:digit:]][[:digit:]]\?\|2[0-4][[:digit:]]\|25[0-5]\).\([01]\?[[:digit:]][[:digit:]]\?\|2[0-4][[:digit:]]\|25[0-5]\).\([01]\?[[:digit:]][[:digit:]]\?\|2[0-4][[:digit:]]\|25[0-5]\)/[012]\?[[:digit:]]$'
|
- |
|
29 |
until [[ $(expr $PRIVATE_IP_MASK : $PTN) -gt 0 ]]
|
- |
|
30 |
do
|
- |
|
31 |
if [ $Lang == "fr" ]
|
- |
|
32 |
then echo -n "Entrez l'adresse IP d'ALCASAR au format CIDR (a.b.c.d/xx) : "
|
- |
|
33 |
else echo -n "Enter ALCASAR IP address in CIDR format (a.b.c.d/xx) : "
|
- |
|
34 |
fi
|
- |
|
35 |
read PRIVATE_IP_MASK
|
- |
|
36 |
done
|
- |
|
37 |
else
|
- |
|
38 |
PRIVATE_IP_MASK=$DEFAULT_PRIVATE_IP_MASK
|
- |
|
39 |
fi
|
- |
|
40 |
else
|
- |
|
41 |
PRIVATE_IP_MASK=`grep PRIVATE_IP conf/etc/alcasar.conf|cut -d"=" -f2`
|
- |
|
42 |
rm -rf conf/etc/alcasar.conf
|
- |
|
43 |
fi
|
- |
|
44 |
# Define LAN side global parameters
|
- |
|
45 |
hostname $HOSTNAME
|
- |
|
46 |
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP_MASK | cut -d"=" -f2` # private network address (ie.: 192.168.182.0)
|
- |
|
47 |
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2` # private network mask (ie.: 255.255.255.0)
|
- |
|
48 |
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1` # ALCASAR private ip address (consultation LAN side)
|
- |
|
49 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP_MASK |cut -d"=" -f2` # network prefix (ie. 24)
|
- |
|
50 |
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX # ie.: 192.168.182.0/24
|
- |
|
51 |
classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`; classe_sup_sup=`expr $classe + 2` # ie.: 2=classe B, 3=classe C
|
- |
|
52 |
PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`. # compatibility with hosts.allow et hosts.deny (ie.: 192.168.182.)
|
- |
|
53 |
PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2` # private network broadcast (ie.: 192.168.182.255)
|
- |
|
54 |
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup` # last octet of LAN address
|
- |
|
55 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # last octet of LAN broadcast
|
- |
|
56 |
PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1` # First network address (ex.: 192.168.182.1)
|
- |
|
57 |
PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # last network address (ex.: 192.168.182.254)
|
- |
|
58 |
|
- |
|
59 |
} # end create_new_interface
|
- |
|
60 |
|
- |
|
61 |
|
- |
|
62 |
|
- |
|
63 |
|
- |
|
64 |
|
- |
|
65 |
X=1
|
- |
|
66 |
nbr=3 # nbr interface réseau accédant à l'internet (comprenant celle par défaut eth0)
|
- |
|
67 |
while [ $X -lt $nbr ]
|
- |
|
68 |
do
|
- |
|
69 |
echo $X
|
- |
|
70 |
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF:${X}
|
- |
|
71 |
DEVICE=$EXTIF:${X}
|
- |
|
72 |
BOOTPROTO=static
|
- |
|
73 |
IPADDR=$IPADDR1
|
- |
|
74 |
NETMASK=$NETMASK-${X}
|
- |
|
75 |
ONBOOT=yes
|
- |
|
76 |
METRIC=10
|
- |
|
77 |
NOZEROCONF=yes
|
- |
|
78 |
MII_NOT_SUPPORTED=yes
|
- |
|
79 |
IPV6INIT=no
|
- |
|
80 |
IPV6TO4INIT=no
|
- |
|
81 |
ACCOUNTING=no
|
- |
|
82 |
USERCTL=no
|
- |
|
83 |
EOF
|
- |
|
84 |
|
- |
|
85 |
X=$(( $X + 1))
|
- |
|
86 |
done
|
- |
|
87 |
|
- |
|
88 |
exit 0
|
- |
|
89 |
|
13 |
WEIGHT1=1
|
90 |
WEIGHT1=1
|
14 |
WEIGHT2=1
|
91 |
WEIGHT2=1
|
15 |
#WEIGHT3=3
|
92 |
#WEIGHT3=3
|
16 |
|
93 |
|
17 |
# Définition des interfaces :
|
94 |
# Définition des interfaces :
|