Welcome to AUXNET IRC Network

Idle on AUXnet a lot? Why not play our idlerpg game, you can check it out at #idleRPG - for more information visit the website http://idlerpg.auxnet.org

How to Auto Reconnect PPTP in CentOS/Redhat

Attention: open in a new window. PDFPrintE-mail

All of us may have seen  that in windows based OS, PPTP connection always make attempt to reconnect PPTP whenever any kind of termination occur in connection. Have you think about how this will work in CentOS or Redhat machine?

Definitely we will seek help from CRON, but here is a little bit trick. Let’s see…

  • Set a PPTP Connection Parameter:

First of all, we need to set a PPTP connection in /etc/ppp/peers/ like this:

[[email protected] ~]# vim /etc/ppp/peers/new_pptp

pty “pptp –nolaunchpppd”
password secret_password
remotename PPTP

  • Make a Script:

Now we need to make a script to call pptp as follows:

[[email protected] ~]# vim /etc/ppp/peers/auto_dial.sh

if ! ping -Q 2 -c 2 -t 2; then
/usr/sbin/pppd call new_pptp
sleep 5
/sbin/route add default ppp0


  1. if ! ping -Q 2 -c 2 -t 2; then : The condition is set such as the commands in the script will work only when this condition full-fill. Here will be the gateway IP of PPTP ip block. Which means it is the gateway of the network on which client will be connected. This should be placed at PPTP server interface. So, the script will check 2 times  ping result. If ping drop occurs in consecutive 2 times, it will run next commands.
  2. /usr/sbin/pppd call new_pptp: This is to call PPTP connection.
  3. sleep 5: Wait for 5sec before moving to next command. This interval is given to establish PPTP connection.
  4. /sbin/route add default ppp0: This will add default route via PPTP interface.
  • Add CRON Job:

Here comes the final part of this work. Let’s make a CRON job to run this script. Open crntab file using nano and add with your required interval. Here I’ve instructed CRON to run this at every 2 minute interval.

[[email protected] ~]# nano /etc/crontab


# For details see man 4 crontabs

# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/2 * * * * root /etc/ppp/peers/auto_dial.sh

Now start the cron using /etc/init.d/cron start