10 Feb 2011

Open VPN di UBUNTU

Virtual Private Network (VPN) adalah hubungan antar jaringan privat yang melalui
channel komuikasi jaringan public seperti internet. Dengan VPN memungkinkan Anda
dari manapun dapat mengakses jaringan lokal kantor Anda. VPN umumnya memanfaatkan
metode tunneling , dimana antar jaringan membentuk channel komunikasi baru antar
jaringan itu sendiri dengan menggunakan protokol point to point. Karena VPN ini
memanfaatkan channel komunikasi jaringan public maka security dalam VPN menjadi mutlak.
Untuk itu dibutuhkan suatu mekanisme komunikasi via VPN yang lebih aman salah satu caranya
adalah memanfaatkan SSL (secure socket layer). Komuinikasi menggunkan SSL memungkinkan
traffic data antar jaringan VPN tersebut dienkripsi terlebih dahulu sebelum melewati cahnnel
komunikasi public.
Selain memanfaatkan SSL, untuk VPN Anda dapat memanfaatkan protokol IPSec. Dalam materi ini
kita hanya akan membahas VPN dengan SSL. Untuk itu kita membutuhkan aplikasi yang memungkinkan
kita untuk membangun VPN via SSL tersebut. Aplikasi open source yang mendukung VPN via SSL yaitu OpenVPN.
buah server yang memiliki IP public tetap diperlukan sebagai VPN server:

root@efrizal# apt-get install openvpn
root@efrizal# cd /etc/openvpn
root@efrizal# cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 easy-rsa
root@efrizal# cd easy-rsa

Edit file vars pada bagian

KEY_COUNTRY=ID
KEY_PROVINCE=JABAR
KEY_CITY=DEPOK
KEY_ORG=NF
KEY_EMAIL= efrizal@nurulfikri.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Kemudian jalankan

root@efrizal#source ./vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys

root@efrizal#./clean-all

root@efrizal# ./build-ca
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 incorporated
into 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 blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [INDONESIA]: enter
string is too long, it needs to be less than 2 bytes long
Country Name (2 letter code) [INDONESIA]:ID
State or Province Name (full name) [DKI]:enter
Locality Name (eg, city) [JAKARTA]:eneter
Organization Name (eg, company) [nf]:enter
Organizational Unit Name (eg, section) []:COmputer
Common Name (eg, your name or your server’s hostname) [nf CA]:nurulfikri.com
Email Address [ efrizal@nurulfikri.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it ]:enter

root@efrizal-laptop:/etc/openvpn/easy-rsa# ./build-key-server server

Generating a 1024 bit RSA private key
……++++++
…++++++
writing new private key to ’server.key’
—–

Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:rendang
An optional company name []:nf
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject’s Distinguished Name is as follows
countryName :PRINTABLE:’ID’
stateOrProvinceName :PRINTABLE:’JABAR’
localityName :PRINTABLE:’DEPOK’
organizationName :PRINTABLE:’NF’
commonName :PRINTABLE:’server’
emailAddress :IA5STRING:’ efrizal@nurulfikri.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it
Certificate is to be certified until Jan 9 10:30:01 2020 GMT (3650 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

root@efrizal#./build-dh

Lihat keys apakah sudah di generate

root@efrizal#ls -l /etc/openvpn/easy-rsa/keys

root@efrizal#cd keys
root@efrizal# cp ca.crt ca.key dh1024.pem server.crt server.key ../..
root@efrizal# cd ../..
root@efrizal# cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz .

(Membuat key untuk admin jika anda inginkan)

# ./build-key admin
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

(Membuat key untuk user jika di perlukan)

./build-key-pass namauser
./build-key namauser

root@efrizal# gunzip server.conf.gz
root@efrizal# mv server.conf openvpn.conf
kemudian lakukan perintah ./build-dh lagi.

Melakukan test key

# openvpn –genkey –secret key
# openvpn –test-crypto –secret key

Atur konfigurasinya di /etc/openvpn/openvpn.conf
lalu aktifkan konfigurasi berikut (tanda ; didepan di hapus)

proto tcp
dev tun
ca ca.crt
cert server.crt
key server.key
client-to-client
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 20
comp-lzo
max-client 250
persist-key
persist-tun
status openvpn-status log
verb 3

Restart daemonnya:

root@efrizaL# /etc/init.d/openvpn start
atau
root@efrizal#openvpn –config /etc/openvpn/server/conf

Pantau aktifitasnya dengan cara:

root@efrizal# tail -f /var/log/daemon.log

Selanjutnya pembuatan file sertifikat untuk masing-masing VPN client:

root@efrizal#cd /etc/openvpn/easy-rsa
root@efrizal#source ./vars
root@efrizal#./build-key depok
root@efrizal#cd key/

Kirim ca.crt, bogor.crt, dan bogor.key ke client, Anda bisa menggunakan email dengan melampirkan attachment. Lakukan hal serupa untuk VPN client lainnya, misal untuk cabang bandung, surabaya, dst.

Client
Selanjutnya di komputer client dipasang juga paket openvpn yang sama, hanya beda di konfigurasi.

root@efrizal#apt-get install openvpn
root@efrizal#cd /etc/openvpn

Letakkan ca.crt, depok.crt, dan depok.key di sini.

root@efrizal#mv bogor.crt client.crt
root@efrizal#mv bogor.key client.key
root@efrizal#cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf openvpn.conf

Edit openvpn.conf, sesuaikanlan dengan VPN server Anda, atau bisa juga langsung menyebutkan IP public-nya:

..
proto tcp
..

Lalu restart daemon-nya:

root@efrizal# /etc/init.d/openvpn restart

Perhatikan prosesnya:

root@efrizal# tail -f /var/log/daemon.log

Nantinya akan muncul network device tun0:

root@efrizal# ifconfig tun0

Lakukanlah hal serupa untuk komputer client lainnya, dan cobalah ping satu sama lain.

Jika ingin melihat sambungan OpenVPN dari dua (2) Windows.

cd /etc/openvpn
cp -Rf /usr/share/doc/openvpn/examples/sample-config-files/ /etc/openvpn/
cp -Rf /usr/share/doc/openvpn/examples/sample-keys/ /etc/openvpn/
openvpn –config sample-config-files/loopback-client
openvpn –config sample-config-files/loopback-server

Jika di perlukan kita dapat menginstalasi OpenVPN Administrator. Contoh menginstalasi OpenVPN-Admin

# apt-get install mono openvpn-admin

0 komentar:

Posting Komentar