How to Configure a VPN on an Ubuntu VPS

Install pptpd


  1. $ sudo apt–get 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.2–10

Second line is the IP range to assign 

Set DNS


  1. $ sudo vi /etc/ppp/pptpd–options

Modify the following section to use Google DNS:


  1. ms–dns 8.8.8.8
  2. ms–dns 8.8.4.4

Set account:


  1. $ sudo vi /etc/ppp/chap–secrets

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 apt–get install iptables

Set up NAT:


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

Save rules so they persist after reboot:


  1. sudo iptables–save >/etc/iptables–rules

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. pre–up iptables–restore </etc/iptables–rules

Set MTU to prevent oversized packets:


  1. sudo iptables –A FORWARD –s 10.100.0.0/24–p tcp –m tcp —tcp–flags SYN,RST SYN –j TCPMSS —set–mss 1200

If set, remember to save:


  1. sudo iptables–save >/etc/iptables–rules

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.