我的理解是,使用ipset运行Fail2ban更快。为此目的:
我下载并安装了每个指令(修改为Fedora 37),ritsu/ipset-故障2ban从Git。
我的班格仍然被设置为:banaction_allports = firewallcmd-rich-rules[actiontype=]
当我尝试用:banaction = firewallcmd-ipset添加或替换上面的内容时
我会犯这样的错误:
2023-04-09 15:51:46,130 fail2ban.actions [986]: NOTICE [postfix-auth] Restore Ban 117.69.159.181
2023-04-09 15:51:46,526 fail2ban.utils [986]: ERROR 7f29c6bd0ea0 -- exec: ipset -exist create f2b-postfix-unv hash:ip timeout 0
firewall-cmd --direct --add-rule ipv4 filter INPUT_direct 0 -p tcp -m multiport --dports smtp,imap2,imap3,imaps,pop3,pop3s,465,587, submission -m set --match-set f2b-postfix-unv src -j REJECT --reject-with icmp-port-unreachable
2023-04-09 15:51:46,527 fail2ban.utils [986]: ERROR 7f29c6bd0ea0 -- stderr: "Error: COMMAND_FAILED: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.8 (legacy): invalid port/service `' specified"
2023-04-09 15:51:46,527 fail2ban.utils [986]: ERROR 7f29c6bd0ea0 -- stderr: 'Error occurred at line: 2'
2023-04-09 15:51:46,527 fail2ban.utils [986]: ERROR 7f29c6bd0ea0 -- stderr: "Try `iptables-restore -h' or 'iptables-restore --help' for more information."
2023-04-09 15:51:46,527 fail2ban.utils [986]: ERROR 7f29c6bd0ea0 -- stderr: ''
2023-04-09 15:51:46,527 fail2ban.utils [986]: ERROR 7f29c6bd0ea0 -- returned 13如果我运行firewall-cmd --list-all-zones,我会得到当前被禁止的IP地址的列表。
但是,它们不在/etc/firewalld/zones下的任何区域文件中。
$ iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP all -- anywhere anywhere match-set blacklist-fail2ban src
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
DROP tcp -- anywhere 185.191.32.198 tcp dpt:http如果我错了,我哪里出错了?
谢谢
增编1
根据Ginnungagap关于框架问题的建议,我对他关于后缀逗号的问题的回答是:
错误示例的jail.local是:
[postfix-unv]
enabled = true
filter = postfix-unv
port = smtp,imap2,imap3,imaps,pop3,pop3s,465,587, submission
logpath = /var/log/maillog
maxretry = 1
bantime = 604800我没看到额外的逗号。我也没有在实际的过滤器中看到额外的逗号。我去调查一下。
增编2
按照你的建议改行。当我发出cmd nft列表规则集时,它似乎起作用了。
我重新启动了firewalld,它没有额外的规则(即富集)。
我重新启动了fail2ban,它在一分钟内加载了所有被禁止的规则。
我还需要来自Git的文件(如上面提到的)吗?
谢谢你,我非常感谢你的帮助。
发布于 2023-04-10 08:33:16
直接规则fail2ban试图注入的端口列表中有一个后缀逗号,导致iptableq-restore记录的错误。
无论如何,我强烈建议使用nftable,它将允许fail2ban管理自己的表和本机集支持。出于兼容性的考虑,iptable仍然存在,但其灵活性远不如nftable。
在使用nftable后端时,Firewalld只会刷新自己的表,这样firewall-cmd就不会清除Fail2ban的表(或者其他的表)。
将后端更改为nftable相当简单,只需将banaction = nftables-multiport添加到监狱或将全局banaction和banaction_allports分别更改为nftables-multiport和nftables-allports即可。
https://serverfault.com/questions/1128307
复制相似问题