Debian10_Centos8_fail2ban

转载注明来源: 本文链接 来自osnosn的博客,写于 2020-11-7.

  • Debian-10 的 fail2ban 支持 ipv6。防火墙内核是 nft,缺省用 iptables/ip6tables 指令,也可以装 nftables 用 nft 指令。
  • CentOS-8 的 fail2ban 支持 IPv6. 防火墙内核用 nft,缺省用 firewall-cmd, nft, iptables/ip6tables 指令。
  • CentOS-7 的 fail2ban 还不支持 IPv6. 防火墙内核是 iptables,缺省用 firewall-cmd, iptables 指令。

安装配置 fail2ban (debian10)

  • apt install fail2ban
  • debian-10 安装后,默认就已经"激活" 并 "启动"
  • 创建 /etc/fail2ban/filter.d/nginx-MyRule.local (按需。如果你不需要,就不用创建)

    这是自定义的nginx访问的规则。

    目的是阻止网页的扫描,如果有大量访问"文件不存在的页面",就禁了他。
[INCLUDES]

#before = botsearch-common.conf

[Init]

# Block is the actual non-found directories to block
block = \/?(<webmail>|<phpmyadmin>|<wordpress>|cgi-bin|mysqladmin)[^,]* # These are just convenient definitions that assist the blocking of stuff that
# isn't installed
webmail = roundcube|(ext)?mail|horde|(v-?)?webmail phpmyadmin = (typo3/|xampp/|admin/|)(pma|(php)?[Mm]y[Aa]dmin) wordpress = wp-(login|signup|admin)\.php [Definition] failregex = ^<HOST> \- \S+ \[\] \"(GET|POST|HEAD) \/\S+ \S+\" (400|401|404) .+$
^<HOST> \- \S+ \[\] \"(GET|POST|HEAD) \/<block> \S+\" 404 .+$ ignoreregex = datepattern = {^LN-BEG}%%ExY(?P<_sep>[-/.])%%m(?P=_sep)%%d[T ]%%H:%%M:%%S(?:[.,]%%f)?(?:\s*%%z)?
^[^\[]*\[({DATE})
{^LN-BEG} # Author: MyLocalRule
  • 创建 /etc/fail2ban/jail.local
[sshd]
enabled = true
port = 22,2222
#ignoreip=127.0.0.1/8 192.168.0.0/16
ignoreip=127.0.0.1/8
findtime=300
# 一次ssh密码错产生3条匹配
maxretry=10
bantime=1800 # 以下部分,按需。(不需要就整段不要)
[nginx-MyRule]
enabled = true
port = http,https,10443
logpath = %(nginx_access_log)s
ignoreip = 127.0.0.1/8
maxretry = 30
findtime = 1200
bantime = 14400
  • 重启 service fail2ban reload
  • fail2ban 启动后不会马上在iptables中创建规则。所以这时去看防火墙规则,是没有变化的。要等到需要deny时,才动态创建的。
  • 如果满足ban规则,因为 debian-10 默认是用 iptables/ip6tables 指令。
    • 默认用 multiport 动作。一条对应多个端口的规则分别加入iptables/ip6tables的INPUT,跳转到f2b-sshd。
    • ipv4, debian-10 会在 iptables 的 Chain f2b-sshd 中插入对应ipv4的deny规则。
    • ipv6, debian-10 会在 ip6tables 的 Chain f2b-sshd 中插入对应ipv6的deny规则。
    • 以上规则,最终会自动转换为 nft rule 执行。
      • 多端口的一条规则分别加入table ip(6) filter { chain INPUT { ... } }跳转f2b-sshd。
      • ipv4/ipv6的deny插入table ip(6) filter { chain f2b-sshd { ... } }

安装配置 fail2ban (centos-8)

  • dnf install fail2ban
  • 其他配置,和 debian-10 相同。
  • centos-8 安装后,没有"激活" 和 "启动", 所以需要手工激活/启动。

    systemctl enable fail2ban; systemctl start fail2ban
  • fail2ban 启动后不会在nft中创建规则。所以nft中看不到变化。要等到需要deny时,才会在nft中添加rule。
  • 如果满足ban规则,因为 centos-8 默认是用 nft 做防火墙。
    • 用 tcp dport 动作。一个端口插入一条deny规则。
    • ipv4/ipv6, centos-8 都会在 table inet firewalld { chain filter_IN_public_deny { ... } } 插入deny规则。
    • iptables/ip6tables 中 没有规则。

转载注明来源: 本文链接 来自osnosn的博客.

Debian10_Centos8_fail2ban的更多相关文章

  1. UnRAID_6.8.2_配置_设置

    UnRAID_6.8.2_配置_设置 转载注明来源: 本文链接 来自osnosn的博客,写于 2020-10-05. 参考: UnRAID download Getting_Started Offic ...

随机推荐

  1. PyQt(Python+Qt)学习随笔:exit code 1073741845与槽函数所在对象不能定义同名实例方法问题

    最近做了几次测试,在PyQt中如果使用与槽函数同名的实例方法可能会导致不可控的错误. 案例1:如果两个信号映射到同名的槽函数,虽然参数不一样,但真正响应的槽函数是最后定义的槽函数,具体案例请见< ...

  2. Python实现自动整理文件

    前言 工作上的文档和资料好几个月没整理了,因为平常太忙都是随手往桌面丢.整个桌面杂乱无章全是文档和资料.几乎快占满整个屏幕了,所有我必须要整理一下了.但是手动整理太费时间了,于是我想到了python. ...

  3. 我摊牌了,大厂面试Linux就这5个问题

    说真的,这就是<我想进大厂>系列第八篇,但是Linux的问题确实很少,就这样,强行编几个没有营养的问题也没啥意义. 1.CPU负载和CPU利用率的区别是什么? 首先,我们可以通过uptim ...

  4. deepFM(原理和pytorch理解)

    参考(推荐):https://blog.csdn.net/w55100/article/details/90295932 要点: 其中的计算优化值得注意 K代表隐向量维数 n可以代表离散值one-ho ...

  5. basic english

    color/visual see look color dark light beautiful shade black blue brown clear gray green orange red ...

  6. protobuf 协议浅析

    目录 Protobuf 协议浅析 1. Protobuf 介绍 1.1 Protobuf 基本概念 1.2 Protobuf 的优点 1.3 Protobuf, JSON, XML 的区别 2. Pr ...

  7. 要你命3000会员版v20.03_全球抖音模式

    要你命3000是搭配抖音和极其多软件的神器,支持国际版.国内版,可以去除全部限制,无需爬墙,无需拔卡,35个国家/自由切换,真心强大,请务必低调,谢谢合作. 下载地址:https://sansuinb ...

  8. Linux下查看目录文件大小

    1.ls -lht 查看当前目录下文件的大小 2.du -sh 查看当前文件夹的大小

  9. PHPCMS V9.6.0 SQL注入漏洞分析

    0x01 此SQL注入漏洞与metinfo v6.2.0版本以下SQL盲注漏洞个人认为较为相似.且较为有趣,故在此分析并附上exp. 0x02 首先复现漏洞,环境为: PHP:5.4.45 + Apa ...

  10. 第五章 Gateway--服务网关

    欧克 ,我接着上篇第四章 Sentinel–服务容错,继续写下去 开始网关之旅 5.1网关简介 大家都都知道在微服务架构中,一个系统会被拆分为很多个微服务.那么作为客户端要如何去调用 这么多的微服务呢 ...