Kamis, 17 Oktober 2013

Install openVPN di VPS CentOS 5

01.04

http://fadhly.web.id/wp-content/uploads/2013/02/openvpn_logo1.pngHai kembali bersama saya yg kangen untuk share yg kali ini mengenai langkah² instalasi openVPN ke VPS.
begini langkahnya :D

Sebelumnya cek dahulu apakah Tun/Tap di vps sudah aktif apa belum, begini caranya :


ketikan command ini:
# ls -al /dev/net/tun
apabila sudah enabled maka akan muncul pesan seperti berikut:
crw——- 1 root root 10, 2010 May 10 16:21 /dev/net/tun
dan bila belum aktif lakukan langkah berikut ini  :
#mkdir -p /dev/net
#mknod /dev/net/tun c 10 200
#chmod 600 /dev/net/tun
#ls -al /dev/net/tun
langkah selanjutnya install gcc, autoconf.noarch, zlib-devel, pam-devel, openssl-devel
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 tidak 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 IPMU/24 -o eth0 -j MASQUERADE
Sedangkan untuk VPS (openvz), command nya adalah sbb:
#iptables -t nat -A POSTROUTING -s IPMU/24 -o venet0 -j SNAT --to 74.208.x.x
IP disesuaikan dengan IP venet0 di VPS anda.
Tutor Ini Dari SHL :))

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 komentar:

Posting Komentar

 

© 2013 I'Learning. All rights resevered. Designed by Templateism

Back To Top