大网数据广告活动
服务器运维问答

Maximum bantime with fail2ban

· 52CE 我爱测

I am using fail2ban/firewalld to restrict bot-like access to a Nginx server. Typically, the configuration of the corresponding jail looks like: [nginx-botsearch] #banaction = iptables-multiport enabled = true filter = nginx-botse…

问题原文

原帖链接 · ewcz · CC BY-SA 3.0

I am using fail2ban/firewalld to restrict bot-like access to a Nginx server. Typically, the configuration of the corresponding jail looks like:

[nginx-botsearch]
#banaction = iptables-multiport
enabled = true
filter = nginx-botsearch
logpath = /var/log/nginx*/*access*.log
maxretry = 3
bantime = 3600

This works as expected (the banaction defaults to firewallcmd-ipset), i.e., the iptables -L command shows an entry in the INPUT_direct chain:

REJECT     tcp  --  anywhere             anywhere             multiport dports http,https match-set fail2ban-nginx-botsearch src reject-with icmp-port-unreachable

with the corresponding ipset of fail2ban-nginx-botsearch.

However, I noticed a strange behavior when the bantime is increased. Everything works as expected for bantime <= 4294967. When I set bantime = 4294968 and reload fail2ban service, the entry in the iptables output is missing (the ipset is not created) and indeed, testing with, e.g., the ab utility shows that the ban is not enforced. Interestingly, using banaction = iptables-multiport works even for "large" bantimes. What might be the reason for this behavior? I am using fail2ban v 0.9.7 on CentOS 7.

已采纳解答

原帖链接 · Peter Zhabin · CC BY-SA 3.0

This isn't strictly a fail2ban related issue, bit rather a bug in netfilter code on your kernel. In short, your version of ipset has an integer overflow for timeout parameter, so you see an unpredictable behavior when it exceeds 32bit integer.

You don't see this with multiport as it does not use this code and instead relies on its own devices to track timeouts.

Here's a link to the patch for this issue in netfilter code.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-09-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。