Ubuntu server persistent auto reconnecting PPTP VPN connection

Ubuntu server persistent auto reconnecting PPTP VPN connection

I have set up a PPTP VPN client on my Ubuntu server. Unfortunately when the server reboots, the connection goes down and stays down. After a long search I found a solution on this website. It is simple bash script, which checks if the VPN server (which had the VPN ip of is pingable. If not it restarts the PPTP VPN connection.

ping -c3 > pingreport
result=`grep "0 received" pingreport`
truncresult="`echo "$result" | sed 's/^\(.................................\).*$/\1/'`"
if [[ $truncresult == "3 packets transmitted, 0 received" ]]; then
pon company-vpn

I execute this script every five minutes, by editing the /etc/crontab file and added the following rule:

*/5 *   * * *   root    bash /root/vpn-check.sh

15 thoughts on “Ubuntu server persistent auto reconnecting PPTP VPN connection

  1. Hi,

    I am unable to run the above script. I even tried adding
    to the beginning of the below script

    and then run it as
    */5 * * * * bash /root/vpn-check.sh > /root/cronlog.txt 2>&1

    and it doesn’t work. Pls help, what could be wrong.

    When I run the same from #, It works and starts pptp connection.

  2. I tried this script , when i run the script using
    bash manually is working fine , when i am trying to use it with cronjob is not working , i can see the cron is running

    tail -f /var/log/syslog | grep CRON
    Dec 14 11:56:01 server3 CRON[26319]: (root) CMD (/bin/bash /var/scripts/vpn-check.sh)

    but not executing the script …

  3. just add

    maxfail 0

    to the end of your pptp config file, so you don’t need a script anymore!

  4. It can be a bit simplified:
    ping -c3 2>&1 | grep -q ‘, 0 received’ && pon company-vpn

  5. I found a more simple solution for the script:

    ifconfig >/tmp/ifconfig.txt
    if ! grep –quiet ppp0 /tmp/ifconfig.txt ; then
    pon conn_name

    Replace conn_name for your connection name. Check if ppp0 is the interface name, replace if necessary.

Leave a Reply

Your email address will not be published. Required fields are marked *