Please read the original article - S’il vous plaît lire l'article original -- How To: Load Balancing & Failover With Dual/ Multi WAN / ADSL / Cable Connections on Linux Comment: Load Balancing et Failover avec double / Multi WAN / ADSL / Câble Connexions sur Linux . It contains detailed information with a sample script. Il contient des informations détaillées avec un exemple de script. Viliam Kočinský modified my script to send email when routing table changes. Viliam Kočinský modifié mon script pour envoyer des e-mails lors de changements table de routage. Also he is starting the script as a service from /etc/init.d. De plus, il commence le script comme un service dans / etc / init.d. Read below for his enhancements: Lire ci-dessous pour ses améliorations:


I’m using your gwping script. Je suis gwping l'aide de votre script. Realy usefull. Vraiment utile. I added posibility to send email, when routing table change: J'ai ajouté posibility à envoyer des e-mails, lorsque la table de routage changement:

# cat /usr/local/sbin/gwping # Cat / usr / local / sbin / gwping
…….

EMAILFROM="root@myserver.example.com" Emailfrom = "root@myserver.example.com"
EMAILTO="someone@example.com" Emailto = "someone@example.com"
….. … ..

if [[ $CLS1 -eq 0 || $CLS2 -eq 0 ]]; then if [[$ CLS1-eq 0 | | $ CLS2-eq 0]], puis
if [[ $LLS1 -eq 1 && $LLS2 -eq 0 ]]; then if [[$ LLS1-eq 1 & & $ LLS2-eq 0]], puis
echo Switching to $NAME2 Le passage à echo $ NOM2
ip route replace default scope global via $GW2 dev $EXTIF2 ip route par défaut remplacer portée mondiale via $ GW2 dev $ EXTIF2
LSROUTE=$(ip route show) LSROUTE = $ (ip route show)
echo "$LSROUTE" | mail -s "GWPING - Routing table changed. Line $NAME1 is down." echo "$ LSROUTE" | mail-s "GWPING - table de routage changé. Ligne $ NOM1 est en panne." -r $EMAILFROM $EMAILTO - r $ $ Emailfrom Emailto
elif [[ $LLS1 -eq 0 && $LLS2 -eq 1 ]]; then elif [[$ LLS1-eq 0 & & $ LLS2-eq 1]], puis
echo Switching to $NAME1 Le passage à echo $ NOM1
ip route replace default scope global via $GW1 dev $EXTIF1 ip route par défaut remplacer portée mondiale via $ GW1 dev $ EXTIF1
LSROUTE=$(ip route show) LSROUTE = $ (ip route show)
echo "$LSROUTE" | mail -s "GWPING - Routing table changed. Line $NAME2 is down." echo "$ LSROUTE" | mail-s "GWPING - table de routage changé. Ligne $ NOM2 est en panne." -r $EMAILFROM $EMAILTO - r $ $ Emailfrom Emailto
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 ]]; then elif [[$ LLS1-eq 0 & & $ LLS2-eq 0]], puis
echo Restoring default load balancing echo La restauration par défaut d'équilibrage de charge
#ip route replace default scope global via $GW1 dev $EXTIF1 # ip route par défaut remplacer portée mondiale via $ GW1 dev $ EXTIF1
ip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2 ip route par défaut remplacer portée mondiale nexthop via $ GW1 dev $ EXTIF1 poids W1 $ nexthop via $ GW2 dev $ $ EXTIF2 poids W2
LSROUTE=$(ip route show) LSROUTE = $ (ip route show)
echo "$LSROUTE" | mail -s "GWPING - Routing table changed. Both lines are up." echo "$ LSROUTE" | mail-s "GWPING - table de routage changé. Les deux lignes sont en hausse." -r $EMAILFROM $EMAILTO - r $ $ Emailfrom Emailto
fi Fi
fi Fi
sleep $SLEEPTIME dormir $ SLEEPTIME
done fait

Also I’m starting this script as service from /etc/init.d Aussi je commence ce script comme service dans / etc / init.d

# cat /etc/init.d/gwping # Cat / etc / init.d / gwping
#!/bin/sh #! / bin / sh
# Author: Viliam Kocinsky # Auteur: Viliam Kocinsky

### BEGIN INIT INFO # # # BEGIN INIT INFO
# Short-Description: Monitor Internet access connection links and modify kernel route if some link go down. # Short-Description: Surveillez l'accès à Internet le cadre des liens du noyau et de modifier l'itinéraire si un lien aller vers le bas.
# Description: This is startup script for gwping script, that manage internet connection failover (if you have at least 2 providers). # Description: Ce script de démarrage est pour gwping script, qui gèrent le basculement connexion Internet (si vous avez au moins 2 fournisseurs).
# That is, it reguraly ping one IP address # En d'autres termes, il reguraly ping une adresse IP
# on internet through certain provider (but trying all) . # Sur Internet par l'intermédiaire de certains fournisseurs (mais d'essayer tous). If ping doesn’t come back, than it addjust kernel route table. Si le ping ne revient pas, que addjust noyau itinéraire tableau.
# See inside script for details. # Voir à l'intérieur de script pour plus de détails. This script is from the website: Ce script est sur le site:
# http://blog.taragana.com/index.php/archive/how-to-load-balancing-failover-with-dual-multi-wan-adsl-cable-connections-on-linux/ # Http://blog.taragana.com/index.php/archive/how-to-load-balancing-failover-with-dual-multi-wan-adsl-cable-connections-on-linux/
#
### END INIT INFO # # # END INIT INFO

command="$1" command = "$ 1"

case "$command" in case "$ commande" en
start)
echo "Starting gwping." echo "A gwping."
/usr/local/sbin/gwping & / usr / local / sbin / gwping &
echo $! echo $! > /usr/local/share/gwping_pid > / Usr / local / share / gwping_pid
;;
stop)
echo "Stoping gwping." echo "stoping gwping."
kill -9 $(cat /usr/local/share/gwping_pid) && rm /usr/local/share/gwping_pid kill -9 $ (cat / usr / local / share / gwping_pid) & & rm / usr / local / share / gwping_pid
;;
*)
echo "Usage /etc/init.d/gwping start|stop" echo "Usage / etc / init.d / gwping start | stop"
;;
esac