IPTABLES

Type Firewall

1.Packet Filter Gateway
Bertugas melakukan filterisasi terhadap paket-paket yg datang dari
luar jaringan yang dilindunginya.
Bila pada lyaer tcp/ip firewall ini melakukan filterisasi pada layer internet protokol
(ip) atau pada network level pada model OSI.

2.Aplication Level Gateway
biasa disebut proxy firewall. Mekanismenya tidak hanya berdasarkan sumber tujuan dan atribut
paket tapi bisa juga mencapai isi (content) paket tersebut.
Mekanisme lainnya yang terjadi adalah paket tersebut tidak langsung sampai ke server tujuan,
melainkan sampai sampai firewall ini saja.

3.Circuit Level Gateway
model ini bekerja pada bagian tcp pada layer tcp/ip.
Firewall ini akan mengadaka pengawasan terhadap awal hubungan tcp yg biasa di sebut
tcp handshaking untuk menentukan apakah sesi hubunga tersebut itu diperoleh atau tidak.
bentuknya hampir sama dengan aplication level gateway, hanya bagian filter terdapat pada
layer yang berbeda.

4.Stateful Multilayer Inpection Firewall
Model ini mengabungakan dari ketiga firewall sebelumnya.

5.aplication |
4.tranport control |
protokol | paket data yang di filter
3.internet protokol |
2.data link
1.physikal

IPTABLES (administration tool for IPV4 packet filterng dan NAT

iptables digunakan untuk melakukan setup, menjaga dan inspeksi pada tables dari IP filter paket dengan aturan yang ada di kernel Linux.
Dimana terdiri dari tabel yang berbeda, masing-masing tabel terdapat nomor chain dan juga terdapat user-defined chain.
masing-masing chain terdapat lampiran aturan yang cocok pada setiap paket. Masing-masing rule(aturan) secara spesifik akan melakukan dengan
paket yang cocok.

Table
Pada saat ini ada 3 table independent, dimana masing tabel akan tampilkan kapanpun tergantung konfigurasi kernel dan module yang tersedian.

opsi
-t –table

Opsi ini secara spesifika akan mencocokan dengan tabel dengan perintah yang akan dijalankan. Konfigurasi kernel akan menampilkan secara otomatis
modul yang ada.

tabel yang biasa digunakan:

1.filter
Ini adalah default tabel, berarti tanpa menulis opsi table ini yang digunakan adalh table filter ini.
Pada table ini terdapat:
chain INPUT (for packet destination to local socket)
chain FORWARD (for packet being routed through the box)
chain OUTPUT (for locally-generated packets)

2.nat
table ini akan di kosultasikan ketika paket membuat koneksi baru bertemu. Pada table ini terdapat :
PREROUTING (for altering packets as soon as they come in)
OUTPUT (for altering locally-generated packet before routing)
POSTROUTING (for altering paket packets as they are about to go out)

3.mangle
Table ini digunakan untuk khusus paket yang berubah. Sampai kernel 2.4.17 digunakan dua chain
PREROUTING (for altering incoming paket sebelum di routing)
OUTPUT (for altering locally-generated packets before routing)
Sejak kernel 2.4.18 chain berubah dengan ditambahkan:
INPUT (for packets coming into the box itself)
FORWARD ( for altering packets being route through the box)
4.raw
Tabel ini digunakan oleh konfigurasi utama dari traking koneksi bercombinasi denga NORACK target.
Digunakan chain:
PREROUTING (for packets arriving via any network intrface)
OUTPUT (for packets generated by local processes.
iptables [-t table] [pattern] [-j target]

Sebuah rule iptables dapat menspisifikasikan sumber paket(-s)
tujuan paket(-d)
protokol dan(-p)
(filter adalah default table jika option -t tidak disertakan)

1.Untuk memblok(deny) suatu paket yg datang dari ip 192.168.0.254

iptables -t filter -A INPUT -s 192.168.0.254 -j DROP

2.Tanda ! disertakan di depan ip address sumber atau tujuan
menyatakan negasi dari ip address tersebut

iptables -t filter -A OUTPUT -d ! 192.168.0.254 -j DROP

(rule di atas memblok semua paket ke semua ip address kecuali
ip address 192.168.0.254)

3.Incoming dan Outgoing interface dapat di spesifikasikan :

iptables -t filter -A INPUT -s 192.168.0.251 -i eth1 -j DROP

(rule di atas memblok semua paket dari 192.168.0251 yang datang
dari interface eth1)

4.Untuk memblok paket-paket protokol icmp dari jaringan kelas C 192.168.24.0:

iptables -t filter -A INPUT -s 192.168.24.0/255.255.255.0 -p icmp -j DROP

5.Untuk memblok semua paket yg di tuju ke port 80

iptables -t filter -A INPUT -s ! 192.168.24.0/24 -p tcp –dport 80 -j DROP

6.Menampilkan daftar rule suatu chain

iptables -t filter -L INPUT

(jika chain tdk di sertakan akan menampilkan daftar seluruh rule
dari semua chain)

7.Menghapus rule ke n dari chain INPUT. Gunkan nomor urut rule pada chain
tersebut atau mengunakan sintak yg sebenarnya.

iptables -t filter -D INPUT 3
iptables -t filter -D INPUT -s 192.168.0.254 -j DROP

8.Rule2 dapat di hapus (flushed) dari satu atau lebih chain dengan perintah

iptables -t filter -F

Seluruh chein dan rule dapat di kelola secara permanen dengan mengunakan
” init scipt sys V” dengan script ” iptables” u/ menyimpan ulang seluruh rule
dengan perintah:

/etc/rc.d/init.d/iptables save atau service iptables save

Untuk menjamin rule2 yg dibuat dapat di implementasikan ulang pada saat
boot jalankan perintah

chkconfig iptables
chkconfig ipchains –del

NAT(Network address Transaltion)
-SNAT (Digunakan untuk menyembunyikan source address dari paket dg cara
memetakan ulang source address paket yg keluar ke ip address
komputer lain(rentang address lain).

-DNAT (membelokkan(redirect) paket yg datang ke lokasi lain seperti
ke mesin proxy)

COMMAND
-A => menambahkan aturan pd akhir chain.
-D => menghapus aturan pada chain
-R => hapus dan menganti entry baru
-I => memasukan aturan pada suatu baris di chain
-L => menampilan aturan pada sebuah tabel
-F => mengosongkan aturan pada chain
-N => membuat chain baru
-X => menghapus chain yg disebutkan
-P => membuat kebijakan default pada sebuah chain
-E => merubah nama suatu chain

OPTION
-v => memberikan input yg lebih detail
-x => memberikan output yg lebih tepat
-n => memberikan output berbentuk angka
-line-number=> menampilkan nomor daftar aturan
-modprobe=> memerintahkan iptables u/ memangil modul tertentu

GENERIC MACTHES
-p => mengecek tipe protokol tertentu udp, tcp,icmp dal all (/etc/protocols)
-s => mencocokan paket berdasarkan alamat ip asal
-d => mencocokan paket berdasarkan alamat tujuan
-i => mencocokan paket berdasarkan interface dimana paket datang
( hanya u/ input forward dan prerouting)
-o => memcocokan paket berdasarkan interface dimana paket keluar
(untuk output forward dan postrouting)

TCP
–sport => mencocokan berdasarkan port asal
-dport => idem
-tcp-flags => mencocokan paket berdasarkan tcpflags yg ada pd paket tersebut
-syn => memcheck apakah syn sudah sama dengan tcp flags

–icmp-type => mengirim pesan-pesan kesalahnnm

FORWARD Chain

1.iptables -t filter -F FORWARD
(flush any existing rules on the FORWARD Chain)

2.iptables -t filter -P FORWARD DROP
(default forwading policy is DROP at this point, no forwading works)

3.iptables -t filter -A FORWARD -j REJECT
–in-interface eth0 –out-interface eth1 -s 192.168.1.0/24
(expressly prohibit those on the inside from reaching the outside but be polite about it (reject)

4.iptables -t filter -A FORWARD -j ACCEPT –out-interface eth1 –destination 192.168.2.0/24
(allow anyone to send to perimeter net)

5.iptables -t filter -A FORWARD -j ACCEPT –in-interface eth1 –out-interface eth0 -s 192.168.4.0/24 -d 192.168.5.0/24
(allow the parameter net to send to the inside)

6.iptables -t filter -A FORWARD -j ACCEPT –in-interface eth1 –out-interface ppp0 -s 192.168.3.0/24
(allow the perimeter net to forward to the inside)

7.iptables -t filter -A FORWARD -j LOG –log-tcp-options –in-interface ppp0 –d 192.168.7.0/24
(log any direct packet attempt from outside)

INPUT Chain

1.iptables -t filter -A INPUT -j DROP –in-interface sppp0
(if you don,t want anyone physicaly on the outside to make any conection to your router whatsoever)

2. iptables -t filter -P INPUT DROP
(set policy to drop (by default, nothing is allowed in))

3.iptables -t filter -A INPUT -j ACCEPT –in-interface eth0 –proto tcp –dport 22
(allow ssh conections from any ip on the inside)

4.iptables -t filter -A INPUT -j ACCEPT –in-interface ppp0 -s 10.17.63.191/32 –proto tcp –dport 22
(allow ssh (only) from the outside from this one host)
5.iptables -t filter -A INPUT -j ACCEPT –in-interface eth1 -s 192.168.1.23 –proto udp –sport 53
(if you want to be able to use DNS server)

6.iptables -t filter -A INPUT -j REDIRECT –in-interface eth0
(use reject for conections attempts from inside)

netfilter
7.iptables -t filter -A INPUT -j ACCEPT –in-interface eth1 –proto tcp –sport 25 ! –syns
(if you need to be able to send SMTP mail)

8.iptables -t filter -A INPUT -j ACCEPT –match state –state ESTABLISHED
(allow responses to locally initiated connections)

–state
NEW = the packet is initiating a conection
ESTABLISHED = the packet is part of negotiotioned conection
RELATED = the packet is assotiation with conection, such as ICMP error.
INVALID = the packet is not associated with a packet flow, or is othewise problematic.
the packet should be dropped.
–match limit
1.iptables -t filter -A INPUT -j ACCEPT –in-interface ppp0 –proto icmp echo-request
limit 2/s –limit-burst 3
(2 ping pre second should be enough for most purpose)

OUTPUT Chain

1.iptables -t filter -A OUTPUT -j ACCEPT –proto icmp –icmp-type echo-response
–out-interface eth0 –limit 5/s –limit-burst 5
(if you don,t want to response to many pings)

2.iptables -t filter -A OUPUT -j REJECT –proto tcp –match multiport –dport 21,23
(no cleartext password protokol)

3.iptables -t filter -A OUTPUT -j ACCEPT –match owner –gid-owner 17 –match state
match state –state NEW,ESTABLISHED –proto tcp –dport 22
(allow organating ssh for member of the netmin group)