Fail2ban ufw 操作在监控时不运行,但可用于手动禁止

Fail2ban ufw 操作在监控时不运行,但可用于手动禁止

我在 Ubuntu 16.04 上使用 fail2ban 0.9.3。它jail.local看起来像这样:

[DEFAULT]

banaction = ufw

[apache-post]
enabled = true
filter = apache-post
port = http,https
logpath  = /var/log/apache2/other_vhosts_access.log
maxretry = 20
bantime = 3600

我在 ubuntu 16.04 上运行 fail2ban 0.9.3。

我有一个自定义ufw操作定义如下:

[Definition]
actionstart =
actionstop =
actioncheck =
actionban = ufw insert 1 deny from <ip>
actionunban = ufw delete deny from <ip>

(这与 fail2ban 附带的功能不同,它只是阻止所有端口上的 IP)。

该操作有效 - 如果我执行此操作fail2ban-client set apache-post banip 10.0.0.1然后检查ufw status,则 IP 被禁止:

To                         Action      From
--                         ------      ----
Anywhere                   DENY        10.0.0.1

但是当服务器重新启动并运行时,就会出现问题。fail2ban 正确地监控日志并启动禁令,但 ufw 中并没有禁止 IP。以下是日志示例:

2018-10-09 14:00:57,679 fail2ban.actions        [31576]: NOTICE  [apache-post] Ban 10.0.5.2
2018-10-09 14:01:02,897 fail2ban.actions        [31576]: NOTICE  [apache-post] 10.0.5.2 already banned
2018-10-09 14:01:07,903 fail2ban.actions        [31576]: NOTICE  [apache-post] 10.0.5.2 already banned
2018-10-09 14:01:12,908 fail2ban.actions        [31576]: NOTICE  [apache-post] 10.0.5.2 already banned
2018-10-09 14:01:17,914 fail2ban.actions        [31576]: NOTICE  [apache-post] 10.0.5.2 already banned

如果我检查ufw status,那么 IP 还没有被禁止 - 所以显然操作还没有真正执行,但 fail2ban 认为它已经执行了。

如果我此时重新启动 fail2ban 服务器,它将检查最近的日志并成功地禁止 IP - 即,当它在重新启动时执行操作时,ufw操作会正确执行。同样,如果我手动运行banip命令,则 IP 会被正确禁止。但禁止监控日志不起作用。

我很困惑为什么它在手动操作时可以工作,但在正常运行时却不行。我该如何调试它?

UFW 正在运行:

> sudo ufw status
Status: active

检查监狱的状态表明它处于活动状态,并且它认为它已经禁止了 IP:

Status for the jail: apache-post
|- Filter
|  |- Currently failed: 0
|  |- Total failed:     643
|  `- File list:        /var/log/apache2/other_vhosts_access.log
`- Actions
   |- Currently banned: 9
   |- Total banned:     11
   `- Banned IP list:   10.0.5.2 (and more)

答案1

您是否已确认 ufw 确实正在运行?例如,在我的 Ubuntu 安装中,需要设置“enabled=YES”才能/etc/ufw/ufw.conf让 ufw 在启动时启动。在 Ubuntu 16.04 上,默认情况下它是关闭的。

我猜你是说你替换了默认版本/etc/fail2ban/action.d/ufw.conf?为什么?你的配方适用于原始版本吗?

fail2ban status <JAIL>这显示了什么?

相关内容