Please read the original article - Si prega di leggere l'articolo originale -- How To: Load Balancing & Failover With Dual/ Multi WAN / ADSL / Cable Connections on Linux Come: il bilanciamento del carico e failover Con Dual / Multi WAN / ADSL / Connessioni via cavo su Linux . It contains detailed information with a sample script. Esso contiene informazioni dettagliate con uno script di esempio. Viliam Kočinský modified my script to send email when routing table changes. Viliam Kočinský modificato il mio script per inviare e-mail quando tabella di routing modifiche. Also he is starting the script as a service from /etc/init.d. Egli è anche lo script di partenza come un servizio da / etc / init.d. Read below for his enhancements: Leggi qui di seguito per i suoi miglioramenti:


I’m using your gwping script. Sto utilizzando il tuo gwping script. Realy usefull. Veramente utile. I added posibility to send email, when routing table change: Ho aggiunto possibilità di inviare e-mail, quando tabella di routing cambiamento:

# 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]], quindi
if [[ $LLS1 -eq 1 && $LLS2 -eq 0 ]]; then if [[$ LLS1-eq 1 & & $ LLS2-eq 0]], quindi
echo Switching to $NAME2 Il passaggio a echo $ NAME2
ip route replace default scope global via $GW2 dev $EXTIF2 ip route predefinita sostituire portata globale attraverso 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 - tabella di routing cambiato. Riga $ name1 è giù." -r $EMAILFROM $EMAILTO - r $ $ Emailfrom Emailto
elif [[ $LLS1 -eq 0 && $LLS2 -eq 1 ]]; then elif [[$ LLS1-eq 0 & & $ LLS2-eq 1]], quindi
echo Switching to $NAME1 Il passaggio a echo $ name1
ip route replace default scope global via $GW1 dev $EXTIF1 ip route predefinita sostituire portata globale attraverso 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 - tabella di routing cambiato. Riga $ NAME2 è giù." -r $EMAILFROM $EMAILTO - r $ $ Emailfrom Emailto
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 ]]; then elif [[$ LLS1-eq 0 & & $ LLS2-eq 0]], quindi
echo Restoring default load balancing echo Ripristino default di bilanciamento del carico
#ip route replace default scope global via $GW1 dev $EXTIF1 # ip route predefinita sostituire portata globale attraverso 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 predefinita sostituire portata globale nexthop via GW1 dev $ $ $ EXTIF1 peso W1 nexthop via GW2 dev $ $ $ EXTIF2 peso 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 - tabella di routing cambiato. Entrambe le linee sono". -r $EMAILFROM $EMAILTO - r $ $ Emailfrom Emailto
fi Fi
fi Fi
sleep $SLEEPTIME sonno $ SLEEPTIME
done fatto

Also I’m starting this script as service from /etc/init.d Sono anche a partire da questo script come servizio da / etc / init.d

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

### BEGIN INIT INFO # # # BEGIN INIT INFO
# Short-Description: Monitor Internet access connection links and modify kernel route if some link go down. # Descrizione breve: Monitor di connessione di accesso a Internet link e modificare l'itinerario del kernel se alcuni link scendere.
# Description: This is startup script for gwping script, that manage internet connection failover (if you have at least 2 providers). # Descrizione: Si tratta di script di avvio per gwping script, che gestiscono la connessione a Internet di failover (se si dispone di almeno 2 fornitori).
# That is, it reguraly ping one IP address # Questo è, reguraly ping ad un indirizzo IP
# on internet through certain provider (but trying all) . # Su internet attraverso alcuni provider (ma cercando tutti). If ping doesn’t come back, than it addjust kernel route table. Se ping non ritorna, di quello che addjust kernel rotta tabella.
# See inside script for details. # Vedere all'interno di script per i dettagli. This script is from the website: Questo script è dal sito web:
# 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 # # # FINE INIT INFO

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

case "$command" in caso "$ comando"
start)
echo "Starting gwping." echo "Avvio di gwping".
/usr/local/sbin/gwping & / usr / local / sbin / gwping &
echo $! echo $! > /usr/local/share/gwping_pid > / Usr / local / share / gwping_pid
;;
stop) fermata)
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