我遇到了 Fail2ban 问题。在日志中我有以下内容:
2021-12-05 00:49:23,968 fail2ban.utils [979765]: ERROR 7f9a6df8cdf0 -- stderr: '/bin/sh: 1: iptables: not found'
2021-12-05 00:49:23,968 fail2ban.utils [979765]: ERROR 7f9a6df8cdf0 -- stderr: '/bin/sh: 2: iptables: not found'
2021-12-05 00:49:23,968 fail2ban.utils [979765]: ERROR 7f9a6df8cdf0 -- stderr: '/bin/sh: 3: iptables: not found'
2021-12-05 00:49:23,968 fail2ban.utils [979765]: ERROR 7f9a6df8cdf0 -- returned 127
2021-12-05 00:49:23,969 fail2ban.utils [979765]: INFO HINT on 127: "Command not found". Make sure that all commands in 'iptables -w -N f2b-nginx-badbots\niptables -w -A f2b-nginx-badbots -j RETURN\niptables -w -I INPUT -p tcp -j f2b-nginx-badbots' are in the PATH of fail2ban-server process (grep -a PATH= /proc/`pidof -x fail2ban-server`/environ). You may want to start "fail2ban-server -f" separately, initiate it with "fail2ban-client reload" in another shell session and observe if additional informative error messages appear in the terminals.
2021-12-05 00:49:23,969 fail2ban.actions [979765]: ERROR Failed to execute ban jail 'nginx-badbots' action 'iptables-allports' info 'ActionInfo({'ip': '81.213.141.194', 'family': 'inet4', 'fid': <function Actions.ActionInfo.<lambda> at 0x7f9a6f56eca0>, 'raw-ticket': <function Actions.ActionInfo.<lambda> at 0x7f9a6f56f3a0>})': Error starting action Jail('nginx-badbots')/iptables-allports: 'Script error'
2021-12-05 00:49:23,969 fail2ban.actions [979765]: NOTICE [nginx-badbots] Restore Ban 82.66.13.48
2021-12-05 00:49:23,976 fail2ban.utils [979765]: ERROR 7f9a6df8cdf0 -- exec: iptables -w -N f2b-nginx-badbots
有人可以启发我吗?
提前致谢
答案1
在您发布的日志行中,您可以看到错误“ /bin/sh: 2: iptables: not found”
消息command not found
通常意味着该命令未安装,或者(较少见)该命令不在 PATH 环境变量内。
尝试安装包含所需命令的软件包,在您的情况下,这将是 iptables 命令,它与软件包同名。
像这样的安装命令sudo apt install iptables
应该为您提供 debian 上 fail2ban 功能所需的命令。
答案2
对于已经安装了 iptables 的人,这是我所做的:
我在 Ubuntu 18.04 上,使用 fail2ban v0.9.4
我进入/etc/fail2ban/action.d/iptables-common.conf
并编辑了文件的最后一行:
# Option: iptables
# Notes.: Actual command to be executed, including common to all calls options
# Values: STRING
#iptables = iptables <lockingopt> <--- Commented this
iptables = /sbin/iptables <lockingopt> <--- Changed to this
我给了它 iptables 的二进制路径,现在它可以工作了。