Assuming I have a Virtual Private Server from someone like Linode, running Ubuntu, how do I easily set up a PPTP VPN so that Ubuntu clients can connect to it?
By default, Ubuntu offers to connect to these PPTP networks. I want to set it up in such a way that it's very easy to connect to (I.e. without installing any packages on the client).
The Absolute Minimum Server Setup
What follows are the absolute minimum instructions that you need to get a basic PPTP VPN server running under Ubuntu. Clients will then be able to VPN into the server and route their internet traffic so that it goes through the server to the internet. As always, consult the full documentation to understand what everything is doing.
First, install the required software:
Second, enable
ip_forward
in the kernel for IPv4 by uncommenting the associated line in /etc/sysctl.conf:Third, enable NAT (if it isn't enabled already) so that users on the private VPN network can have their packets routed out to the internet:
Note: This guide assumes you have no firewall configured on the server. If you have a firewall on the server, such as UFW, consult the relevant documentation instead.
Fourth, for each VPN user, create an account in the file /etc/ppp/chap-secrets. Replace
$USER
with the actual username you want to use for that VPN user.Finally, you are ready to...
Configure the Client
In the Network Manager applet, select VPN Connections → Configure VPN, then click Add. On the next screen select PPTP for the VPN type, then click Create.
In this window, enter your server's hostname or IP along with the username and key that you added to the /etc/ppp/chap-secrets file on the server.
Now click Advanced.
In this window, enable "Use Point-to-Point encryption (MPPE)" and select 128-bit security. Disable the use of MSCHAP authentication (leave MSCHAPv2 enabled).
Finally, click Ok and then Save to close out the previous window.
You can now test the VPN connection by going to the Network Manager applet → VPN Connections and selecting the connection that you just created. Make sure you get a message saying that the VPN connection was successful, then browse to an IP checking website to verify that your IP now shows up as the server's IP.
If you get a message saying that the VPN connection to the server failed: first verify that you correctly entered the client settings; second, check that the client has network connectivity to TCP port 1723 on the server; finally, check the log file /var/log/messages on the server for further clues. If your VPN connection succeeds, but you subsequently are unable to browse to any websites from the client, consult this incredibly helpful diagnostic guide on the pptpd website.
Notes
If the local network you are connected to is using the 192.168.0.0/24 and 192.168.1.0/24 subnets, you are going to run into issues because that is what the PPTP server uses by default. You will have to configure PPTP to use different subnets in pptpd.conf.
There are numerous other configuration changes you may want to make. For example, all your domain name lookups will still be queried using your local DNS server instead of going through the PPTP server. Take the time to read over the full documentation to find out how to change this setting and many others.
This tutorial I wrote will guide you through. It should help you avoid common mistakes made by people using VPS.
First login into your VPS Panel and enable TUN/TAP and PPP. If you do not have such option contact your ISP to enable this for you.
First install this package:
Because we do not want our VPN to be public we are going to create users.
I am using VI you can use NANO or whatever text editor you like
The format is
Example
*
means access from all IP addresses is allowed, specify IP only if you have static one.Editing PPTPD Settings
Look for the localip and remoteip settings. Remove the
#
(comment character) for both so that these settings will actually be recognized. Change localip to your server IP. If you don’t know your server IP, you may look in your VPS control panel.The remoteip is basically the IP range that clients (computers that are connected to your VPN) will be assigned. For example, if you want the following IP range: 192.168.120.231-235, your VPN server will be able to assign 192.168.120.232, 192.168.120.233, 192.168.120.234, and 192.168.120.235 to clients. It’s up to you what you want to use for this field.
Personally I choose this settings:
So I can get about 200 clients connected.
Add DNS servers to
/etc/ppp/pptpd-options
You can whether add this to end of file or find those lines, uncomment them and change IPs to your desired Public DNS.
Set up Forwarding
It is important to enable IP forwarding on your PPTP server. This will allow you to forward packets between public IP and private IPs that you setup with PPTP. Simply edit /etc/sysctl.conf and add the following line if it doesn’t exist there already:
To make changes active, run
sysctl -p
Create a NAT rule for iptables
This is an important part, if you are using VPS you probably wont use eth0 but venet0 instead, you should check which interface you have by running
ifconfig
If you would also like your PPTP clients to talk to each other, add the following iptables rules:
Again, you need to replace eth0 with venet0 if you are using VPS.
I would recommend running
Now your PPTP server also acts as a router.
You can run this command so the VPN service starts on boot
I recommend installing iptables-persistent so rules stay even after reboot
Follow this tutorial: PPTP VPN Server with Ubuntu