Anyway what is openvpn?
http://en.wikipedia.org/wiki/OpenVPN
Okay, let's begin.
First off all install CentOS on your vps, here i'm using SolusVM for OS install and choose CentOS 5.5
I'm using CentOS 5.5 because TUN/TAP is not available in CentOS 32bit and x86. Okay, the installation will be finish in approximately 30 minutes, after finished now login to root using ssh.
Before we're going to install OPENVPN, check your TUN/TAP whether it is active or not, if it's not you can try to install another CentOS or contact your vps provider to activate TUN/TAP.
#cat /dev/net/tun
if you're TUN/TAP status is like that, then your TUN/TAP is ready, otherwise it's not.
Now we're begin the installation, first of all install gcc and make.
#yum install gcc make
Download package for OPENVPN
#wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm
Download repository for OPENVPN
if you're using 32bit version
#wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
if you're using 64bit version
#wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
you can check your server architecture with:
#uname -a
Install package needed for OPENVPN
#yum install rpm-build
#yum install autoconf.noarch
#yum install zlib-devel
#yum install pam-devel
#yum install openssl-devel
Install the downloaded rpm package and add the repository to your CentOS
#rpmbuild --rebuild lzo-1.08-4.rf.src.rpm
#rpm -Uvh /usr/src/redhat/RPMS/x86_64/lzo-*.rpm
#rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
note: check your architecture engine, if you're using 32bit then change "x86_64" to "i386"
Install OPENVPN
#yum install openvpn
Copy the folder for creating certificate to directory /etc/openvpn/
#cp -r /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
Now let's create the certificate
#cd /etc/openvpn/easy-rsa/2.0
#chmod 755 *
#source ./vars
#./vars
#./clean-all
Build CA
#./build-ca
you'll be asked to fill the field data, you can empty that with click enter repeatedly, but the one you have to fill is the "Common Name" field.
Build Key Server
#./build-key-server server
same as build-ca, but in the "Common Name" fill with: server
Build Diffie Hellman
#./build-dh
Building certificate done, now we create the configuration file in the directory /etc/openvpn
#cd /etc/openvpn
#nano server.conf
you can also use vi or pico editor to create the configuration file
Here is the example of configuration file.
local 123.123.123.123 #- change it with your server ip address
port 1234 #- change the port you want
proto udp #- protocol can be tcp or udp
dev tun
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so /etc/pam.d/login
client-cert-not-required
username-as-common-name
server 1.2.4.0 255.255.255.0
push "redirect-gateway def1"
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 4.2.2.1"
keepalive 5 30
comp-lzo
persist-key
persist-tun
status server-tcp.log
verb 3
Now start the OPENVPN
#openvpn /etc/openvpn/server.conf
if the status is Initialization Sequence Completed then your OPENVPN is ready.
Now we're enabling ip forward and create NAT iptables rules so we can access the internet with OPENVPN server.
#echo 1 > /proc/sys/net/ipv4/ip_forward
If you're using VPS:
#iptables -t nat -A POSTROUTING -s 1.2.3.0/24 -j SNAT --to 123.123.123.123
If you're using Dedicated Server:
#iptables -t nat -A POSTROUTING -s 1.2.3.0/24 -o eth0 -j MASQUERADE
Install process is done, now create user for you OPENVPN.
#useradd username -s /bin/false
#passwd username
to delete existing user, you can use
#userdel username
Now go to your OPENVPN GUI config folder and create client configuration file. This is the example for client configuration.
client
dev tun
proto udp
remote 123.123.123.123 4567 #- your OPENVPN server ip and port
resolv-retry infinite
nobind
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
persist-key
persist-tun
ca ca.crt
auth-user-pass
comp-lzo
verb 3
save the configuration with filename.ovpn.
And the last thing you have to do is download ca.crt file in directory /etc/openvpn/easy-rsa/2.0/keys to your PC and save to the OPENVPN GUI config folder.
Your OPENVPN is ready!
if you want to test OPENVPN, here's the config file:
http://rapidshare.com/files/407751537/vpn4free_cfg_test.rar
rar pass: vpn4free.org
Reference:
http://blog.hostgokil.com/tutorial-instalasi-openvpn-di-vps-centos.html
http://paijrut.net/?p=7
http://www.kaskus.us/showthread.php?t=4437825
This worked, Thanks mate.
ReplyDeletewho is your VPS provider?
thanks very helpful
ReplyDeleteThis is awesome!
ReplyDeleteCan you make a script for this?
I shall highly appreciate it.
very informative. thanks for sharing. will probably try this.
ReplyDeletethank you for this its good for business
ReplyDeleteHi this one is great and is actually a high-quality post. uk vpn
ReplyDelete