jump to navigation

Membuat firewall di FreeBSD menggunakan IPFW May 20, 2010

Posted by danoe87 in linux/unix.
Tags: , , , , , , , , , , ,
comments closed
Sudah lama ga update blog sore ini kayae waktu yang tepat sambil menunggu waktu presentasi ke atasan, maka dari itu saya akan menulis sebuah tutorial membuat firewall pada mesin FreeBSD.
Firewall yang digunakan adalah IPFW, jangan tanya kenapa koq pake firewall ini karena emang lagi pengen pasang aja ga ada alasan tertentu hehehe. Firewall ini biasanya sudah terpasang pada saat kita melakukan installasi FreeBSD
Step ini adalah opsional namun jika menambahkan fungsi NAT maka dilakukanlah compile kernel. Sebagai catatan editor yang digunakan adalah ee (easy-editor)
Pastikan IPFW belum dicompile pada kernel
# ipfw list
jika didapatkan error maka kita harus melakukan kompilasi kernel
ipfw: getsockopt(IP_FW_GET): Protocol not available
Berpindah ke lokasi kernel dan copy kernel asli freebsd
# cd /usr/src/sys/1386/conf
# cp GENERIC IPFWKERNEL
tambahkan support IPFW
# ee IPFWKERNEL
tambahkan line berikut ini pada kernel diatas

options IPFIREWALL # dibutuhkan untuk IPFW
options IPFIREWALL_VERBOSE # optional; logging
options IPFIREWALL_VERBOSE_LIMIT=10 # optional; don’t get too many log entries
options IPDIVERT # dibutuhkan untuk NAT

tutup dan simpan perubahan pada file. Selanjutnya adalah build kernel baru
# cd /usr/src
# make buildkernel KERNCONF=IPFWKERNEL
Install kernel baru
# make installkernel KERNCONF=IPFWKERNEL
selanjutnya reboot mesin anda
# reboot
ENABLE IPFW pada saat boot mesin

masuk ke /etc/rc.conf
# ee /etc/rc.conf
masukkan line dibawah ini
firewall_enable=”YES”
firewall_script=”/usr/local/etc/ipfw.rules”
tutup dan simpan file tersebut

Menulis Rule pada script Firewall
masuk ke script ipfw.rules
# ee /usr/local/etc/ipfw.rules
masukkan line dibawah ini
IPF=”ipfw -q add”
ipfw -q -f flush
#loopback
$IPF 10 allow all from any to any via lo0
$IPF 20 deny all from any to 127.0.0.0/8
$IPF 30 deny all from 127.0.0.0/8 to any
$IPF 40 deny tcp from any to any frag
# statefull
$IPF 50 check-state
$IPF 60 allow tcp from any to any established
$IPF 70 allow all from any to any out keep-state
$IPF 80 allow icmp from any to any
# open port ftp (20,21), ssh (22), mail (25) http (8118), dns (53)
$IPF 110 allow tcp from any to any 21 in
$IPF 120 allow tcp from any to any 21 out
$IPF 130 allow tcp from any to any 22 in
$IPF 140 allow tcp from any to any 22 out
$IPF 150 allow tcp from any to any 25 in
$IPF 160 allow tcp from any to any 25 out
$IPF 170 allow udp from any to any 53 in
$IPF 175 allow tcp from any to any 53 in
$IPF 180 allow udp from any to any 53 out
$IPF 185 allow tcp from any to any 53 out
$IPF 200 allow tcp from any to any 80 in
$IPF 210 allow tcp from any to any 80 out
# deny and log everything
$IPF 500 deny log all from any to any
tutup dan simpan perubahan
# sh /usr/local/etc/ipfw.rules
selanjutnya ketikkan command dibawah ini
#ipfw list
perhatikan apa yang muncul… :)
IPFW sudah siap digunakan

Copyright © 2008
This feed is for personal, non-commercial use only.
The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:
)