PPTP Debian/Ubuntu OpenVZ Setup Script

[alert =style="green"]I was about to setup another PPTPd on one a new VPS that I got and i have always used a script that used to be @  http://www.putdispenserhere.com/, but the site was down so after a little investigation (google cache) I found a copy that I cleaned up for readability and saved it here for future usage.[/alert]

 

Make sure that your VPS has it’s PPP module working. To check, run:
[precode]cat /dev/ppp[/precode]
If you receive this message, your PPP module is ready for use:
[precode]cat: /dev/ppp: No such device or address[/precode]
To install the script, copy and paste this into your SSH client of choice:
[precode]
wget http://www.lowendguide.com/pptpinstall.sh
chmod +x pptpinstall.sh
./pptpinstall.sh
[/precode]

 

the complete script source

[precode]

#!/bin/bash

# Interactive PoPToP install script on a OpenVZ VPS

# Tested on Debian 5, 6, and Ubuntu 11.04

# 2011 v1.1

# Author: Commander Waffles

# http://www.putdispenserhere.com/pptp-debian-ubuntu-openvz-setup-script/

 

echo “######################################################”

echo “Interactive PoPToP Install Script for OpenVZ VPS”

echo “by Commander Waffles http://www.putdispenserhere.com”

echo “Should work on various deb-based Linux distos.”

echo “Tested on Debian 5, 6, and Ubuntu 11.04″

echo

echo “Make sure to message your provider and have them enable”

echo “IPtables and ppp modules prior to setting up PoPToP.”

echo

echo “You need to set up the server before creating more users.”

echo “A separate user is required per connection or machine.”

echo “######################################################”

echo

echo

echo “######################################################”

echo “Select on option:”

echo “1) Set up new PoPToP server AND create one user”

echo “2) Create additional users”

echo “######################################################”

read x

if test $x -eq 1; then

echo “Enter username that you want to create (eg. client1 or john):”

read u

echo “Specify password that you want the server to use:”

read p

 

# get the VPS IP

ip=`ifconfig venet0:0 | grep ‘inet addr’ | awk {‘print $2′} | sed s/.*://`

 

echo

echo “######################################################”

echo “Downloading and Installing PoPToP”

echo “######################################################”

apt-get update

apt-get install pptpd

 

echo

echo “######################################################”

echo “Creating Server Config”

echo “######################################################”

cat > /etc/ppp/pptpd-options <<END

name pptpd

refuse-pap

refuse-chap

refuse-mschap

require-mschap-v2

require-mppe-128

ms-dns 8.8.8.8

ms-dns 8.8.4.4

proxyarp

nodefaultroute

lock

nobsdcomp

END

 

# setting up pptpd.conf

echo “option /etc/ppp/pptpd-options” > /etc/pptpd.conf

echo “logwtmp” >> /etc/pptpd.conf

echo “localip $ip” >> /etc/pptpd.conf

echo “remoteip 10.1.0.1-100″ >> /etc/pptpd.conf

 

# adding new user

echo “$u * $p *” >> /etc/ppp/chap-secrets

 

echo

echo “######################################################”

echo “Forwarding IPv4 and Enabling it on boot”

echo “######################################################”

cat >> /etc/sysctl.conf <<END

net.ipv4.ip_forward=1

END

sysctl -p

 

echo

echo “######################################################”

echo “Updating IPtables Routing and Enabling it on boot”

echo “######################################################”

iptables -t nat -A POSTROUTING -j SNAT –to $ip

# saves iptables routing rules and enables them on-boot

iptables-save > /etc/iptables.conf

 

cat > /etc/network/if-pre-up.d/iptables <<END

#!/bin/sh

iptables-restore < /etc/iptables.conf

END

 

chmod +x /etc/network/if-pre-up.d/iptables

cat >> /etc/ppp/ip-up <<END

ifconfig ppp0 mtu 1400

END

 

echo

echo “######################################################”

echo “Restarting PoPToP”

echo “######################################################”

/etc/init.d/pptpd restart

 

echo

echo “######################################################”

echo “Server setup complete!”

echo “Connect to your VPS at $ip with these credentials:”

echo “Username:$u ##### Password: $p”

echo “######################################################”

 

# runs this if option 2 is selected

elif test $x -eq 2; then

echo “Enter username that you want to create (eg. client1 or john):”

read u

echo “Specify password that you want the server to use:”

read p

 

# get the VPS IP

ip=`ifconfig venet0:0 | grep ‘inet addr’ | awk {‘print $2′} | sed s/.*://`

 

# adding new user

echo “$u * $p *” >> /etc/ppp/chap-secrets

 

echo

echo “######################################################”

echo “Addtional user added!”

echo “Connect to your VPS at $ip with these credentials:”

echo “Username:$u ##### Password: $p”

echo “######################################################”

 

else

echo “Invalid selection, quitting.”

exit

fi

[/precode]

13 comments for “PPTP Debian/Ubuntu OpenVZ Setup Script

  1. March 12, 2013 at 21:41

    I used to use that all the time. I was sad when the site went down a lot, I also used the Google Cache as well.

  2. Phil
    March 17, 2013 at 22:57

    What firewall settings should be used with this?
    Specifically, I could not get it to work with apf (http://www.rfxn.com/projects/advanced-policy-firewall/) enabled. With the firewall disabled, things work fine.

    Alternately, there’s some hacks to get ufw partly working. What settings are needed for pptp with ufw?

    • March 18, 2013 at 11:08

      To allow PPTP in a firewall you have to open port 1723.
      for ufw the command would be something like
      sudo ufw allow 1723
      or
      sudo ufw allow 1723/tcp

      Can’t say the apf command, I don’t have that fresh in my mind :)

  3. Bob
    April 11, 2013 at 02:07

    Just wanted to let you know I updated my script slightly along with the documentation.

    • April 11, 2013 at 08:29

      Really nice to see you here! I personally used that script on all the vps I use for vpn.
      Easy and quick, good to go solution.
      I’ll have to check out your updates and wee what you made different, except for changing the name :)

      • Anok
        June 21, 2013 at 14:33

        The script is now hosted on github, maybe you should link it here. :)

        • June 21, 2013 at 19:24

          If you read the reply from Bob, he updated the script and site to have better documemtation.

          I’ll probably write another post about this after some time.

  4. ahmiq
    September 24, 2013 at 16:23

    anything for centos? i have given up :(

  5. Mike
    November 21, 2013 at 22:03
  6. ardi
    January 17, 2014 at 09:35

    please edit
    localip 10.1.0.1
    remoteip 10.1.0.2-100

  7. July 22, 2014 at 09:23

    Hiya very cool blog!! Man .. Excellent .. Wonderful ..
    I’ll bookmark your site and take the feeds additionally?
    I am glad to find so many useful information here
    within the post, we want work out more strategies in this regard, thank you for sharing.

    . . . . .

  8. July 22, 2014 at 15:11

    Hey! Quick question that’s entirely off topic.
    Do you know how to make your site mobile friendly? My blog
    looks weird when viewing from my iphone 4. I’m trying to find a template or
    plugin that might be able to correct this problem. If you have any suggestions, please share.
    Cheers!

  9. July 22, 2014 at 15:13

    It’s remarkable in favor of me to have a site, which is useful in support
    of my knowledge. thanks admin

Leave a Reply

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