Thursday, August 16, 2012

How to Install VPN Server in Ubuntu

I am going to install a VPN server on my own ubuntu server to be connected to it from anywhere of this world. I am going to use pptpd package.

First, I have installed the package using the following code
sudo apt-get install pptpd


Then, I have to configure this. I have to edit /etc/pptpd.conf file.

I have commanded in terminal as follow:

sudo vim /etc/pptpd.conf


Added following two lines:

localip 192.168.0.10
remoteip 192.168.0.230-239

Now I have to add user credentials to the file /etc/ppp/chap-secrets as follows:


# client    server  secret          IP Address
moin        pptpd   somepassword    "*" 


At last, I have to restart pptpd daemon using following command

sudo service pptpd restart 

 To allow access to the VPN server from Internet, I had to edit /etc/sysctl.conf using the following command

sudo vim /etc/sysctl.conf

I have uncommented the following line

net.ipv4.ip_forward=1
 
(to search the line press esc and write /net.ipv4.ip_forward=1 
and press enter. then delete "#")
 
Then use iptables to get the net forwarded:

/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE
 
Optionally you can install bind9 and have a DNS resolver you can use for the vpn connection:

apt-get install bind9 -y
 
Then start it:

/etc/init.d/bind9 start
 
It's done. It worked for me, hope, also work for you.