Hi all the list.

I have added IPSec restart in the script, because it seems not to work well without it 
at each time.
Sorry !
Now, it seems to be ok.

#!/bin/sh
#
# Check a regular interval defined in /etc/crontab that IP exists for IFACE
# and that IP has not changed
# this is obtained by scanning "ip addr show $IFACE" return (function getip()).
# If IFACE is down or IP has changed, then a script can be executed.
# Return to correct defaultroute if IPSEc user lost ISP link.

# Adapted by J. Nilo from a script by T. Nkaoua
# Defaultroute switching survey feature added by F6HQZ Francois BERGERET 
# (tks to J.Nilo and T.Nkaoua)

IFACE=ppp0
FILE=/tmp/checkip

getip() {
        IP=`ip addr show $IFACE | grep inet | cut -f1 -d"p" | cut -f2 -d"t" | cut -f1 
-d"/"`
}

getgate() {
        GATE=`ip addr show $IFACE | grep inet | cut -f1 -d"/" | cut -f2 -d"r" | cut 
-f1 -d"/"`
}

getdefroute() {
        DEFROUTE=`ip route | grep default | cut -f3 -d"v"`
}

if [ -f $FILE ]; then
        read OLDIP < $FILE
else
        getip
        echo $IP > $FILE
        exit
fi

getip
echo $IP > $FILE
getgate
getdefroute

if ! [ "$IP" ]; then
        logger "checkip: Checkip connection broken detection"
#
# Put any command here that you want to activate if IFACE is down
#
        exit
fi

if   [ $DEFROUTE != $IFACE ]; then
        logger checkip: IP:$IP GATE:$GATE DEFAULTROUTE:$DEFROUTE
        logger checkip: WARNING: defaultroute was $DEFROUTE
        logger checkip: ip route del default
        ip route del default
        logger checkip: ip route add default via $GATE dev $IFACE
        ip route add default via $GATE dev $IFACE
        logger checkip: ipsec restart
        ipsec setup --restart
        exit
fi

if [ $OLDIP != $IP ]; then
        logger checkip: IP has changed for $IFACE: new IP is $IP - old IP was $OLDIP
#
# Put any command here that you want to activate if IP has changed
#
        logger checkip: ip route del default
        logger checkip: ip route add default via $GATE dev $IFACE
        ip route del default
        ip route add default via $GATE dev $IFACE
fi

#------------------------ FILE END ----------------------------------- 

Instructions to install checkip.dat :

Copy this file to : 
/usr/sbin/checkip.dat

chmod 755 checkip.dat

Edit /etc/cron.d/multicron and add a new line :
*/1     * * * * root    /usr/sbin/checkip.dat

Backup root.lrp

And enjoy with Bering running 24/24 without any interruption due to ISP link cutted !

Best Regards,
Francois BERGERET,
France.


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html

Reply via email to