Professional Documents
Culture Documents
Contoh Iptables Rules
Contoh Iptables Rules
Output di atas mengindikasikan bahwa firewall tidak aktif. Bertikut ini contoh yang
menunjukkan firewall Aktif :
# iptables -L -n -v
Dimana,
-L : List rules.
-v : Menampilkan informasi rinci. Pilihan ini membuat perintah list
menampilkan nama interfaces, pilihan aturan, dan masker KL.
Konter paket dan byte juga tercantum, dengan akhiran K, M atau
G untuk 1000, 1.000.000 dan 1000000000 pengganda masing-
masing.
-n : Menampilkan alamat IP dan port dalam format numerik.
#1.1: Untuk memeriksa firewall dengan nomor baris,
masukkan perintah:
# iptables -n -L -v --line-numbers
# iptables -X
# iptables -t nat -F
# iptables -t nat -X
# iptables -t mangle -F
# iptables -t mangle -X
Dimana,
-F : Menghapus semua rules
-X : Menghapus chain.
-t table_name : Pilih tabel (disebut nas atau mangle) dan
menghapus rules.
-P : Mengatur default policy (seperti DROP, REJECT, atau
ACCEPT).
Anda akan mendapatkan daftar IP. Lihat jumlah di sebelah kiri, kemudian
menggunakan nomor untuk menghapusnya. Untuk menghapus nomor baris
contoh 4, masukkan perintah:
# iptables -D INPUT 4
Dimana,
Contoh output:
Contoh output:
# cat /root/my.active.firewall.rules
# iptables -L -v -n
#### you will not able to connect anywhere as all traffic is dropped ###
# ping cyberciti.biz
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2
# iptables -L -v -n
### *** now ping and wget should work *** ###
# ping cyberciti.biz
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2
Untuk memblok port 80 hanya untuk ip address trtentu misal 1.2.3.4, masukkan
perintah:
# iptables -A INPUT -p tcp -s 1.2.3.4 --dport 80 -j DROP
Contoh output:
Sebagai catatan alamat ip dan tipe berikut ini untuk memblokir semua lalu lintas
keluar untuk 75.126.153.206:
# iptables -A OUTPUT -d 75.126.153.206 -j DROP
Contoh output:
Contoh output:
CIDR: 69.171.224.0/19
"IP_SPOOF A: "
Tanggapan Ping juga dapat dibatasi pada jaringan tertentu atau host:
# iptables -A INPUT -s 192.168.1.0/24 -p icmp --icmp-type echo-request -j ACCEPT
##
ACCEPT
## nat example ##
IPTABLES_MODULES_UNLOAD = no
1.
2. Replace ACCEPT with DROP to block port:
3. ## open port ssh tcp port 22 ##
4. iptables -A INPUT -m state state NEW -m tcp -p tcp dport 22 -j
ACCEPT
5. iptables -A INPUT -s 192.168.1.0/24 -m state state NEW -p tcp
dport 22 -j ACCEPT
6.
7. ## open cups (printing service) udp/tcp port 631 for LAN users
##
8. iptables -A INPUT -s 192.168.1.0/24 -p udp -m udp dport 631 -j
ACCEPT
9. iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp dport 631 -j
ACCEPT
10.
11. ## allow time sync via NTP for lan users (open udp port 123) ##
12. iptables -A INPUT -s 192.168.1.0/24 -m state state NEW -p udp
dport 123 -j ACCEPT
13.
14. ## open tcp port 25 (smtp) for all ##
15. iptables -A INPUT -m state state NEW -p tcp dport 25 -j ACCEPT
16.
17. # open dns server ports for all ##
18. iptables -A INPUT -m state state NEW -p udp dport 53 -j ACCEPT
19. iptables -A INPUT -m state state NEW -p tcp dport 53 -j ACCEPT
20.
21. ## open http/https (Apache) server port to all ##
22. iptables -A INPUT -m state state NEW -p tcp dport 80 -j ACCEPT
23. iptables -A INPUT -m state state NEW -p tcp dport 443 -j
ACCEPT
24.
25. ## open tcp port 110 (pop3) for all ##
26. iptables -A INPUT -m state state NEW -p tcp dport 110 -j
ACCEPT
27.
28. ## open tcp port 143 (imap) for all ##
29. iptables -A INPUT -m state state NEW -p tcp dport 143 -j
ACCEPT
30.
31. ## open access to Samba file server for lan users only ##
32. iptables -A INPUT -s 192.168.1.0/24 -m state state NEW -p tcp
dport 137 -j ACCEPT
33. iptables -A INPUT -s 192.168.1.0/24 -m state state NEW -p tcp
dport 138 -j ACCEPT
34. iptables -A INPUT -s 192.168.1.0/24 -m state state NEW -p tcp
dport 139 -j ACCEPT
35. iptables -A INPUT -s 192.168.1.0/24 -m state state NEW -p tcp
dport 445 -j ACCEPT
36.
37. ## open access to proxy server for lan users only ##
38. iptables -A INPUT -s 192.168.1.0/24 -m state state NEW -p tcp
dport 3128 -j ACCEPT
39.
40. ## open access to mysql server for lan users only ##
41. iptables -I INPUT -p tcp dport 3306 -j ACCEPT
42.
Dimana,
Untuk melihat bantuan dengan perintah dan target khusus, masukkan perintah:
# iptables -j DROP -h
Jika tidak, buka port 80 dengan menggunakan iptables untuk semua user:
# iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT