Tuesday, February 9, 2010

IP Tables

TARGET

1. ACCEPT=proses dari iptables selesai, lalu dilanjutkan ke tujuan
2. DROP=proses dari iptables sebelsai, lalu diblok
3. REJECT-proses dari iptables selesai, lalu diblok lalu mengirim pesan ka host tersebut bahwa paket diblok.

Built-in-chain
1. INPUT=paket dari host yang ditujukan ke firewall
2. FORWARD=paket yang diroute lewat firewall,contoh cari client ke internet
3. OUTPUT=paket dari firewall ke internet

COMMAND
aturan penulisan:
iptables [-t table] -[AD] chain rule-specification [options]
iptables [-t table] -I chain [rulenum] rule-specification [options]
iptables [-t table] -R chain rulenum rule-specification [options]
iptables [-t table] -D chain rulenum [options]
iptables [-t table] -[LFZ] [chain] [options]
iptables [-t table] -N chain
iptables [-t table] -X [chain]
iptables [-t table] -P chain target [options]
iptables [-t table] -E old-chain-name new-chain-name

keterangannya:
-t = menentukan nama table. secara default filter, tetapi ada 4 pilihan (filter, nat, mangle, raw)
chain= ada 3 pilihan (INPUT, FORWARD, OUTPUT)
rulenum=nomor urut aturan chain
target=ada 3 pilihan (ACCEPT, DROP, REJECT)

option command:
-A (ADD)=menambah rule barisan terakhir chain yang ditentukan
contoh= iptables -A INPUT -j DROP ( semua paket yang masuk ke INPUT akan di DROP)

-D (DELETE)=menghapus rule yang ada di chain tertentu, ada dua jenis penghapusan, yaitu dengan nomor urut rule (rulenum) atau dengan pencocokan rule-specification.
contoh=iptables -D INPUT 1, atau iptables -D INPUT -s 10.14.210.100 -j DROP ( pertama adalah menghapus rule pertama di chain input, yang kedua adalah menghapus rule yang cocok dengan spesifikasi tersebut di chain INPUT)

-I (INSERT)=Menambah rule dan chain di baris yang ditentukan
contoh=iptables -I INPUT 1 -dport 8080 -j DROP (menambahkan rule di urutan pertama pada chain INPUT)

-R (REPLACE)=mereplace rule yang ada di chain berdasarkan rulenum.
contoh=iptables -R INPUT 1 -s 192.168.0.1 -j DROP (menimpa rule nomor satu di chain INPUT dengan rule baru tersebut)

-L (LIST)=menampilkan daftar rule seluruhnya dari iptables atau dari chain tertentu jika jenis chainnya ditentukan.
contoh=iptables -L INPUT (menampilkan semua rule yang ada di chain INPUT)

-F =menghapus seluruh rule atau pada rule tertentu di chain jika ditentukan
confoh=iptables -F (menghapus semua rule yang ada di semua chain)

-Z (Zero)= untuk mengenolkan semua counter yang dichain tertentu, misalkan coba -v, setelah itu gunakan -Z, lalu lihat beda -v setelah di -Z.
contoh=iptables -Z INPUT

-N (NEW)=membuat chain baru
contoh=iptables -N ALLOW (membuat chain bernama ALLOW)

-X =menghapus chain tertentu
contoh=iptables -X ALLOW (menghapus chain bernama ALLOW)

-E (EDIT)=mengubah nama chain
contoh=iptables -E ALLOW COBA (merubah nama chain ALLOW menjadi COBA)


PARAMETER RULES
-s ==> source
(iptables -A INPUT -s 192.168.1.1)
-d ==> destination
(iptables -A INPUT -d 192.168.1.1)
-p ==> protocol
(iptables -A INPUT -s 192.168.1.1 -p tcp)
-i ==> in-interface
(iptables -A INPUT -i eth0)
-o ==> out-interface
(iptables -A FORWARD -o eth0)
–sport ==> source port
(iptables -A INPUT -s 192.168.1.1 -p tcp –sport 22)
–dport ==> destination port
(iptables -A INPUT -p tcp –dport 22)
–sys ==> untuk identifikasi new connection request
(iptables -A INPUT -i ppp0 -p tcp –syn –dport ! 80 -j DROP)
Catatan : Gunakan tanda ! untuk negasi/ pernyataan tidak/ selain.
Gunakan tanda : untuk menyatakan sampai, misal port 10 sampai 20, maka ditulis 10:20.

Contoh-Contoh Script IPTables :
iptables -A INPUT -p icmp –icmp-type 8 -j DROP
(DROP semua paket icmp-request yang masuk ke server kita, dengan kata lain komputer kita ga bisa di ping)
=> –icmp-type 0 for reply 8 for request.
iptables -A OUTPUT -p udp -o eth0 –dport 53 –sport 1024:65535 -j ACCEPT
(ACCEPT paket yang dengan protokol UDP, out-interface eth0, destination port 53, source port 1024-65535)
iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -d $SERVER_IP -m state –state NEW, ESTABLISHED, RELATED -j ACCEPT
($SERVER_IP adalah variable, bisa digantikan dengan IP server. -m state –state adalah untuk mengetest keadaan paket, ada 4 yang bisa digunakan, yaitu NEW, ESTABLISHED, RELATED, dan INVALID. NEW : paket memulai koneksi baru. ESTABLISHED : paket adalah bagian dari koneksi yang terjadi antara dua host, misalnya ICMP reply message, yang merupakan balasan dari ICMP request. RELATED : koneksi yang termasuk RELATED adalah jika ia berhubungan dengan koneksi ESTABLISHED yang telah ada. INVALID : paket tidak teridentifikasi atau tidak memiliki state, ini mungkin terjadi karena system running out memory atau karena ICMP error messages yang tidak merespon ke known connections.

blokir url di iptables
iptables -A OUTPUT -p TCP -d www.google.com -j DROP
iptables -A OUTPUT -p ICMP -d www.google.com -j DROP

blokir ip computer
iptables -t filter -A INPUT -s 192.168.1.122 -j DROP

blokir
iptables -A INPUT -s 102.168.1.0/255.255.255.0 -p ICMP -j DROP

Blokir portscanning ( syn )
iptables -A INPUT -s ! 192.168.1.0/24 -p TCP -dport 80 -syn -j DROP


iprange
iptables -A INPUT -s 192.168.1.112/192.168.1.254 -p TCP -j ACCEPT

iptables -A INPUT -m iprange –src-range 192.168.1.122-192.168.1.254 -p TCP -j DROP

block port
iptables -A INPUT -p tcp –dport 1214:1216 -j DROP ( REJECT )

command2
iptables -F menghapus smua config

iptables -D output 2 -->menghapus config output line 2
iptables -D INPUT -s 192.168.1.122 -->menghapus specific file

konfigurasi == > vi /etc/sysconfig/iptables-config

rules vi /etc/sysconfig/iptables
\
iptables -A INPUT -s 192.168.1.122 -p UDP -j DROP

sumber : http://ur73.wordpress.com/


http://www.catatanlepas.com/komputer/43-security/150-dasar-dasar-iptables.html

No comments: