I have a headless machine running Lubuntu that I'm using a file server. I already SSH into it, and use remote desktop from within my local network to do any maintenance I need, either on the desktop or via the terminal.

The last step, as far as I can see, is setting up a VPN. I would call myself an intermediate computer user; I can use the terminal from instructions comfortably, and understand the basics of LAN and WAN. Unfortunately, the instructions I can find for setting up a reliable VPN on Ubuntu (I believe OpenVPN) are either incomplete, incorrect or too complex. All I want is to have the VPN running on my server from startup, and use it on a laptop, mobile and tablet when out and about to access files and music.

Can anybody either help me out directly, or point me to a well-written, reliable web resource that can help me? I'm pulling my hair out...


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.

First, install the required software:

sudo apt-get install pptpd

Second, enable ip_forward in the kernel for IPv4 by uncommenting the associated line in /etc/sysctl.conf:

sudo sed -i -r 's/^\s*#(net\.ipv4\.ip_forward=1.*)/\1/' /etc/sysctl.conf

Reload the config file to have the change take effect immediately.

sudo -i sysctl -p

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:

OUTIF=`/sbin/ip route show to exact 0/0 | sed -r 's/.*dev\s+(\S+).*/\1/'`

sudo -i iptables --table nat --append POSTROUTING --out-interface $OUTIF --jump MASQUERADE

Enable NAT on boot from the rc.local script.

CMD="iptables --table nat --append POSTROUTING --out-interface $OUTIF --jump MASQUERADE"
sudo sed -i "\$i$CMD\n" /etc/rc.local

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.

KEY=`head -c 20 /dev/urandom | sha1sum | nawk '{print $1}'`
echo "$USER pptpd $KEY *" | sudo tee -a /etc/ppp/chap-secrets

Finally, you are ready to...

  • Thank you for this response - is there any admin software that I can use once I have installed from the terminal? Also, I do have UFW - where should have to look for the documentation? Is it just allowing the ports that VPNs typically use? Jul 31 '15 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.