CentOS7 启用 Firewalld 防火墙的情况下,默认情况下是使用的 firewallcmd-rich-rules 进行IP地址屏蔽,但是 firewallcmd-rich-rules 在需要屏蔽大量IP的时候效率非常低,重载时需要等待很久。
bde1ef25489de495cc18bbe09fb290d3cad21ad15f53bfcbc92b6dd70b75eb77
可以通过检查 /etc/fail2ban/jail.d/00-firewalld.conf 文件,默认配置如下:# This file is part of the fail2ban-firewalld package to configure the use of# the firewalld actions as the default actions. You can remove this package# (along with the empty fail2ban meta-package) if you do not use firewalld[DEFAULT]banaction = firewallcmd-rich-rules[actiontype=<multiport>]banaction_allports = firewallcmd-rich-rules[actiontype=<allports>]
如果需要变更为使用 ipset ,只需要将 /etc/fail2ban/jail.d/00-firewalld.conf 内容变更为如下即可:# This file is part of the fail2ban-firewalld package to configure the use of# the firewalld actions as the default actions. You can remove this package# (along with the empty fail2ban meta-package) if you do not use firewalld[DEFAULT]banaction = firewallcmd-ipset[actiontype=<multiport>]banaction_allports = firewallcmd-ipset[actiontype=<allports>]
更改配置文件后需要使用 fail2ban-client restart 重启 fail2ban 才能生效,单纯的 reload 是无法生效的。
之后可以通过以下命令检查 firewalld 防火墙规则是否已经生效:# 获取所有 direct 规则firewall-cmd –direct –get-all-rules# 获取 ipset 列表ipset list