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
1
firewall-cmd --get-ipset-types
Configuring IPset Options
Membuat IPset
1
firewall-cmd --permanent --new-ipset=bad_ip --type=hash:ip
Membuat ipset dari file XML
Buat dan edit file seperti berikut
1
2
3
4
5
6
<?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
1
firewall-cmd --permanent --new-ipset-from-file=bad_ip.xml --name=bad_ip
List IPset
1
firewall-cmd --permanent --get-ipsets
Print informasi IPset
1
firewall-cmd --permanent --info-ipset=bad_ip
Menambahkan entri IPset
1
firewall-cmd --permanent --ipset=bad_ip --add-entry=192.168.0.2
Anda dapat menambahkan banyak entri sekaligus menggunakan file
1
firewall-cmd --permanent --ipset=bad_ip --add-entries-from-file=iplist.txt
List entri IPset
1
firewall-cmd --permanent --ipset=bad_ip --get-entries
Hapus entri IPset
1
firewall-cmd --permanent --ipset=bad_ip --remove-entry=192.168.0.2
Hapus IPset
1
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.
1
firewall-cmd --permanent --zone=drop --add-source=ipset:bad_ip
Reload firewalld
1
firewall-cmd --reload
Use IPset with direct rule
1
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -m set --match-set bad_ip src -j DROP
Reload firewalld
1
firewall-cmd --reload
Example IPset types
hash:ip
1
2
firewall-cmd --permanent --new-ipset=myipset --type=hash:ip
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.1.10
hash:ip,mark
1
2
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
1
2
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
1
2
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
1
2
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
1
2
firewall-cmd --permanent --new-ipset=myipset --type=hash:mac
firewall-cmd --permanent --ipset=myipset --add-entry=00:11:22:33:44:55
hash:net
1
2
firewall-cmd --permanent --new-ipset=myipset --type=hash:net
firewall-cmd --permanent --ipset=myipset --add-entry=192.168.0.0/24
hash:net,iface
1
2
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
1
2
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
1
2
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
1
2
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