安装pptpd,调试时关注/var/log/syslog

参考链接: https://help.ubuntu.com/community/PPTPServer

Setup PPTP Server

First we need to install pptp server using apt-get

1
sudo apt-get install pptpd

Then we need to configure the pptpd.

1
sudo nano /etc/pptpd.conf

Add server IP and client IP at the end of the file. You can add like below:

1
2
localip 192.168.0.1
remoteip 192.168.0.100-200

This sets up the PPTP server to use IP 192.168.0.1 while distributing the IP range 192.168.0.100 to 192.168.0.200 to PPTP clients. Change these as you wish as long as they are private IP addresses and do not conflict with IP addresses already used by your server.

Configure DNS servers to use when clients connect to this PPTP server

1
sudo nano /etc/ppp/pptpd-options

Uncomment the ms-dns and add google like below or OpenDNS

1
2
ms-dns 8.8.8.8
ms-dns 8.8.4.4

Now add a VPN user in /etc/ppp/chap-secrets file.

1
sudo nano /etc/ppp/chap-secrets

The column is username. Second column is server name, you can put “pptpd” in there. Third column is password. The last column is the IP addresses, you can put * to allow all IP.

1
2
# client  server  secret  IP addresses
username * myPassword *

Finally start your server

1
/etc/init.d/pptpd restart

Setup IP Forwarding

To enable IPv4 forward. Change /etc/sysctl.conf file, add forward rule below.

1
sudo nano /etc/sysctl.conf

Uncomment the line

1
net.ipv4.ip_forward=1

Then reload the configuration

1
sudo sysctl -p

Add forward rule in iptables

1
sudo nano /etc/rc.local

adding to the bottom just before the exit 0

1
2
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE
iptables -A FORWARD -p tcp --syn -s 192.168.0.0/24 -j TCPMSS --set-mss 1356

This example is using 192.168.0 for its PPTP subnet. The second rule adjusts the MTU size :

You are done. Just reboot your server and you should be able to connect to using PPTPD and send all your traffic through this server.

Tips

以上配置在 Ubuntu 15.04中会有问题

1
sudo vi /var/log/syslog

查看日志可以看到类似的错误信息

1
2
3
Sep 28 13:56:33 Fangs-DO pppd[1435]: Plugin /usr/lib/pptpd/pptpd-logwtmp.so is for pppd version 2.4.5, this is 2.4.6
Sep 28 13:56:33 Fangs-DO pptpd[1434]: GRE: read(fd=6,buffer=7f7c2b0084a0,len=8196) from PTY failed: status = -1 error = Input/output error, usually caused by unexpected termination of pppd, check option syntax and pppd logs
Sep 28 13:56:33 Fangs-DO pptpd[1434]: CTRL: PTY read or GRE write failed (pty,gre)=(6,7)

于是根据Google出来的解决方案,不明就里地将 /etc/pptpd.conf 中的logwtmp注释掉,就搞定了。