Sabtu, 10 Januari 2009

Setup Firewall IPFW pada FreeBSD

Ipfirewall (ipfw) adalah IP packet filter pada FreeBSD dan fasilitas untuk traffic accounting . IPFW sudah termasuk dalam system FreeBSD. Tetapi untuk mengaktifkan harus di load dahulu module kernel nya pada rc.conf dengan perintah firewall_enable=”YES” .
koompile kernel FreeBSD untuk IPFW

Pastikan IPFW support belum terkompile pada kernel:
#ipfw list

Jika anda mendapatkan error seperti berikut ini, maka anda harus meng kompile ulang kernel FreeBSD anda.
ipfw: getsockopt(IP_FW_GET): Protocol not available



Opsi lain dengan mengecek file config kernel nya /usr/src/sys/i386/conf dan dari option IPFIREWALL :
# grep IPFIREWALL /usr/src/sys/i386/conf
Recompile ulang Kernel dengan opsi IPFW

Copy file baru dari default kernel:
# cd /usr/src/sys/i386/conf
# cp GENERIC IPFWKERNEL

tambahkan dengan option IPFW support:
# vi IPFWKERNEL
options IPFIREWALL # required for IPFW
options IPFIREWALL_VERBOSE # optional; logging
options IPFIREWALL_VERBOSE_LIMIT=10 # optional; don’t get too many log entries
options IPDIVERT # needed for natd
simpan dan tutup file tsb. recompile kernel, tulis perintah berikut ini :
# cd /usr/src
# make buildkernel KERNCONF=IPFWKERNEL
Install kernel baru tsb:
# make installkernel KERNCONF=IPFWKERNEL
Nah… sekarang reboot systemnya:
# reboot
Step # 1: Enabling IPFW

Buka file /etc/rc.conf
# vi /etc/rc.conf
tambahkan berikut ini:
firewall_enable="YES"
firewall_script=”/usr/local/etc/ipfw.rules”

Simpan dan tutup file..
Step # 2 Buat Script Firewall Rule

Anda buat file ipfw.rule dan letakkan script firewall tsb pada /usr/local/etc/ipfw.rule :
# vi /usr/local/etc/ipfw.rules
tambahkan contah perintah berikut:

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 (80), dns (53) etc
$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

Simpan dan tutup file.
Step # 3: Start firewall

Sekarang anda dapat merestart ulang server anda atau anda dapat me reload rules tsb dengan perintah berikut ini.
# sh /usr/local/etc/ipfw.rules
Task: Lihat daftar rules yang sedang berjalan

Tuliskan perintab berikut ini:
# ipfw list

Selamat mencoba
sumber: http://ndok.wordpress.com

Tidak ada komentar: