Selasa, 29 April 2008

Konfigurasi VPN ( Virtual Private Network )

untuk instalasi sebaiknya memakai yum install saja agar lebih gampang,agar tidak dipusingkan dengan dependency2-nya
[irfan@localhost]#yum install -y openvpn

untuk membangun koneksi OpenVPN ada 2 cara, menggunakan Static Key dan menggunakan Certificate Authority (CA),masing2 mempunyai kelebihan dan kekurangan

Cara yang pertama yaitu menggunakan Static Key, cara ini hanya dapat digunakan untuk koneksi OpenVPN antara satu server dan satu client tetapi cara ini mempunyai konfigurasi yang simple
Berikut gambar topology yang akan kita gunakan untuk eksperimen


Dalam kasus ini kita umpamakan PC01 sebagai server machine dan PC02 sebagai client server

#Konfigurasi pada machine server
masuk ke direktory /etc/openvpn dan buat key di direktory tersebut

[PC01@localhost]# cd /etc/openvpn/
[PC01@localhost]# openvpn –genkey –secret kunci.key

setelah key selesai dibuat,kemudian copy key tersebut ke machine client pada direktory /etc/openvpn (dlm hal ini aku menggunakan perintah scp untuk proses peng-copy-an –lebih lanjut tentang perintah scp dapat dibaca pada artikel lain di web-blog ini

[PC01@localhost]# scp kunci.key root@client_node:/etc/openvpn

setelah itu buat file baru server.conf pada /etc/openvpn kemudian isikan konfigurasi seperti dibawah ini,tutup kemudian simpan file tsb

[PC01@localhost]#vi server.conf
dev tun //menggunakan tunnel untuk membangun koneksi openVPN
ifconfig 222.222.222.1 222.222.222.2 //IP address yg digunakan untuk tunnel (awas jng sampai kebalik antara server dg client)
secret kunci.key //nama file key yang telah kita buat tadi
comp-lzo //data yg ditransfer akan di compress dengan metode ini

#Konfigurasi pada machine client
buat file baru dengan nama client.conf di /etc/openvpn kemudian isikan file konfigurasi seperti dibawah ini setelah selesai tutup dan simpan file tsb

[PC02@localhost]# cd /etc/openvpn/
[PC02@localhost]# vi client.conf
remote 172.29.1.1 //IP address server machine
dev tun //menggunakan tunnel untuk membangun koneksi openVPN
ifconfig 222.222.222.2 222.222.222.1 //IP address yg digunakan untuk tunnel (awas jng sampai kebalik antara server dg client)
secret kunci.key //nama file key yang telah kita buat tadi
comp-lzo //data yg ditransfer akan di compress dengan metode ini

Setelah konfigurasi pada server dan client machine selesai dibuat kemudian jalankan openVPN pada masing2 machine
menjalankan openVPN pada server machine
masuk ke direktory /etc/openvpn
#openvpn –config server.conf
menjalankan openVPN pada client machine
masuk ke direktory /etc/openvpn
#openvpn –config client.conf
Now we test the connection
server machine

Sekarang cara yg kedua dengan menggunakan Certificate Authority (CA), cara ini dapat digunakan untuk koneksi satu server dan lebih dari satu client. Untuk maen2 kali ini kita masih mengunakan topology seperti gambar diatas

#Konfigurasi pada server machine
masuk ke /usr/share/openvpn/easy-rsa, trus edit file vars dan isikan KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, KEY_EMAIL (jangan sampe dikosongin)

#cd /usr/share/openvpn/easy-rsa
#vi vars
export KEY_COUNTRY=” ”
export KEY_PROVINCE=” ”
export KEY_CITY=” ”
export KEY_ORG=” ”
export KEY_EMAIL=” ”

Trus jalanin perintah dibawah ini untuk menginisialisasi PKI (public key infrastructure)
#. ./vars
#./clean-all
#./build-ca //membuat certificate authority (CA)

membuat key untuk server dan client, untuk contoh dibawah saya membuat key untuk 1 server dan 2 client
#./build-key-server server
#./build-key client1
#./build-key client2

next step untuk men-generate Diffie Hellman parameter
#./buil-dh
Jika langkah2 diatas berhasil maka akan ada direktory keys di /usr/share/openvpn/easy-rsa, copy direktory keys tsb ke /etc/openvpn
#cp -r /usr/share/openvpn/easy-rsa/keys /etc/openvpn/
masuk ke direktory keys tsb dan copy ca.crt,client1.crt,client1.key ke /etc/openvpn/ client1 machine (lakukan perintah yg sama pada client2 machine)

Setelah itu copy /usr/share/doc/openvpn-2.0.7/sample-config-files/server.conf ke /etc/openvpn dan edit file server.conf yg telah di copy tadi sesuai kebutuhan (konfigurasi server.conf akan dijelaskan dibawah)
#cp /usr/share/doc/openvpn-2.0.7/sample-config-files/server.conf /etc/openvpn
#vi /etc/openvpn/server.conf

#Konfigurasi pada client machine
Copy /usr/share/doc/openvpn-2.0.7/sample-config-files/client.conf ke /etc/openvpn dan edit file client.conf yg telah di copy tadi sesuai kebutuhan (konfigurasi client.conf akan dijelaskan dibawah)
#cp /usr/share/doc/openvpn-2.0.7/sample-config-files/client.conf /etc/openvpn
#vi /etc/openvpn/client.conf

Sekarang kita akan langsung aja maen2 dg contoh topology diatas
Example #1
Host-to-host
Contoh pertama kita akan membangun koneksi openVPN antara PC01 (server) dan PC02 (client)

#konfigurasi pada server machine
[PC01@localhost]#vi /etc/openvpn/server.conf
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb3

jalankan service openvpn
[PC01@localhost]#service openvpn start
[PC01@localhost]#cd /etc/openvpn/keys
[PC01@localhost]#openvpn –config server.conf

#konfigurasi pada client machine
edit /etc/openvpn/client.conf
[PC02@localhost]#vi /etc/openvpn/client.conf
client
dev tun
proto udp
remote 172.29.1.1 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
comp-lzo
verb 3

jalankan service openvpn
[PC02@localhost]#service openvpn start
[PC02@localhost]#cd /etc/openvpn/keys
[PC02@localhost]#openvpn –config client.conf

#Test koneksi

Example #2
Network-to-host
Contoh kedua kita akan membangun koneksi openVPN antara PC01 (server) dan PC02 (client).Sebagai tambahan PC02 dapat terkoneksi dengan PC03 (network dari PC01)

#konfigurasi pada server machine
[PC01@localhost]#vi /etc/openvpn/server.conf
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push “route 172.29.2.0 255.255.255.0″
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb3

jalankan service openvpn
[PC01@localhost]#service openvpn start
[PC01@localhost]#cd /etc/openvpn/keys
[PC01@localhost]#openvpn –config server.conf

#konfigurasi pada client machine
[PC02@localhost]#vi /etc/openvpn/client.conf
client
dev tun
proto udp
remote 172.29.1.1 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
comp-lzo
verb 3

jalankan service openvpn
[PC02@localhost]#service openvpn start
[PC02@localhost]#cd /etc/openvpn/keys
[PC02@localhost]#openvpn –config client.conf

Example #3
Network-to-network
Contoh ketiga kita akan membangun koneksi openVPN antara PC01 (server) dan PC02 (client).Sebagai tambahan network dari PC02 dapat terkoneksi dengan network PC01

#Konfigurasi server machine
[PC01@localhost]#vi /etc/openvpn/server.conf
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push “route 172.29.2.0 255.255.255.0″
client-config-dir ccd
route 172.29.3.0 255.255.255.0
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb3

#buat directory ccd dan file client di /etc/openvpn/keys dan isikan konfigurasi seperti dibawah
[PC01@localhost]#mkdir /etc/openvpn/keys/ccd
[PC01@localhost]#cd /etc/openvpn/ccd
[PC01@ keys]#vi client
iroute 172.29.2.0 255.255.255.0

jalankan service openvpn
[PC01@localhost]#service openvpn start
[PC01@localhost]#cd /etc/openvpn/keys
[PC01@localhost]#openvpn –config server.conf

#konfigurasi pada client machine
[PC02@localhost]#vi /etc/openvpn/client.conf
client
dev tun
proto udp
remote 172.29.1.1 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
comp-lzo
verb 3

jalankan service openvpn
[PC02@localhost]#service openvpn start
[PC02@localhost]#cd /etc/openvpn/keys
[PC02@localhost]#openvpn –config client.conf

Tidak ada komentar: