How To Set Up A VPN In A VPS

Looking for a simple, stable and significant VPS as your web hosting? Check out DigitalOcean, only $5 per month, and you can get $10 in credit just for signing up now.

Want to set up a VPN yourself instead to use others’? This post will show you a very simple way to do that, and what you need is a computer and a VPS.

The following steps are based on the Terminal application of Mac, for Linux, the steps will be nearly the same, and for Windows, you need to install the Putty tool to run those commands. Here we go:

1. Buy a VPS

To start off, you need to buy an Xen (not OpenVZ) VPS, and choose to install a Ubuntu operating system.

By the way, during the buying process, you need to enter a domain, which can be any one if you just need to set up a VPN in the VPS.

P.S.:

The prices of VPS machines are not cheap (usually over $5 per month), you can search Google and find a suitable one.

how to set up a vpn

2. Connect to your VPS

Run your Terminal, and enter the following command:

ssh [email protected]

Just replace "xxx.xxx.xxx.xxx" with your VPS’ IP, such as "178.18.17.212".

Then you will see the following message:

Are you sure you want to continue connecting (yes/no)?

Enter "yes" and press the "Return" key, then, enter your password and press the "Return" key.

P.S.:

If you’ve rebuilt your VPS, you may meet the following error:

Host key verification failed.

In that case, enter the following command at first:

ssh-keygen -R xxx.xxx.xxx.xxx

Remember to replace "xxx.xxx.xxx.xxx" with your VPS’ IP address.

3. Install PPTPD

Copy and paste the following command:

apt-get install pptpd

Then you will see the following message:

Do you want to continue [Y/n]?

Press the "Y" key and then the "Return" key.

4. Edit the VPN interface IP addresses

Copy and paste the following command:

nano /etc/pptpd.conf

Press the "Return" key, scroll down the cursor with the Down arrow key to the end and find the following codes:

#localip 192.168.0.1
#remoteip 192.168.0.234-238,192.168.0.245

Put the cursor after the 2 "#" symbols and press the "Delete" key to remove them.

Press the "Control" & "X" keys, and press the "Y" key, then press the "Return" key to save your revision.

P.S.:

By the way, you can also use the "Vi" command instead of "Nano", but more difficult.

5. Edit DNS addresses

Copy and paste the following command:

nano /etc/ppp/pptpd-options

Press the "Return" key and scroll down the cursor with the Down arrow key to the following codes:

#ms-dns 10.0.0.1
#ms-dns 10.0.0.2

Change the above codes to the following ones:

ms-dns 8.8.8.8
ms-dns 8.8.4.4

(Tips: You can also copy the above codes and paste it under the original ones.)

After that, press the "Control" & "X" key, and press the "Y" key, then press the "Enter" key to save your revision.

P.S.:

The above are Google’s Public DNS IP addresses, you can also replace them with OpenDNS: 208.67.222.222 & 208.67.220.220.

6. Add VPN accounts

Copy and paste the following command:

nano /etc/ppp/chap-secrets

Press the "Return" key and enter the following information:

username pptpd password *

For example:

freenuts pptpd 123456 *

(P.S.: You need to press the Tab key to make a pace among each value.)

After that, press the "Control" & "X" keys, and press the "Y" key, then press the "Return" key to save your revision.

7. Forward IPv4

Copy and paste the following command:

nano /etc/sysctl.conf

Press the "Return" key and then press the Down arrow key to move the cursor to the following line:

#net.ipv4.ip_forward=1

Move the cursor to the end of the "#" symbol and remove it with the "Delete" key.

Press the "Control" & "X" keys, and press the "Y" key, then press the "Enter" key to save your revision.

8. Apply the forward

Your forward change won’t be active immediately, and you need to apply it with the following commend:

sysctl -p

If everything is correct, then you can see the following result:

net.ipv4.ip_forward = 1

9. Allow the routing

Copy and paste the following command:

iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE

Press the "Return" key.

10. Restart PPTPD

Copy and paste the following command:

/etc/init.d/pptpd restart

Press the "Return"key, then you can use your VPN with the username and password you’ve set before.

P.S.:

It may be not available for you to connect to a PPTP VPN in Mac Air OS X 10.6 due to an unknown bug.

Bonus:

The following is a PPTP VPN account created in a 2Host VPS according to the above 10 steps:

Server Address: 178.18.17.212
Account Name: freenuts
Password: 123456

The above VPN will be free and available for a month, and you can check out this post for how to use it in your computer and mobile phone.

Spread the love
This entry was posted in Other Free Nuts and tagged , . Bookmark the permalink.