Minggu, 28 November 2010

MEMBUAT VPN SERVER

Sekarang ini banyak sekali yang bisa dipergunakan untuk membuat sebuah vpn server dari mulai yang langsung berupa hardware sampai yang hanya berupa aplikasi, dari yang harganya mahal sampai yang gratisan.
OpenVPN adalah salah satu aplikasi VPN gratis (opensource) yang cukup bisa diandalkan. Beberapa sumber mengatakan OpenVPN bukan lah yang teraman tetapi apabila data yang harus ditransfer antara dua network atau lebih tidak terlalu sensitif sepertinya OpenVPN lebih dari cukup apalagi OpenVPN juga sangat gampang untuk diinstall.

Disini saya hanya akan bercerita tentang langkah installasi OpenVPN di FreeBSD. Walaupun mungkin bisa saja beberapa trik nya dipergunakan di Linux atau *nix like OS lainnya.
Ok daripada lama bercerita mari kita mulai saja.
Pertama OpenVPN pada FreeBSD bisa ditemui pada folder /usr/ports/security/openvpn, library yang diperlukan biasanya lzo lib tetapi berhubung saya menginstallnya lewat ports maka seluruh dependensi secara otomatis akan diinstalkan.
Untuk installasi silahkan ikuti langkah berikut (Semua dilakukan oleh root)
cd /usr/ports/security/openvpn
make config
make build
make install clean
Langkah diatas dilakukan supaya anda punya kesempatan untuk melihat apa yang terjadi pada setiap langkah. Sebenarnya bisa saja anda change directory dan langsung mengetikan make install clean.
Setelah beres proses installasi dan tidak ada error yang berarti, selanjutnya masukan baris berikut ke file /etc/rc.conf dengan menggunakan text editor kesayangan anda.
openvpn_enable="YES"
Sekarang kita akan membuat config file yang akan diletakan di folder /usr/local/etc/openvpn kalau folder tersebut belum ada silahkan buat terlebih dahulu dengan perintah
mkdir /usr/local/etc/openvpn 
Kemudian silahkan pindah ke folder tersebut dan mulai buat file openvpn.conf dengan text editor kesayangan anda.
cd /usr/local/etc/openvpn
pico openvpn.conf
sekarang silahkan masukan contoh config berikut ini.
# Specify device
dev tun 

# # Server dan client IP Pool
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt 

# Certificates untuk VPN Authentication
ca /usr/local/etc/openvpn/keys/ca.crt
cert /usr/local/etc/openvpn/keys/server.crt
key /usr/local/etc/openvpn/keys/server.key
dh /usr/local/etc/openvpn/keys/dh1024.pem 

# Routes untuk client
push "route 192.168.0.0 255.255.255.0"
# compression VPN link
comp-lzo 

keepalive 10 60
ping-timer-rem
persist-tun
persist-key 

# Run OpenVPN sebagai daemon dan drop privileges ke user/group nobody user nobody
group nobody
daemon
Simpan file diatas dan kita lanjutkan dengan cerificates. Copy script untuk membuat certificates dari folder /usr/local/share/doc/openvpn dengan cara seperti berikut ini (contoh dicopy kan ke folder /home/giest silahkan diganti dengan user anda).
cp -r /usr/local/share/doc/openvpn/easy-rsa /home/giest/
cd /home/giest/easy-rsa
Setelah berhasil mengcopy script easy-rsa selanjutnya silahkan adan edit file vars dengan editor kesayangan anda dan sesuaikan dengan keperluan (tanpa dieditpun tidak masalah hanya nanti anda akan diberikan beberapa pertanyaan yang berulang-ulang). Berikut ini contoh bagian yang harus anda edit.
export KEY_COUNTRY=ID
export KEY_PROVINCE="WEST JAVA"
export KEY_CITY=BANDUNG
export KEY_ORG="GIEST-VPN"
export KEY_EMAIL="admin@giest.org" 
Kemudian kita pindah dari shell default FreeBSD (biasanya tcsh) ke sh atau bash terlebih dahulu. Apabila anda tidak berpindah shell saya jamin anda tidak akan berhasil membuat certificates untuk openvpn.
Untuk berpindah ke sh atau bash silahkan ketik command berikut.
sh
Setelah anda berpindah shell ikuti langkah-langkah berikut ini.
. vars
NOTE: when you run ./clean-all, I will be doing a rm -rf on /usr/home/Giest/easy-rsa/keys
./clean-all
./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) [ID]:
State or Province Name (full name) [WEST JAVA]:
Locality Name (eg, city) [BANDUNG]:
Organization Name (eg, company) [GIEST-VPN]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address [admin@giest.org]:  
Ok seperti yang anda lihat anda diharuskan menjawab beberapa pertanyaan, tetapi karena sebelumnya saya sudah edit file vars maka saya bisa langsung menekan enter untuk mempergunakan jawaban default.
Selanjutnya adalah build certificate dan key ikuti langkah-langkah berikut ini
./build-key-server server
Generating a 1024 bit RSA private key
..........++++++
..................................................++++++
writing new private key to 'server.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) [ID]:
State or Province Name (full name) [WEST JAVA]:
Locality Name (eg, city) [BANDUNG]:
Organization Name (eg, company) [GIEST-VPN]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:SERVER
Email Address [admin@giest.org]: 

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:PASUNDAN
Using configuration from /usr/home/Giest/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName               :P RINTABLE:'ID'
stateOrProvinceName   :P RINTABLE:'WEST JAVA'
localityName                :P RINTABLE:'BANDUNG'
organizationName      :P RINTABLE:'GIEST-VPN'
commonName            :P RINTABLE:'SERVER'
emailAddress             :IA5STRING:'admin@giest.org'
Certificate is to be certified until Jun 26 10:04:29 2017 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  
Tuh kan kalo kita gak edit file vars kita harus jawab pertanyaan tersebut sekali lagi :D . sekrang kita akan build certificate dan key untuk digunakan oleh client. Dicontoh ini saya akan membuat certificate untuk 2 client saja. kalau anda memiliki lebih dari dua client silahkan disesuaikan.
./build-key client1
Generating a 1024 bit RSA private key
.........++++++
....................................++++++
writing new private key to 'client1.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) [ID]:
State or Province Name (full name) [WEST JAVA]:
Locality Name (eg, city) [BANDUNG]:
Organization Name (eg, company) [GIEST-VPN]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:CLIENT1
Email Address [admin@giest.org]: 

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:PASUNDAN
Using configuration from /usr/home/Giest/easy-rsa/openssl.cnf
DEBUG[load_index]: unique_subject = "yes"
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :P RINTABLE:'ID'
stateOrProvinceName   :P RINTABLE:'WEST JAVA'
localityName          :P RINTABLE:'BANDUNG'
organizationName      :P RINTABLE:'GIEST-VPN'
commonName            :P RINTABLE:'CLIENT1'
emailAddress          :IA5STRING:'admin@giest.org'
Certificate is to be certified until Jun 26 10:10:43 2017 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  
Untuk client2 silahkan ketikan
./build-key client2 
yang harus anda ganti hanya bagian
[source]Common Name (eg, your name or your server’s hostname) []:CLIENT2[/source]
Apabila anda tidak melakukan perubahan disini maka certificates dan key untuk client ke dua tidak akan terbentuk.
Selanjutnya kita build dh parameter dengan perintah seperti berikut
1. # ./build-dh
  2. Generating DH parameters, 1024 bit long safe prime, generator 2
  3. This is going to take a long time
  4. ......................................................................................+.................+.................+..........................................................................................................................................+..+.....................................................................................+...........................................................+..............................+...............................................+..........................................+...........+..............+...........................................++*++*++*  
ok sekarang proses pembuatan key sudah selesai sekarang langsung saja anda keluar kembali ke shell default anda dengan perintah exit
Sekarang copy kan folder keys ke /usr/local/etc/openvpn dengan perintah
cp -r keys /usr/local/etc/openvpn/ 
Sebelum kita mulai menjalankan openvpn server kita siapkan dulu file untuk log. Silahkan edit file /etc/syslog.conf dan tambahkan baris berikut ini pada bagian bawah file syslog.conf.
!openvpn
.* /var/log/openvpn.log
kemudian buat file openvpn.log dan restart syslog ny
touch /var/log/openvpn.log
killall -HUP syslogd 
Sekarang kita load dulu module tun/tap supaya nanti device tun bisa muncul.
kldload if_tun
kldload if_tap
kalau anda menemukan error kldload: can’t load if_tun: File exists berarti tun dan atau tap sudah ter load jadi jangan khawatir.
Supaya tun dan tap ter load setiap kali boot silahkan edit file /boot/default/loader.conf kemudian cari baris berikut dan rubah menjadi YES
if_tap_load="YES"               # Ethernet tunnel software network interface
if_tun_load="YES"               # Tunnel driver (user process ppp)  
Ok lengkap lah sudah sekarang kita siap untuk menjalankan OpenVPN server untuk pertama kali. Untuk menjalankan OpenVPN silahkan ketikan perintah berikut ini.
/usr/local/etc/rc.d/openvpn start  
Selanjutnya kita cek apakah semuanya sudah siap atau belum pertama kita cek tun device dengan perintah ifconfig
tun0: flags=8051 mtu 1500
inet 10.8.0.1 --> 10.8.0.2 netmask 0xffffffff
Opened by PID 10147
Kalau anda sudah melihat tampilan seperti diatas berarti OpenVPN server anda sudah sukses jalan.
Sekarang tinggal kita tambahkan rules berikut untuk pf.conf anda (maaf yang pake ipfw cari sendiri ya :D )
# VPN Interface
vpn_if="tun0" 

# VPN Network
vpn_network="10.8.0.0/24" 

# NAT VPN connections
nat on $ext_if from $vpn_network to any -> ($ext_if) 

# VPN connections inbound
pass in on $ext_if proto udp from any to port 1194 keep state
pass quick on $vpn_if 
 
 

2 komentar:

  1. We are a group of volunteers and opening a new scheme in our community.
    Your web site offered us with valuable information to work on.

    You have done an impressive task and our whole group might be grateful to
    you.

    Also visit my page ... live girl chat

    BalasHapus
  2. I am extremely impressed with your writing skills as well as with
    the layout on your blog. Is this a paid theme or did you customize it yourself?

    Either way keep up the excellent quality writing, it's rare to see a great blog like this one today.

    Also visit my page - porn sites

    BalasHapus

Makasih yang udah mampir,,Komen dong masih kosong nih...

SEO Tools by MessageForce