Debian10_Centos8_fail2ban
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 { ... } }。
- 多端口的一条规则分别加入
- 默认用 multiport 动作。一条对应多个端口的规则分别加入iptables/ip6tables的
安装配置 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 中 没有规则。
Debian10_Centos8_fail2ban的更多相关文章
- UnRAID_6.8.2_配置_设置
UnRAID_6.8.2_配置_设置 转载注明来源: 本文链接 来自osnosn的博客,写于 2020-10-05. 参考: UnRAID download Getting_Started Offic ...
随机推荐
- Pentaho Report Designer 入门教程(一)
PentahoReport Designer 入门教程 采用Pentaho Report Designer5.1版本,也是最新的版本. 一. 安装和介绍 介绍部分内容略,首先安装jdk,并 ...
- BlueCMS代码审计
BlueCMS版本号为:bluecms_v1.6_sp1 本地搭建环境后将源代码丢进seay源代码审计系统,开启本地web服务页面访问,大部分白盒+小部分黑盒审计 搭建好环境后第一步先检查是否有重装漏 ...
- Java基础学习之数据类型、基础语法与数组(3)
目录 1.数据类型 1.1.基本数据类型 1.2.引用数据类型 1.3.自动装箱与拆箱 2.基础语法 2.1.标识符 2.2.修饰符 2.2.1.访问控制修饰符 2.2.2.非访问控制修饰符 2.3. ...
- CSS基础-背景
CSS背景 background 纯色背景 {background-colcor:gray; padding:20px} 为元素设置背景色,并设置了内边距,使得元素中的文本向外少有延伸. 用rgba设 ...
- Raft概述
Raft 1. 概述 Raft是一种一致性(共识)算法,相比Paxos,Raft更容易理解和实现,它将分布式一致性问题分解成多个子问题,Leader选举(Leader election).日志复制(L ...
- 通过CSS绘制五星红旗
任务要求: 1.创建一个div作为红旗旗面,用CSS控制其比例宽高比为3:2,背景为红色. 2.再创建五个小的div,用CSS控制其大小和位置. 3.用CSS同时控制每个小div的大小.边框和位置,同 ...
- MySQL技术内幕InnoDB存储引擎(四)——表相关
表是什么? 就是关于特定实体地数据集合,是关系型数据库模型地核心. 索引组织表 什么是索引组织表? 表中数据都是根据主键的顺序组织存放的,这种存储方式就是索引组织表.就是存储在一个索引结构中的表. 也 ...
- Ubuntu18开机执行shell命令
1.打开shell终端,输入 sudo vi /etc/rc.local 2.在编辑器里面输入自己要启动的脚本,特别强调:脚本(程序)要有可执行权限 #!/bin/bash echo "ru ...
- JDK11 下载安装与配置环境变量
1.jdk11本身也包含jre,不需要安装jre,低版本需要安装jre 2.jdk下载地址:https://www.oracle.com/technetwork/java/javase/downloa ...
- Java IO流 BufferedInputStream、BufferedOutputStream的基本使用
BufferedInputStream.BufferedOutputStream的基本使用 BufferedInputStream是FilterInputStream流的子类,FilterInputS ...