OpenVPN merupakan aplikasi open-source untuk membuat jaringan VPN (Virtual Private Network) yang croos platform, dimana aplikasi tersebut bekerja membuat koneksi point-to-point tunnel yang telah terenkripsi. Aplikasi ini dapat berjalan di Windows/Mac OS/Linux/ dll.
Pada posting ini saya menggunakan komputer server dengan OS Linux Debian 7.2.0 jika anda menggunakan distro linux lain yang berbasis debian maka langkah-langkahnya tidak berbeda.
Untuk membuat server VPN , anda harus memiliki :
Buat username baru.
root@dzikra:~# useradd dzikra
root@dzikra:~# passwd dzikraLalu restart layanan openvpn dengan perintah :
root@dzikra:~# service openvpn restart
[ ok ] Stopping virtual private network daemon:.
[ ok ] Starting virtual private network daemon: dzikra.
root@dzikra:~#
Pada posting ini saya menggunakan komputer server dengan OS Linux Debian 7.2.0 jika anda menggunakan distro linux lain yang berbasis debian maka langkah-langkahnya tidak berbeda.
Untuk membuat server VPN , anda harus memiliki :
- Komputer server dengan alamat IP Publik agar komputer server dapat diakses lewat internet, atau anda dapat berlangganan hosting VPS seperti Digital Ocean hosting ini berada di Singapura maka otomatis server VPN anda berada di Singapura, selain itu anda juga langsung mendapat alamat IP Publik. Minimal persyaratan Hardware-nya adalah :
- Processor : memiliki 2 inti
- RAM : 4GB
- Hardisk : 50 GB
- NIC : 1 buah LAN Adapter
- OS : Linux Debian 7.2.0
- Sebuah Laptop atau komputer yang terkoneksi ke Internet, digunakan untuk meremote Server dari jarak jauh, jika tidak maka cukup konfigurasi langsung di depan layar monitor server.
Menginstall dan mengkonfigurasi OpenVPN pada server Debian
-
Jika komputer server berada jauh maka untuk menkonfigurasinya dengan cara Remote, jika langsung dari komputernya maka tidak perlu Remote, cukup langsung dari layar monitor server dan login dengan user root .
- Remote komputer server yang akan dijadikan server VPN dengan SSH login mengunakan username root .caranya ketikan perintah ini pada terminal (Linux) untuk Windows menggunakan PuTTY. ssh -l root [ALAMAT IP PUBLIK SERVER] atau ssh root@[ALAMAT IP PUBLIK SERVER]
- Jalankan perintah apt-get update dan apt-get install openvpn untuk menginstall aplikasi openvpn server pada komputer server. root@dzikra:~# apt-get update
- lalu buka direktori /etc/openvpn dan download EasyRSA pada direktori tersebut. root@dzikra:~# cd /etc/openvpn
- Konfigurasi sysctl dan iptables untuk melakukan forwarding connection terhadap OpenVPN. IPTABLES
- Buka file /etc/sysctl.conf dengan editor nano root@dzikra:~# /etc/sysctl.conf
- letakan kode ini pada baris paling bawah. kode ini berfungsi mengaktifkan IP Forwarding net.ipv4.ip_forward = 1
- Membuat file sertifikat dengan EasyRSA
- Buka direktori /etc/openvpn dan ekstark file tar.gz easy-rsa yang sudah didownload sebelumnnya root@dzikra:~# cd /etc/openvpn
- buka direktori easy-rsa-2.2.2/easy-rsa/2.0/ dan jalankan perintah source ./vars dan ./clean-all root@dzikra:/etc/openvpn# cd easy-rsa-2.2.2/easy-rsa/2.0/
- Jalankan perintah ./build-ca untuk membuat sertifikat ca komputer server, dan isi formulir tersebut berdasarkan informasi lokasi komputer server.
- jalankan ./build-key-server [nama key(bebas)] untuk membuat private key untuk komputer client , lalu isi formulir sesuai informasi lokasi komputer client.
- jalankan perintah ./build-dh lalu tunggu hingga prosesnya selesai.
- pindahkan folder keys ke direktori /etc/openvpn. root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0# mv keys/ /etc/openvpn/
- buka lagi direktori /etc/openvpn dan pindahkan file tar.gz easy-rsa ke direktori /srv root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0# cd /etc/openvpn
- Buat file konfigurasi VPN pada direktori /etc/openvpn dengan editor nano. root@dzikra:/etc/openvpn# nano dzikra.conf #Nama file bebas
contoh:
ssh -l root 12.12.12.2 atau ssh root@12.12.12.2
maka anda akan dimintai password user root seperti dibawah ini :
sosro@sosro-Satellite-M100 ~ $ ssh -l root 12.12.12.2 The authenticity of host '12.12.12.2 (12.12.12.2)' can't be established. ECDSA key fingerprint is ad:12:78:30:7f:ab:08:5d:8b:b5:37:80:69:0b:38:6f. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '12.12.12.2' (ECDSA) to the list of known hosts. root@12.12.12.2's password: Linux dzikra 3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 i686 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sun Feb 28 20:00:43 2016 root@dzikra:~#
root@dzikra:~# apt-get install openvpn
root@dzikra:/etc/openvpn# wget -O easy-rsa.2.2.2.tar.gz https://github.com/OpenVPN/easy-rsa/archive/2.2.2.tar.gz
root@dzikra:~# echo 1 > /proc/sys/net/ipv4/conf/default/forwarding
root@dzikra:~# iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j MASQUERADE
alamat ip 192.168.100.0 nantinya akan digunakan sebagai alamat interface tunelling (tun0) pada OpenVPN.
SYSCTL
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
root@dzikra:/etc/openvpn# tar zxvf easy-rsa.2.2.2.tar.gz
root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0/# source ./vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/2.0/keys
root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0/# ./clean-all
root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0/# ./build-ca Generating a 2048 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) [US]:ID #negara State or Province Name (full name) [CA]:Jawa Barat #provinsi Locality Name (eg, city) [SanFrancisco]:Bekasi #kota Organization Name (eg, company) [Fort-Funston]:Pelajar #pekerjaan Organizational Unit Name (eg, section) [MyOrganizationalUnit]:TKJ #bagian pekerjaan Common Name (eg, your name or your server's hostname) [dzikra]:dzikra #nama atau hostname server (bebas) Name [EasyRSA]:dzikra Email Address [me@myhost.mydomain]:dzikrafathin@gmail.com #alamat email root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0/#
root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0# ./build-key dzikra #contoh dengan nama key menggunakan nama saya Generating a 2048 bit RSA private key ........................+++ .......................+++ writing new private key to 'dzikra.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) [US]:ID #negara State or Province Name (full name) [CA]:Jawa Barat #Provinsi Locality Name (eg, city) [SanFrancisco]:Bekasi #Kota Organization Name (eg, company) [Fort-Funston]:Pelajar #Pekerjaan Organizational Unit Name (eg, section) [MyOrganizationalUnit]:TKJ #Bagian Kerja Common Name (eg, your name or your server's hostname) [dzikra]:dzikra #Nama atau hostname server Name [EasyRSA]:dzikra Email Address [me@myhost.mydomain]:dzikrafathin@gmail.com #alamat Email Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'ID' stateOrProvinceName :PRINTABLE:'Jawa Barat' localityName :PRINTABLE:'Bekasi' organizationName :PRINTABLE:'Pelajar' organizationalUnitName:PRINTABLE:'TKJ' commonName :PRINTABLE:'dzikra' name :PRINTABLE:'dzikra' emailAddress :IA5STRING:'dzikrafathin@gmail.com' Certificate is to be certified until Mar 2 13:00:03 2026 GMT (3650 days) Sign the certificate? [y/n]:y #tekan "y" untuk membuat sertifikat 1 out of 1 certificate requests certified, commit? [y/n]y #tekan "y" lagi Write out database with 1 new entries Data Base Updated root@dzikra:/etc/openvpn/easy-rsa-2.2.2/easy-rsa/2.0#
root@dzikra:/etc/openvpn# mv easy-rsa* /srv
Lalu isi file tersebut dengan konfigurasi dibawwah ini :
port 1194 #Nomor Port OpenVPN proto tcp #Protocol yang digunakan (TCP/UDP) dev tun tun-mtu 1500 tun-mtu-extra 32 mssfix 1450 ca /etc/openvpn/keys/ca.crt cert /etc/openvpn/keys/dzikra.crt #Nama file key yang dibuat dengan easy-rsa key /etc/openvpn/keys/dzikra.key dh /etc/openvpn/keys/dh2048.pem plugin /usr/lib/openvpn/openvpn-auth-pam.so /etc/pam.d/login client-cert-not-required username-as-common-name server 192.168.100.0 255.255.255.0 #Merupakan alamat IP interface tun0 pada server VPN ifconfig-pool-persist ipp.txt push "redirect-gateway def1" push "dhcp-options 8.8.8.8" #DNS Server push "dhcp-options 8.8.4.4" #DNS Server push "route-method exe" push "route-delay 2" keepalive 5 30 auth none cipher AES-128-CBC comp-lzo persist-key persist-tun status server-1194.log verb 3 max-clients 50 #Jumlah maks client yang terhubung management localhost 500
root@dzikra:~# passwd dzikra
[ ok ] Stopping virtual private network daemon:.
[ ok ] Starting virtual private network daemon: dzikra.
root@dzikra:~#
Testing Koneksi OpenVPN client
- Install Aplikasi OpenVPN pada komputer Client.
- Installer (32-bit), Windows XP and later : openvpn-install-2.3.4-I603-i686.exe (http://swupdate.openvpn.org/community/releases/openvpn-install-2.3.4-I003- i686.exe)
- Installer (64-bit), Windows XP and later : openvpn-install-2.3.4-I603-x86_64.exe (http://swupdate.openvpn.org/community/releases/openvpn-install-2.3.4-I003- x86_64.exe)
- Untuk linux jalankan perintah sudo apt-get install openvpn
- Lalu download file ca.crt yang ada pada /etc/openvpn/keys di server VPN dengan WinSCP, atau anda bisa remote server dengan komputer client dan copy-paste isi file ca.crt ke komputer client dan simpan dengan file ca.crt dalam direktori /etc/openvpn. sosro@sosro-Satellite-M100 ~ $ scp root@alamat ip serverVPN:/etc/openvpn/keys/ca.crt
- Buat file client.conf pada direktori /etc/openvpn. sosro@sosro-Satellite-M100 ~ $ cd /etc/openvpn
- Simpan file tersebut dan restart service openvpn. dan anda akan dimintai username dan password yang sebelumnya sudah dibuat.
sosro@sosro-Satellite-M100 /etc/openvpn $ nano client.conf
Lalu isi dengan konfigurasi dibawah ini :
client proto tcp #Protokol yang digunakan (TCP/UDP) dev tun remote 12.12.12.2 1194 #Alamat IP server dan portnya route-method exe route-delay 2 keepalive 3 15 resolv-retry infinite nobind persist-key persist-tun auth none comp-lzo verb 3 cipher AES-128-CBC auth-user-pass tun-mtu 1500 tun-mtu-extra 32 mssfix 1450 reneg-sec 3600 redirect-gateway def1 ca ca.crt
sosro@sosro-Satellite-M100 /etc/openvpn $ su Password : sosro-Satellite-M100 openvpn # service openvpn restart * Stopping virtual private network daemon(s)... * No VPN is running. * Starting virtual private network daemon(s)... * Autostarting VPN 'client' Enter Auth Username:dzikra Enter Auth Password: sosro-Satellite-M100 openvpn #
Komentar
Posting Komentar