Friday, May 25, 2012

Install OpenVPN di VPS

Cek terlebih dahulu apakah VPS atau server anda mendukung dev/tun dg cara berikut:
# ls -al /dev/net/tun
crw------- 1 root root 10, 200 2009-08-01 01:45 /dev/net/tun
Install and build paket yang dibutuhkan :
#yum install gcc rpm-build autoconf.noarch zlib-devel pam-devel openssl-devel make -y
Download paket yang diperlukan :
#wget http://openvpn.net/release/openvpn-2.0.9.tar.gz
#wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm
Install paket yang telah didownload dengan cara berikut :
#rpmbuild --rebuild lzo-1.08-4.rf.src.rpm
#rpm -Uvh /usr/src/redhat/RPMS/i386/lzo-*.rpm
#rpmbuild -tb openvpn-2.0.9.tar.gz
#rpm -Uvh /usr/src/redhat/RPMS/i386/openvpn-2.0.9-1.i386.rpm
apabila mesinnya menggunakan 64bit maka direktorinya biasanya: /usr/src/redhat/RPMS/x86_64/
Sekarang kita copy file konfigurasi nya menuju folder /etc/openvpn
#cp -r /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
Building certificate (membuat sertifikat), masuk direktori /etc/openvpn/easy-rsa/2.0
#cd /etc/openvpn/easy-rsa/2.0
#source ./vars
#./vars
#./clean-all
#./build-ca
akan muncul tulisan2 aneh seperti ini:
Generating a 1024 bit RSA private key
………………………++++++
…………………….++++++
writing new private key to ‘ca.key’
—–
You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter ‘.’, the field will be left blank.—–
Country Name (2 letter code) [KG]:
State or Province Name (full name) [NA]:
Locality Name (eg, city) [BISHKEK]:
Organization Name (eg, company) [OpenVPN-TEST]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server’s hostname) []:
OpenVPN-CAEmail Address [me@myhost.mydomain]:
Kalau tdk mau repot tekan enter saja.
Build key server
#./build-key-server server
Akan keluar tulisan2 seperti yang diatas, yg perlu diisi hanya pada “Common Name”, di sini masukkan kata: server
Build Diffie Hellman
#./build-dh
Build certificate untuk client:
#./build-key vpnhome
Akan keluar tulisan2 seperti yang diatas, yg perlu diisi hanya pada “Common Name”, di sini masukkan kata: vpnhome
Sekarang copy sertifikat2 tersebut ke /etc/openvpn/keys
#cp /etc/openvpn/easy-rsa/2.0/keys /etc/openvpn/keys -R
bikin file server.conf dan letakkan di /etc/openvpn , isi dengan baris berikut :
# nano /etc/openvpn/server.conf
Copas konfigyrasi berikut:
local 74.208.x.x #-- sesuaikan dengan IP server anda
port 9999 #-- port yang dibuka
proto udp #-- pilih udp atau TCP , klo TCP bisa under proxy
dev tun 
ca keys/ca.crt #-- lokasi sertifikat ca.crt
cert keys/server.crt #-- lokasi sertifikat server.crt
key keys/server.key #-- lokasi server.key
dh keys/dh1024.pem #-- lokasi dh1024.pem
server 10.8.0.0 255.255.255.0 #-- alokasi nomer IP client/server
ifconfig-pool-persist ipp.txt #-- supaya alokasi IP client tdk berubah2
push "redirect-gateway def1" #-- supaya gateway koneksi berubah ke server
push "dhcp-option DNS 4.2.2.1" #-- untuk merubah DNS
push "dhcp-option DNS 4.2.2.2" #-- sama kayak atas
keepalive 5 30 
comp-lzo #-- sistem kompresi (wajib aktif di client maupun di server)
persist-key 
persist-tun 
status server-tcp.log
verb 3

Server siap dijalankan, dengan command sbb:
#service openvpn start
atau
#openvpn /etc/openvpn/server.conf
Ok sekarang openVPN server sudah siap , sekarang tinggal bagaimana caranya supaya client dapat menikmasti koneksi seakan-akan direct connection. Yang kita akan lakukan adalah setting firewall :
1. Enabling packet forwarding dengan command:
#echo 1 > /proc/sys/net/ipv4/ip_forward
2. Edit NAT table untuk MASQUERADING
Command berikut khusus untuk server Dedicated saja:
#iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
Sedangkan untuk VPS (openvz), command nya adalah sbb:
#iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j SNAT --to 74.208.x.x
IP disesuaikan dengan IP venet0 di VPS anda.

No comments: