Anda di halaman 1dari 9

Module IPTable di linux Translated by Tengku Aditya Maulana linux dilengkapi dengan firewall berbasis host disebut Netfilter.

Menurut situs resmi proyek: Netfilter adalah satu set kait di dalam kernel Linux yang memungkinkan modul kernel untuk mendaftarkan fungsi callback dengan jaringan stack. Sebuah fungsi callback terdaftar kemudian dipanggil kembali untuk setiap paket yang melintasi hook masing dalam jaringan stack. Ini firewall berbasis Linux dikendalikan oleh program yang disebut iptables untuk menangani penyaringan untuk IPv4, dan ip6tables menangani penyaringan untuk IPv6. Saya sangat merekomendasikan bahwa pertama Anda membaca tutorial singkat kami yang menjelaskan bagaimana mengkonfigurasi firewall berbasis host disebut Netfilter (iptables) di bawah CentOS / RHEL / Fedora / Redhat Enterprise Linux. Daftar posting ini solusi iptables paling umum yang dibutuhkan oleh pengguna Linux baru untuk mengamankan sistem operasi Linux nya dari penyusup. Contoh Pengaturan IP Tables Sebagian besar tindakan yang tercantum dalam posting ini ditulis dengan asumsi bahwa mereka akan dieksekusi oleh root menjalankan bash atau shell modern lainnya. Jangan mengetik perintah pada sistem remote karena akan memutus akses Anda. Untuk tujuan demonstrasi Saya telah menggunakan RHEL 6.x, tetapi perintah berikut harus bekerja dengan distro Linux modern. Ini bukanlah sebuah tutorial tentang cara mengatur iptables. Lihat tutorial di sini. Ini adalah contekan cepat untuk iptables perintah umum.

# 1: Menampilkan Status Firewall Anda Ketik perintah berikut sebagai root: # Iptables-L-n-v Contoh output:

Output di atas menunjukkan bahwa firewall tidak aktif. Contoh berikut menunjukkan firewall aktif: # Iptables-L-n-v

Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target 0 0 DROP 394 43586 ACCEPT 93 17292 ACCEPT 1 142 ACCEPT Chain FORWARD (policy DROP 0 packets, 0 bytes) Pkts bytes target 0 0 ACCEPT 0 0 DROP 0 0 TCPMSS clamp to PMTU 0 0 ACCEPT 0 0 wanin 0 0 wanout 0 0 ACCEPT

prot all all all all

opt -----

in * * br0 lo

out * * * *

source 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0

destination 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0

state INVALID state RELATED,ESTABLISHED

prot all all tcp all all all all

opt --------

in br0 * * * vlan2 * br0

out br0 * * * * vlan2 *

source 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0

destination 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0

state INVALID tcp flags:0x06/0x02 TCPMSS state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT 425 packets, 113K bytes) pkts bytes target prot opt Chain wanin (1 references) Pkts bytes target prot opt Chain wanout (1 references) pkts bytes target prot opt

in in in

out out out

source source source

destination destination destination

dimana, -L: aturan Daftar. -v: Menampilkan informasi rinci. Pilihan ini membuat perintah daftar menampilkan nama antarmuka, pilihan aturan, dan masker KL. Paket dan byte counter juga tercantum, dengan akhiran 'K', masing-masing 'M' atau 'G' untuk 1000, 1.000.000 dan 1000000000 pengganda. -n: alamat IP Tampilan dan port dalam format numerik. Jangan menggunakan DNS untuk menyelesaikan nama. Hal ini akan mempercepat daftar.

# 1.1: Untuk memeriksa firewall dengan nomor baris, masukkan perintah:

Contoh output:
Chain INPUT (policy DROP) num target prot opt source 1 DROP all -- 0.0.0.0/0 2 ACCEPT all -- 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 4 ACCEPT all -- 0.0.0.0/0 Chain FORWARD (policy DROP) num target prot opt source 1 ACCEPT all -- 0.0.0.0/0 2 DROP all -- 0.0.0.0/0 3 TCPMSS tcp -- 0.0.0.0/0 4 ACCEPT all -- 0.0.0.0/0 5 wanin all -- 0.0.0.0/0 6 wanout all -- 0.0.0.0/0 7 ACCEPT all -- 0.0.0.0/0 Chain OUTPUT (policy ACCEPT) num target prot opt source Chain wanin (1 references) num target prot opt source Chain wanout (1 references) num target prot opt source

destination 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 destination 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0 destination destination destination

state INVALID state RELATED,ESTABLISHED

state INVALID tcp flags:0x06/0x02 TCPMSS clamp to PMTU state RELATED,ESTABLISHED

Anda dapat menggunakan nomor baris untuk menghapus atau memasukkan aturan baru dalam firewall.

# 1.2: Untuk menampilkan INPUT atau aturan chain OUTPUT, masukkan perintah:

# Iptables-L INPUT-n-v # Iptables-L OUTPUT-n-v - line-numbers # 2: Stop / Start / Restart Firewall Jika Anda menggunakan CentOS / RHEL / Fedora Linux, masukkan perintah: # service iptables stop # service iptables start # service iptables restart Anda dapat menggunakan perintah iptables itu sendiri untuk menghentikan firewall dan menghapus semua aturan: # iptables -F # iptables -X # iptables -t nat -F # iptables -t nat -X # iptables -t mangle -F # iptables -t mangle -X # iptables -P INPUT ACCEPT # iptables -P OUTPUT ACCEPT # iptables -P FORWARD ACCEPT dimana, -F: Menghapus (pembilasan) semua aturan. -X: Hapus chain. -t : table_name: Pilih tabel (disebut nas atau mangle) dan menghapus / aturan flush. -P : menset menjadi default policy (seperti DROP, REJECT, or ACCEPT). # 3: Menghapus pengaturan Firewall Untuk menampilkan nomor baris bersama dengan informasi lainnya untuk aturan yang ada, masukkan perintah: # Iptables-L INPUT-n - line-numbers # Iptables-L-n OUTPUT - line-numbers # Iptables-L-n OUTPUT - line-numbers | less # Iptables-L-n OUTPUT - line-numbers | grep 202.54.1.1 Anda akan mendapatkan daftar IP. Lihat jumlah di sebelah kiri, kemudian menggunakan nomor untuk menghapusnya. Misalnya menghapus nomor baris 4, masukkan perintah: # Iptables-D INPUT 4 atau mencari sumber IP 202.54.1.1 dan hapus dari aturan: # Iptables-D INPUT-s 202.54.1.1-j DROP dimana, -D: Hapus satu atau lebih aturan dari chain yang dipilih

# 4: Masukkan Aturan Firewall Untuk menyisipkan satu atau lebih aturan dalam rantai yang dipilih sebagai nomor aturan diberikan menggunakan sintaks berikut. Pertama mengetahui nomor baris, masukkan perintah: # Iptables-L INPUT-n - line-numbers Contoh output:
Chain INPUT (policy DROP) num target prot opt source 1 DROP all -- 202.54.1.1 2 ACCEPT all -- 0.0.0.0/0 destination 0.0.0.0/0 0.0.0.0/0

state NEW,ESTABLISHED

Untuk menyisipkan aturan antara 1 dan 2, masukkan perintah: # Iptables-I INPUT 2-s 202.54.1.2-j DROP Untuk melihat aturan diperbarui, masukkan perintah: # Iptables-L INPUT-n - line-numbers Contoh output:
Chain INPUT (policy DROP) num target prot opt source 1 DROP all -- 202.54.1.1 2 DROP all -- 202.54.1.2 3 ACCEPT all -- 0.0.0.0/0 destination 0.0.0.0/0 0.0.0.0/0 0.0.0.0/0

state NEW,ESTABLISHED

Untuk menyimpan aturan firewall di bawah CentOS / RHEL / Fedora Linux, masukkan perintah:
# service iptables save

Dalam contoh ini, drop IP dan menyimpan aturan firewall:


# iptables -A INPUT -s 202.5.4.1 -j DROP # service iptables save

Untuk semua distro lain menggunakan perintah iptables-save:


# iptables-save > /root/my.active.firewall.rules # cat /root/my.active.firewall.rules

# 6: Restore Firewall Untuk mengembalikan aturan firewall membentuk sebuah file bernama / root / my.active.firewall.rules, masukkan perintah:
# iptables-restore < /root/my.active.firewall.rules

Untuk mengembalikan aturan firewall di bawah CentOS / RHEL / Fedora Linux, masukkan perintah:
# service iptables restart

# 7: Mengatur Default Firewall Policies Untuk menghentikan semua trafik pada firewall
# iptables -P INPUT DROP # iptables -P OUTPUT DROP # iptables -P FORWARD DROP # 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

# 7.1: setting Hanya Blok/membatasi masuk trafik Untuk drop semua paket masuk / diteruskan, tetapi memungkinkan trafik data keluar, masukkan perintah:
# iptables -P INPUT DROP # iptables -P FORWARD DROP # iptables -P OUTPUT ACCEPT # iptables -A INPUT -m state --state NEW,ESTABLISHED -j ACCEPT # 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

# 8: Gugurkan Private Network Alamat Pada Public Interface IP spoofing hanyalah untuk menghentikan berikut alamat IPv4 untuk jaringan swasta berkisar pada Public Interface. Paket dengan alamat sumber non-routable harus ditolak dengan menggunakan sintaks berikut:
# iptables -A INPUT -i eth1 -s 192.168.0.0/24 -j DROP # iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP

# 8.1: Alamat IPv4 Ranges Untuk Private Networks (pastikan Anda memblokir mereka pada Public Interface) 10.0.0.0/8 -j (A) 172.16.0.0/12 (B) 192.168.0.0/16 (C) 224.0.0.0/4 (MULTICAST D) 240.0.0.0/5 (E) 127.0.0.0/8 (LOOPBACK) # 9: Memblokir Alamat IP (IP BLOCK) Untuk memblokir alamat ip penyerang disebut 1.2.3.4, masukkan perintah:
# iptables -A INPUT -s 1.2.3.4 -j DROP # iptables -A INPUT -s 192.168.0.0/24 -j DROP

# 10: Blok Permintaan incoming port (BLOK PORT) Untuk memblokir semua incoming port pada port 80, masukkan perintah:
# iptables -A INPUT -p tcp --dport 80 -j DROP # iptables -A INPUT -i eth1 -p tcp --dport 80 -j DROP

Untuk memblokir port 80 hanya untuk alamat ip 1.2.3.4, masukkan perintah:


# iptables -A INPUT -p tcp -s 1.2.3.4 --dport 80 -j DROP # iptables -A INPUT -i eth1 -p tcp -s 192.168.1.0/24 --dport 80 -j DROP

# 11: Blok IP Address Outgoing Untuk memblokir trafik data keluar ke host atau domain tertentu seperti facebook.com, masukkan perintah: # host -t a facebook.com Contoh output:
Facebook.com has address 69.63.176.13

Catat alamat IP dan ketik berikut ini untuk memblokir semua lalu lintas keluar ke 69.63.176.13 :
# iptables -A OUTPUT -d 69.63.176.13 -j DROP

Anda dapat menggunakan subnet sebagai berikut:


# iptables -A OUTPUT -d 192.168.1.0/24 -j DROP # iptables -A OUTPUT -o eth1 -d 192.168.1.0/24 -j DROP

Cari CIDR untuk 69.171.228.13, masukkan perintah :


# whois 69.171.228.40 | grep CIDR

Contoh output:
CIDR: 69.171.224.0/19

Untuk mencegah akses keluar ke www.facebook.com, masukkan perintah:


# iptables -A OUTPUT -p tcp -d 69.171.224.0/19 -j DROP

Anda juga dapat menggunakan nama domain, masukkan perintah:


# iptables -A OUTPUT -p tcp -d www.facebook.com -j DROP # iptables -A OUTPUT -p tcp -d facebook.com -j DROP

Dari iptables halaman depan(Main Page) : ... menentukan nama apapun harus diselesaikan dengan query terpencil seperti DNS (misalnya, facebook.com adalah ide yang sangat buruk), alamat IP (dengan / mask), atau alamat IP polos ...

# 12: Log dan Gugurkan Paket Ketik berikut untuk login dan memblokir IP spoofing pada Public interface disebut eth1
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix "IP_SPOOF A: " # iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP

Secara default semua log ke / var / log file / messages.


tail -f /var/log/messages # grep --color 'IP SPOOF' /var/log/messages

# 13: Log dan Drop Paket dengan pembatasan jumlah Entri Log -M modul batas dapat membatasi jumlah entri log dibuat per waktu. Ini digunakan untuk mencegah banjir file log Anda. Untuk log dan drop spoofing per 5 menit, dalam semburan dari paling lama 7 entri.
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -m limit --limit 5/m --limit-burst 7 -j LOG -log-prefix "IP_SPOOF A: " # iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP

# 14: Memutuskan atau Terima Lalu Lintas Dari Mac Address Gunakan sintaks berikut:
# iptables -A INPUT -m mac --mac-source 00:0F:EA:91:04:08 -j DROP ## *only accept traffic for TCP port # 8080 from mac 00:0F:EA:91:04:07 * ## # iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source 00:0F:EA:91:04:07 -j ACCEPT

# 15: Memblokir atau Izinkan ICMP Ping Permintaan Ketik perintah berikut untuk memblokir permintaan ping ICMP:
# iptables -A INPUT -p icmp --icmp-type echo-request -j DROP # iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -j DROP

Ping tanggapan juga dapat terbatas pada jaringan tertentu atau host:
# iptables -A INPUT -s 192.168.1.0/24 -p icmp --icmp-type echo-request -j ACCEPT

Berikut ini hanya menerima jenis terbatas permintaan ICMP:


### ** assumed that default INPUT policy set to DROP ** ############# iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT ## ** all our server to respond to pings ** ## iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

# 16: membuka jarak/akses dari port-port Gunakan sintaks berikut untuk membuka berbagai port:
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 7000:7010 -j ACCEPT

# 17: membuka jarak/akses Alamat IP Gunakan sintaks berikut untuk membuka berbagai alamat IP:
## only accept connection to tcp port 80 (Apache) if ip is between 192.168.1.100 and 192.168.1.200 ##iptables -A INPUT -p tcp --destination-port 80 -m iprange --src-range 192.168.1.100192.168.1.200 -j ACCEPT ## nat example ## iptables -t nat -A POSTROUTING -j SNAT --to-source 192.168.1.20-192.168.1.25

# 18: Menyetabilkan Koneksi dan Restart Firewall Ketika Anda me-restart iptables layanan yang akan turun Menyetabilkan Koneksi karena membongkar modul dari sistem di bawah RHEL / Fedora / CentOS Linux. Edit, / etc / sysconfig / iptables-config dan mengatur IPTABLES_MODULES_UNLOAD sebagai berikut:
IPTABLES_MODULES_UNLOAD = no

#19: Iptables Memenuhi Layar anda Gunakan tingkat log crit untuk mengirim pesan ke file log dari konsol/terminal:
iptables -A INPUT -s 1.2.3.4 -p tcp --destination-port 80 -j LOG --log-level crit

#20:memBlock ataumembuka Common Ports sintaks untuk membuka dan menutup umum TCP dan UDP port:
Replace ACCEPT with DROP to block port: ## open port ssh tcp port 22 ## iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT ## open cups (printing service) udp/tcp port 631 for LAN users ## iptables -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 631 -j ACCEPT iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp --dport 631 -j ACCEPT ## allow time sync via NTP for lan users (open udp port 123) ## iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 123 -j ACCEPT ## open tcp port 25 (smtp) for all ## iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT # open dns server ports for all ## iptables -A INPUT -m state --state NEW -p udp --dport 53 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT ## open http/https (Apache) server port to all ## iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT ## open tcp port 110 (pop3) for all ## iptables -A INPUT -m state --state NEW -p tcp --dport 110 -j ACCEPT ## open tcp port 143 (imap) for all ## iptables -A INPUT -m state --state NEW -p tcp --dport 143 -j ACCEPT

## open access to iptables -A INPUT iptables -A INPUT iptables -A INPUT iptables -A INPUT

Samba file server -s 192.168.1.0/24 -s 192.168.1.0/24 -s 192.168.1.0/24 -s 192.168.1.0/24

for lan users only ## -m state --state NEW -p -m state --state NEW -p -m state --state NEW -p -m state --state NEW -p

tcp tcp tcp tcp

--dport --dport --dport --dport

137 138 139 445

-j -j -j -j

ACCEPT ACCEPT ACCEPT ACCEPT

## open access to proxy server for lan users only ## iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 3128 -j ACCEPT ## open access to mysql server for lan users only ## iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

Anda mungkin juga menyukai