Auto Re-Connect to DSL pppoe in Linux
Firstly you will need to configure the pppoe client
sudo pppoeconf
To connect you use
sudo pon dsl-provider
and disconnect using
sudo poff -a
PPPD does not always terminate immediately after, creating a killpppd script and placed in /usr/local/sbin/.
#!/bin/sh
#kill pppd brutally
for i in `ps -eaf | grep "pppd" | tr -s " " | cut -f2 -d " "`
do
sudo kill -9 ${i}
done
You need to make it executable, so sudo chmod +x killpppd
Making sure things are disconnected and ready for a reconnect, creating another little script dcon can handle that.
#!/bin/sh
sudo poff -a
sudo killpppd
sudo poff -a
Then make it executable. This script first tries to disconnect gracefully and tries to kill pppd if that was not successful.
Now to create a connect script that only connects if the connection has been lost and does nothing if it has not. Create connect
make it executable
#!/bin/sh
IFACE=ppp0
DOWN=dcon
UP="pon dsl-provider"
LOG=/var/log/dsl-reconnect.log
PTP=`ifconfig $IFACE 2>&1|grep P-t-P|cut -d : -f 3|cut -d " " -f 1`
RECV=`ping -c 1 $PTP 2>&1|grep received|cut -d , -f 2|cut -d " " -f 2`
if [ "$RECV" != "1" ]
then
echo "connecting..."
echo ----- >>$LOG
date>>$LOG
$DOWN >>$LOG 2>&1
#wait for kill
sleep 3
echo "hopefully killed"
$UP >>$LOG 2>&1
fi
It checks if the IP of our server (placed at PTP variable) is ping-able. In that case, the connection has not terminated and it does nothing. However, if the IP of the server is not ping-able, it disconnects (which has probably already been disconnected but pppd may not have died, so we need to kill it otherwise the connection is made with interface ppp1, ppp2 and the script will not work) and then tries to connect.
This must be run as root so create another script named con
#!/bin/sh
sudo connect
Make it executable and it can be run from the terminal to control the connection.
Creating a Cron to handle this to be checked every so often is next.
sudo crontab -e
and add this line - be sure to keep all the astrisks
* * * * * /usr/local/sbin/con
This makes cron run the script “con” every minute.
References:
http://www.khattam.info/2010/03/07/howto-auto-re-connect-to-dsl-pppoe-in...
http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_u...
http://geekhut.blogspot.com/2007/05/auto-reconnecting-lost-dsl-connectio...