ipset による制御
ブラックリストの作成
「blacklist」の名称でリスト作成する。タイプはサブネットで登録できるように「hash:net」にする。
[root@rhel-m01 ~]# firewall-cmd --get-ipset-types
hash:ip hash:ip,mark hash:ip,port hash:ip,port,ip hash:ip,port,net hash:mac hash:net hash:net,iface hash:net,net hash:net,port hash:net,port,net
[root@rhel-m01 ~]# firewall-cmd --permanent --new-ipset=blacklist --type=hash:net
success
[root@rhel-m01 ~]# firewall-cmd --permanent --info-ipset=blacklist
blacklist
type: hash:net
options:
entries:
ブラックリストにエントリーの追加
一覧のファイルを作成している場合はファイルからまとめて登録可能。
[root@rhel-m01 ~]# firewall-cmd --permanent --ipset=blacklist --add-entries-from-file=iplist.txt
個別にコマンド追加する場合は以下。
[root@rhel-m01 ~]# firewall-cmd --permanent --ipset=blacklist --add-entry=192.168.21.0/24
success
[root@rhel-m01 ~]# firewall-cmd --permanent --ipset=blacklist --add-entry=192.168.22.0/24
success
[root@rhel-m01 ~]# firewall-cmd --permanent --ipset=blacklist --get-entries
192.168.21.0/24
192.168.22.0/24
[root@rhel-m01 ~]# firewall-cmd --permanent --info-ipset=blacklist
blacklist
type: hash:net
options:
entries: 192.168.21.0/24 192.168.22.0/24
ブラックリストの適用
作成した「blacklist」を適用する。適用先は破棄用の「drop」ゾーンとなる。
[root@rhel-m01 ~]# firewall-cmd --permanent --zone=drop --add-source=ipset:blacklist
success
[root@rhel-m01 ~]# firewall-cmd --reload
success
[root@rhel-m01 ~]# firewall-cmd --list-all --zone=drop
drop (active)
target: DROP
icmp-block-inversion: no
interfaces:
sources: ipset:blacklist
services:
ports:
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
nftables からの確認
nftables からも firewalld で設定したブラックリストを確認する。長いので関連すると思われる部分のみ抜粋。
[root@rhel-m01 ~]# nft list tables
table ip lists
table inet firewalld
[root@rhel-m01 ~]# nft list table inet firewalld
table inet firewalld { # progname firewalld
flags owner,persist
set blacklist {
type ipv4_addr
flags interval
elements = { 192.168.21.0/24, 192.168.22.0/24 }
}
(略)
chain filter_INPUT {
type filter hook input priority filter + 10; policy accept;
ct state { established, related } accept
ct status dnat accept
iifname "lo" accept
ct state invalid drop
jump filter_INPUT_ZONES
reject with icmpx admin-prohibited
}
(略)
chain filter_INPUT_ZONES {
ip saddr @blacklist goto filter_IN_drop
iifname "ens160" goto filter_IN_public
goto filter_IN_public
}
(略)
chain filter_IN_drop {
jump filter_INPUT_POLICIES_pre
jump filter_IN_drop_pre
jump filter_IN_drop_log
jump filter_IN_drop_deny
jump filter_IN_drop_allow
jump filter_IN_drop_post
jump filter_INPUT_POLICIES_post
drop
}
(以下略)
対象の「blacklist」だけ確認する場合は以下。
[root@rhel-m01 ~]# nft list set inet firewalld blacklist
table inet firewalld {
set blacklist {
type ipv4_addr
flags interval
elements = { 192.168.21.0/24, 192.168.22.0/24 }
}
}
リッチルールによる制御
上記ブラックリストの対象ネットワークにおいて、HTTPS アクセスは除外して接続許可する場合は「drop」ゾーンにリッチルールで除外設定を追加する。
[root@rhel-m01 ~]# firewall-cmd --zone=drop --add-rich-rule='rule family=ipv4 source address="192.168.21.0/24" port port=https protocol=tcp accept' --permanent
success
[root@rhel-m01 ~]# firewall-cmd --zone=drop --add-rich-rule='rule family=ipv4 source address="192.168.22.0/24" port port=https protocol=tcp accept' --permanent
success
[root@rhel-m01 ~]# firewall-cmd --reload
success
[root@rhel-m01 ~]# firewall-cmd --list-all --zone=drop
drop (active)
target: DROP
icmp-block-inversion: no
interfaces:
sources: ipset:blacklist
services:
ports:
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="192.168.21.0/24" port port="https" protocol="tcp" accept
rule family="ipv4" source address="192.168.22.0/24" port port="https" protocol="tcp" accept
nftables からの設定確認
同様に firewalld の設定を確認する。
[root@rhel-m01 ~]# nft list chain inet firewalld filter_IN_drop_allow
table inet firewalld {
chain filter_IN_drop_allow {
ip saddr 192.168.21.0/24 tcp dport 443 accept
ip saddr 192.168.22.0/24 tcp dport 443 accept
}
}
【参考URL】
第1章 firewalld の使用および設定
第2章 nftables の使用
リッチルール(rich rule)を利用してfirewalldのセキュリティを強化する方法