【问题标题】:fail2ban - how to ban ip permanently after it was baned 3 times temporarilyfail2ban - 如何在暂时禁止 3 次后永久禁止 IP
【发布时间】:2021-02-26 20:55:25
【问题描述】:

已按照本教程在 CentOS 8 上设置了 fail2ban 服务:https://www.cyberciti.biz/faq/how-to-protect-ssh-with-fail2ban-on-centos-8/

我已经按照上面的教程进行了类似的设置,如下所示:

[DEFAULT]
# Ban IP/hosts for 24 hour ( 24h*3600s = 86400s):
bantime = 86400
 
# An ip address/host is banned if it has generated "maxretry" during the last "findtime" seconds.
findtime = 1200
maxretry = 3
 
# "ignoreip" can be a list of IP addresses, CIDR masks or DNS hosts. Fail2ban
# will not ban a host which matches an address in this list. Several addresses
# can be defined using space (and/or comma) separator. For example, add your 
# static IP address that you always use for login such as 103.1.2.3
#ignoreip = 127.0.0.1/8 ::1 103.1.2.3
 
# Call iptables to ban IP address
banaction = iptables-multiport
 
# Enable sshd protection
[sshd]
enabled = true

我希望一个IP在被临时禁止3次后被永久禁止。该怎么做?

【问题讨论】:

    标签: centos customization fail2ban


    【解决方案1】:

    长期禁止是不可取的 - 它只会不必要地使您的网络过滤器子系统(以及fail2ban)超载...长期禁止就足够了。

    如果你使用 v.0.11,你可以使用 bantime 增量功能,你的配置可能看起来像这个答案 - https://github.com/fail2ban/fail2ban/discussions/2952#discussioncomment-414693

    [sshd]
    # initial ban time:
    bantime = 1h
    # incremental banning:
    bantime.increment = true
    # default factor (causes increment - 1h -> 1d 2d 4d 8d 16d 32d ...):
    bantime.factor = 24
    # max banning time = 5 week:
    bantime.maxtime = 5w
    

    但请注意,如果启用此功能,它也会影响maxretry,因此第二次和后续被称为不良 IP 的禁令发生的时间要早​​于 3 次尝试后(每次都会减半)。

    【讨论】:

    • 你能举一些例子/场景来说明永久禁止如何不必要地超载网络过滤子系统或fail2ban吗?我看不出长时间禁止大量IP和永久禁止它们之间的区别。嗯...很明显,永久禁止的 ip 列表只会增加,但我认为这不会有什么不同,是吗?
    • 没有什么是免费的。当然你可以使用 ipset-actions(ipset 更适合通过规则检查来处理大量 IP),但你可以自己测量它(或谷歌 iptables/ipset 性能)。另请注意,fail2ban 还必须在其内部处理如此庞大的列表/哈希表(这也会导致某些服务器负载)。然后考虑动态 IP、僵尸网络的有限性(其中一些主机/设备可能会被固定、被提供商滥用或稍后被所有者更改)等等,你可以自己回答你的问题,或者至少了解为什么持续禁止不'完全没有意义。
    【解决方案2】:

    您可以使用 jail [recidive]bantime = -1 永久封禁。示例 jail.local:

    # Jail for more extended banning of persistent abusers
    # !!! WARNINGS !!!
    # 1. Make sure that your loglevel specified in fail2ban.conf/.local
    #    is not at DEBUG level -- which might then cause fail2ban to fall into
    #    an infinite loop constantly feeding itself with non-informative lines
    # 2. Increase dbpurgeage defined in fail2ban.conf to e.g. 648000 (7.5 days)
    #    to maintain entries for failed logins for sufficient amount of time
    [recidive]
    enabled = true
    logpath = /var/log/fail2ban.log
    banaction = %(banaction_allports)s
    bantime = -1        ; permanent
    findtime = 86400    ; 1 day
    maxretry = 6
    

    一般说明: 使用 SSH 密钥验证并在 sshd_config 中设置“AllowGroups”或“AllowUsers”。大多数 SSH 登录尝试将在几次尝试后停止。我还在我的服务器上注意到几个月或几年后它越来越少。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多