IP sets pada firewalld berfungsi sebagai source untuk memblokir atau mengizinkan sekumpulan baik itu IP, Port, Network, Iface, MAC, dan Mark. Metode yang paling disukai adalah menggunakan IP sets yang dibuat untuk firewall direct rule.
Untuk melihat list IP sets yang didukung firewalld
firewall-cmd --get-ipset-types
Configuring IPset Options #
Membuat IPset
firewall-cmd --permanent --new-ipset=bad_ip --type=hash:ip
Membuat ipset dari file XML
Buat dan edit file seperti berikut
<?xml version="1.0" encoding="utf-8"?>
<ipset type="hash:ip">
<entry>192.168.0.2</entry>
<entry>192.168.0.3</entry>
<entry>192.168.0.4</entry>
</ipset>
Selanjutnya buat IPset dengan perintah
firewall-cmd --permanent --new-ipset-from-file=bad_ip.xml --name=bad_ip
List IPset
firewall-cmd --permanent --get-ipsets
Print informasi IPset
firewall-cmd --permanent --info-ipset=bad_ip
Menambahkan entri IPset
firewall-cmd --permanent --ipset=bad_ip --add-entry=192.168.0.2
Anda dapat menambahkan banyak entri sekaligus menggunakan file
firewall-cmd --permanent --ipset=bad_ip --add-entries-from-file=iplist.txt
List entri IPset
firewall-cmd --permanent --ipset=bad_ip --get-entries
Hapus entri IPset
firewall-cmd --permanent --ipset=bad_ip --remove-entry=192.168.0.2
Hapus IPset
firewall-cmd --permanent --delete-ipset=bad_ip
Add IPset to Zone #
Anda dapat menambahkan IPset sebagai sumber ke zona untuk menangani semua lalu lintas yang masuk ke server.
firewall-cmd --permanent --zone=drop --add-source=ipset:bad_ip
Reload firewalld
firewall-cmd --reload
Use IPset with direct rule #
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -m set --match-set bad_ip src -j DROP
Reload firewalld
firewall-cmd --reload
Example IPset types #
hash:ip
firewall-cmd --permanent --new-ipset=myipset --type=hash:ip
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.1.10
hash:ip,mark
firewall-cmd --permanent --new-ipset=myipset --type=hash:ip,mark
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.1.10,RED
hash:ip,port
firewall-cmd --permanent --new-ipset=myipset --type=hash:ip,port
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.1.10,80
hash:ip,port,ip
firewall-cmd --permanent --new-ipset=myipset --type=hash:ip,port,ip
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.1.10,80,192.168.2.20
hash:ip,port,net
firewall-cmd --permanent --new-ipset=myipset --type=hash:ip,port,net
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.1.10,80,192.168.2.0/24
hash:mac
firewall-cmd --permanent --new-ipset=myipset --type=hash:mac
firewall-cmd --permanent --ipset=myipset --add-entry=00:11:22:33:44:55
hash:net
firewall-cmd --permanent --new-ipset=myipset --type=hash:net
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.0.0/24
hash:net,iface
firewall-cmd --permanent --new-ipset=myipset --type=hash:net,iface
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.0.0/24,eth0
hash:net,net
firewall-cmd --permanent --new-ipset=myipset --type=hash:net,net
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.0.0/24,10.0.0.0/8
hash:net,port
firewall-cmd --permanent --new-ipset=myipset --type=hash:net,port
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.0.0/24,80
hash:net,port,net
firewall-cmd --permanent --new-ipset=myipset --type=hash:net,port,net
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.0.0/24,80,10.0.0.0/8