Written by BiRU Thursday, 22 September 2016 07:17
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…
First of all, we need to set a PPTP connection in /etc/ppp/peers/ like this:
[root@localhost ~]# vim /etc/ppp/peers/new_pptp
pty “pptp 10.12.10.2 –nolaunchpppd”
name USERNAME
password secret_password
remotename PPTP
require-mppe-128
Now we need to make a script to call pptp as follows:
[root@localhost ~]# vim /etc/ppp/peers/auto_dial.sh
#!/bin/bash
if ! ping -Q 2 -c 2 -t 2 192.168.6.1; then
/usr/sbin/pppd call new_pptp
sleep 5
/sbin/route add default ppp0
fi
Explaination:
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.
[root@localhost ~]# nano /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# 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