De retour
je vous poste mon fichier de "failover" pour 3 Wan
failover.sh
#!/bin/sh
# Nom des routeurs
NAME1="Routeur 1"
NAME2="Routeur 2"
NAME3="Routeur 3"
# IP des routeurs
GW1="192.168.0.2"
GW2="192.168.0.3"
GW3="192.168.0.4"
# Relative weights of routes. Keep this to a low integer value. I am using 4
W1=4
W2=3
W3=2
# Time between checks in seconds
SLEEPTIME=10
# IP ou nom d hote pour le test de ping
TESTIP=www.google.com
# Ping timeout en secondes
TIMEOUT=2
#
SUCCESSREPEATCOUNT=4
FAILUREREPEATCOUNT=2
# Do not change anything below this line
# Last link status indicates the macro status of the link we determined. This is down initially to force routing change upfront. Don't change these values.
LLS1=1
LLS2=1
LLS3=1
# Last ping status. Don't change these values.
LPS1=1
LPS2=1
LPS3=1
# Current ping status. Don't change these values.
CPS1=1
CPS2=1
CPS3=1
# Change link status indicates that the link needs to be changed. Don't change these values.
CLS1=1
CLS2=1
CLS3=1
# Count of repeated up status or down status. Don't change these values.
COUNT1=0
COUNT2=0
COUNT3=0
while : ; do
ping -W $TIMEOUT -I eth1 -c 1 $TESTIP > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo $NAME1 Down
CPS1=1
else
CPS1=0
fi
if [ $LPS1 -ne $CPS1 ]; then
echo Ping status changed for $NAME1 from $LPS1 to $CPS1
COUNT1=1
else
if [ $LPS1 -ne $LLS1 ]; then
COUNT1=$(expr $COUNT1 + 1)
fi
fi
if [[ $COUNT1 -ge $SUCCESSREPEATCOUNT || ($LLS1 -eq 0 && $COUNT1 -ge $FAILUREREPEATCOUNT) ]]; then
echo Uptime status will be changed for $NAME1 from $LLS1
CLS1=0
COUNT1=0
if [ $LLS1 -eq 1 ]; then
LLS1=0
else
LLS1=1
fi
else
CLS1=1
fi
LPS1=$CPS1
ping -W $TIMEOUT -I eth2 -c 1 $TESTIP > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo $NAME2 Down
CPS2=1
else
CPS2=0
fi
if [ $LPS2 -ne $CPS2 ]; then
echo Ping status changed for $NAME2 from $LPS2 to $CPS2
COUNT2=1
else
if [ $LPS2 -ne $LLS2 ]; then
COUNT2=$(expr $COUNT2 + 1)
fi
fi
if [[ $COUNT2 -ge $SUCCESSREPEATCOUNT || ($LLS2 -eq 0 && $COUNT2 -ge $FAILUREREPEATCOUNT) ]]; then
echo Uptime status will be changed for $NAME2 from $LLS2
CLS2=0
COUNT2=0
if [ $LLS2 -eq 1 ]; then
LLS2=0
else
LLS2=1
fi
else
CLS2=1
fi
LPS2=$CPS2
ping -W $TIMEOUT -I eth3 -c 1 $TESTIP > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo $NAME2 Down
CPS3=1
else
CPS3=0
fi
if [ $LPS3 -ne $CPS3 ]; then
echo Ping status changed for $NAME3 from $LPS3 to $CPS3
COUNT3=1
else
if [ $LPS3 -ne $LLS3 ]; then
COUNT3=$(expr $COUNT3 + 1)
fi
fi
if [[ $COUNT3 -ge $SUCCESSREPEATCOUNT || ($LLS3 -eq 0 && $COUNT3 -ge $FAILUREREPEATCOUNT) ]]; then
echo Uptime status will be changed for $NAME3 from $LLS3
CLS3=0
COUNT3=0
if [ $LLS3 -eq 1 ]; then
LLS3=0
else
LLS3=1
fi
else
CLS3=1
fi
LPS3=$CPS3
if [[ $CLS1 -eq 0 || $CLS2 -eq 0 || $CLS3 -eq 0 ]]; then
if [[ $LLS1 -eq 1 && $LLS2 -eq 0 && $LLS3 -eq 0 ]]; then
echo Switching to $NAME2
ip route replace default scope global via $GW2 dev eth2
elif [[ $LLS1 -eq 0 && $LLS2 -eq 1 && $LLS3 -eq 0 ]];
then
echo Switching to $NAME1
ip route replace default scope global via $GW1 dev eth1
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 && $LLS3 -eq 1 ]];
then
echo Switching to $NAME3
ip route replace default scope global via $GW3 dev eth3
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 && $LLS3 -eq 0 ]];
then
echo Restoring default load balancing
ip route replace default scope global nexthop via $GW1 dev eth1 weight $W1 nexthop via $GW2 dev eth2 weight $W2 nexthop via $GW3 dev eth3 weight $W3
fi
fi
sleep $SLEEPTIME
done
Pour le partage des connexions Wan:
# nano /etc/sysctl.conf
...
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
...
Pour le masquering:
echo "iptables -A POSTROUTING -t nat -o eth1 -j MASQUERADE" >> /etc/rc.local
echo "iptables -A POSTROUTING -t nat -o eth2 -j MASQUERADE" >> /etc/rc.local
echo "iptables -A POSTROUTING -t nat -o eth3 -j MASQUERADE" >> /etc/rc.local
Configuration de mon client:
ip : 192.169.0.30
mask: 255.255.255.0
gateway: 192.168.0.254
dns 1 : 208.67.222.222
dns 2 : 208.67.220.220
Rappel : 192.168.0.254 = eth0 du serveur
Malheureusement rien ne passe :
ping
www.google.com RAS
nslookup
www.google.com Echec