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

Configuring an alternate jail in fail2ban for manual use

· 52CE 我爱测

I have a fail2ban instance that works well. But I also like to occasionally examine the logs manually and try to ID system probes that are working around my standard f2b definitions. What I'm looking for is how I can define a jai…

问题原文

原帖链接 · S.ov · CC BY-SA 3.0

I have a fail2ban instance that works well.

But I also like to occasionally examine the logs manually and try to ID system probes that are working around my standard f2b definitions.

What I'm looking for is how I can define a jail that will last an extended period of time that I can manually use in a command like this:

fail2ban-client set $JAIL banip $IP

Can someone give me the syntax to specify a custom jail in the config file that isn't really triggered from log files (or it could be a standard jail that has some condition that might not make it actually trigger), that I can use in a manual statement? What I want to do is have a much longer ban time for manual bannings that I identify personally while looking through logs.

社区高分解答

原帖链接 · S.ov · CC BY-SA 3.0

Here's how I did this..

I added this to jail.local:

[manban]
enabled  = true
filter   = manban
action   = iptables[name=HTTP, port="80,443,110,995,25,465,143,585,993,587,21,22", protocol=tcp]
logpath  = /var/log/manban.log
maxretry = 1
# 1 month
bantime  = 2592000
findtime = 3600

Then I added the file /etc/fail2ban/filter.d/manban.conf:

[Definition]
failregex = ^\[\w{1,3}.\w{1,3}.\d{1,2}.\d{1,2}:\d{1,2}:\d{1,2} \d{1,4}. \[error] \[client.<HOST>].File does not exist:.{1,40}roundcube.{1,200}
ignoreregex =

I copied the filter protocol of another filter but point it to a file that doesn't exist, then I created a dummy file:

touch /var/log/manban.log

then run the command:

fail2ban-client reload

Now to manually ban an IP address for one month, type:

fail2ban-client set manban banip <IP>

This did the trick.

There are clients now that "learn" your fail2ban bantime, and will automatically adjust their system probes to not get banned. But when you look at the logs, it's obvious these are system probes. You can mess up their systems by creating extraordinary long ban times. You could also write a script that could dump IPs matching a certain criteria to your special ban log and have fail2ban ban them for an extended period of time.

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

资料来源与适用范围

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

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

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