Setting up a Poptop (PPTP) VPN on Ubuntu
This is a pretty useful trick if you need to get around a corporate firewall or the Great fireWall of China. It still allows PPTP through, setting it up is pretty easy and unlike OpenVPN it’s supported by every major OS without any additional software. You can even use it from your iPhone.
To get it going you need one server or VPS that you have access too. Install pptpd with
sudo apt-get install pptpd
Now to edit some files… I’d suggest giving your machine a static IP address by editing /etc/network/interfaces (be careful, if you are not using the server version of Ubuntu Network Manager will most likely take over and set your machine back to DHCP. I’d recommend disabling Network Manager or trying to set a Static IP through it.
You will first need to figure out what subnet your router is using. The quickest way to do this is just to type ifconfig at the command prompt. Look for the output from
eth0, it should look something like this:
eth0 Link encap:Ethernet HWaddr 00:22:22:22:22:22
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::240:45ff:fe26:775a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:225008 errors:0 dropped:0 overruns:0 frame:0
TX packets:76464 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32669088 (32.6 MB) TX bytes:21169594 (21.1 MB)
Interrupt:23 Base address:0xc800
The blue line is the one that you need to pay attention to. To drastically oversimplify, the numbers next to inet addr, are your IP address and the first three represent your subnet. Ok, I’m too lazy to write the rest of this with that much detail. Long story short:
- set your current IP address with
/etc/network/interfacesto a static IP. - edit
/etc/pptpd.confand add this:
localip 192.168.1.101
remoteip 192.168.1.20-24
changing the IPs to match your network’s config. - Add a line to /etc/ppp/chap-secrets with desired name and password
- Uncomment and enable the the
#net.ipv4.ip_forward=0line in/etc/sysctl.conftonet.ipv4.ip_forward=1 - Edit /etc/rc.local and add the following before the
exit 0:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i ppp0 -o eth0 -j ACCEPT - Execute
/etc/init.d/rc.local startto start the IP masquerading - Execute
sysctl -pto refresh the sysctl.conf settings you changed
That should do it.
References:
http://www.sharedknowhow.com/2008/09/linux-vpn-server-installation-for-use-with-iphone/
http://www.ubuntugeek.com/howto-pptp-vpn-server-with-ubuntu-10-04-lucid-lynx.html