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. robot framework 接口自动化测试和关键字开发

    https://www.cnblogs.com/laoqing/p/10787593.html 1.实战-接口自动化测试实例 1.1 接口测试 接口测试通常是系统之间交互的接口,或者某个系统对外提供的 ...

  2. Day1-7【Scrum 冲刺博客集合】

    Day1-Day7博客链接 Day1[Scrum 冲刺博客] Day2[Scrum 冲刺博客] Day3[Scrum 冲刺博客] Day4[Scrum 冲刺博客] Day5[Scrum 冲刺博客] D ...

  3. Srcum冲刺_Day05

    一.团队展示: 1.项目:light_note备忘录 2.队名:删库跑路队 3.团队成员 队员(不分先后) 项目角色 黄敦鸿 后端工程师.测试 黄华 后端工程师.测试 黄骏鹏 后端工程师.测试 黄源钦 ...

  4. js动态加载js文件(js异步加载之性能优化篇)

    1.[基本优化] 将所有需要的<script>标签都放在</body>之前,确保脚本执行之前完成页面渲染而不会造成页面堵塞问题,这个大家都懂. 2.[合并JS代码,尽可能少的使 ...

  5. 原生js之事件解绑

    #removeEventListener ##html <button id='btn'>click</button> ##js ###第一种方式(错误方式) var btn ...

  6. Codeforces Edu Round 54 A-E

    A. Minimizing the String 很明显,贪心之比较从前往后第一个不一样的字符,所以可以从前往后考虑每一位,如果把它删除,他这一位就变成\(str[i + 1]\),所以只要\(str ...

  7. 8、Spring Cloud Zuul

    1.Zuul简介 Zuul包含了对请求的路由和过滤两个最主要的功能. 路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础. 过滤器功能则负责对请求的处理过程进行干预,是实现请 ...

  8. easyUI验证框赋值

    下面来看看easyui的各种验证框赋值的方式: <input name="userId" id="userId" class="easyui-n ...

  9. selenium IDE使用-1

    selenium 硒 Mercury汞,外国人喜欢取这化学的名字 一.selenium概述 1.selenium是开源免费的,针对web应用程序功能自动化测试的工作. 2.做功能自动化的原因:回归测试 ...

  10. 移动端 rem和flexible

    一.rem布局 rem是相对于根元素的字体大小单位. 假设html的字体大小为16px,那么1rem = 16px; 一旦根元素html定义的font-size变化,整个页面中运用到的rem都会随之变 ...