How to Configure a VPN on an Ubuntu VPS

Install pptpd


  1. $ sudo aptget install pptpd

Edit configuration file:


  1. $ sudo vi /etc/pptpd.conf

Go to the bottom and modify IP:


  1. localip your-serverip
  2. remoteip 10.100.0.210

Second line is the IP range to assign 

Set DNS


  1. $ sudo vi /etc/ppp/pptpdoptions

Modify the following section to use Google DNS:


  1. msdns 8.8.8.8
  2. msdns 8.8.4.4

Set account:


  1. $ sudo vi /etc/ppp/chapsecrets

Add a line: username, service, password, IP restriction:


  1. “user” pptpd “user” *

Restart service:


  1. $ sudo /etc/init.d/pptpd restart

Enable forwarding:


  1. $ sudo vi /etc/sysctl.conf

Uncomment this line in the file:


  1. net.ipv4.ip_forward=1

Make it take effect immediately:


  1. sudo sysctl p

Install iptables:


  1. sudo aptget install iptables

Set up NAT:


  1. sudo iptables t nat A POSTROUTING s 10.100.0.0/24o eth0 j MASQUERADE

Save rules so they persist after reboot:


  1. sudo iptablessave >/etc/iptablesrules

If you get: -bash: /etc/iptables-rules: Permission denied, use root user with: su – to save

Edit network card file to auto-load rules:


  1. sudo vi /etc/network/interfaces

Add at the end:


  1. preup iptablesrestore </etc/iptablesrules

Set MTU to prevent oversized packets:


  1. sudo iptables A FORWARD s 10.100.0.0/24p tcp m tcp tcpflags SYN,RST SYN j TCPMSS setmss 1200

If set, remember to save:


  1. sudo iptablessave >/etc/iptablesrules

macOS can connect but no traffic issue: in VPN advanced settings, check “Send all traffic”

That is it.

Leave a Comment

Your email address will not be published.