我正在尝试配置fail2ban以阻止来自本地主机的ssh。 Fail2ban 安装在带有防火墙的 CentOS 7 上(Linux 3.10.0-229.4.2.el7.x86_64 x86_64 )。我已将jail.conf复制到jail.local,我在jail.local中更改了以下参数:
banaction = firewallcmd-new
[sshd]
enabled = true
maxretry = 5
port = ssh
logpath = /var/log/secure
action = firewallcmd-ipset
我没有结果。任何想法 ?
一些日志信息:
2ban.filter [2489]: INFO Added logfile = /var/log/secure
2015-06-23 07:21:33,439 fail2ban.filter [2489]: INFO Set maxRetry = 3
2015-06-23 07:21:33,440 fail2ban.filter [2489]: INFO Set jail log file encoding to UTF-8
2015-06-23 07:21:33,441 fail2ban.actions [2489]: INFO Set banTime = 86400
2015-06-23 07:21:33,442 fail2ban.filter [2489]: INFO Set findtime = 600
2015-06-23 07:21:33,442 fail2ban.filter [2489]: INFO Set maxlines = 10
2015-06-23 07:21:33,501 fail2ban.server [2489]: INFO Jail sshd is not a JournalFilter instance
2015-06-23 07:21:33,599 fail2ban.jail [2489]: INFO Jail 'sshd' started
并且 SELinux 被禁用。
action.d/firewallcmd-ipset.conf 文件
[INCLUDES]
before = iptables-common.conf
[Definition]
actionstart = ipset create fail2ban-<name> hash:ip timeout <bantime>
firewall-cmd --direct --add-rule ipv4 filter <chain> 0 -p <protocol> -m multiport --dports <port> -m set --match-set fail2ban-<name> src -j <blocktype>
actionstop = firewall-cmd --direct --remove-rule ipv4 filter <chain> 0 -p <protocol> -m multiport --dports <port> -m set --match-set fail2ban-<name> src -j <blocktype>
ipset flush fail2ban-<name>
ipset destroy fail2ban-<name>
actionban = ipset add fail2ban-<name> <ip> timeout <bantime> -exist
actionunban = ipset del fail2ban-<name> <ip> -exist
[Init]
# Option: chain
# Notes specifies the iptables chain to which the fail2ban rules should be
# added
# Values: [ STRING ]
#
chain = INPUT_direct
# Option: bantime
# Notes: specifies the bantime in seconds (handled internally rather than by fail2ban)
# Values: [ NUM ] Default: 600
bantime = 600
# DEV NOTES:
#
# Author: Edgar Hoch and Daniel Black
# firewallcmd-new / iptables-ipset-proto6 combined for maximium goodness
答案1
我在这里猜测了一下,因为我没有足够的信息来了解发生了什么。但我会尝试这样的事情:
fail2ban-regex --print-all-missed /var/log/secure /etc/fail2ban/filter.d/sshd.conf
看看它是否找到了某些东西或者可能缺少哪些行。我假设 /var/log/secure 是 sshd 打印登录失败的地方。在我的基于 debian 的系统上它是 /var/log/auth.log 。
我在监狱里也有一个 bantime 和 findtime。
bantime = 86400
findtime = 86400
也许你没有得到任何东西,因为你没有告诉它查看的时间窗口?