centos服务器fail2ban部署指南标准流程

安装

sudo 复制代码
sudo yum install fail2ban -y

Fail2Ban的默认配置文件在/etc/fail2ban/jail.conf,但不建议直接编辑这个文件。/etc/fail2ban/jail.local的优先级默认更高,无需指定路径。

sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo vim /etc/fail2ban/jail.local

[api-worktool]
enabled  = true
port     = http,https
filter   = nginx-errors
logpath  = /www/wwwlogs/api.worktool.ymdyes.cn.log
maxretry = 10

[site2]
enabled  = true
port     = http,https
filter   = nginx-errors
logpath  = /www/wwwlogs/site2.example.com.log
maxretry = 3

创建或编辑过滤器文件 /etc/fail2ban/filter.d/nginx-errors.conf,添4xx、5xx错误码

sudo vim /etc/fail2ban/filter.d/nginx-errors.conf

[Definition]
failregex = ^<HOST> -.* "(GET|POST|PUT|DELETE|HEAD).*HTTP/.*" (4\d{2}|5\d{2}) 

重启fail2ban生效

sudo systemctl enable fail2ban
sudo systemctl restart fail2ban

检查和测试

sudo fail2ban-client status
sudo fail2ban-client status api-worktool
sudo fail2ban-client status site2
sudo fail2ban-client -d

Fail2Ban会使用iptables来禁止IP地址。确保你的防火墙允许Fail2Ban添加规则。(缺省)

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
相关推荐
看星星的派大星16 分钟前
通过 汇编 分析 结构体
linux·汇编
追风赶月、28 分钟前
【Linux】深刻理解操作系统的管理
linux·服务器
Xiao Tong33329 分钟前
linux第一课(操作系统核心)
linux·运维·服务器
萌新程序猿~41 分钟前
Ubuntu设置笔记本电脑合盖时不挂起
linux·ubuntu·电脑
Peterpan000001 小时前
CTF——简单的《WEB》
linux·经验分享·笔记·安全·网络安全
贩卖纯净水.1 小时前
共享内存喜欢沙县小吃
linux·运维·服务器·c++
写代码的学渣1 小时前
运维工程师概述及职责
linux·运维·系统安全
robot_大菜鸟1 小时前
linux -L4.linux 暂停和启动进程
linux·运维·服务器
南林yan2 小时前
Linux:命令行参数
linux
小鹿( ﹡ˆoˆ﹡ )2 小时前
Excel数据清洗工具:提高数据处理效率的利器
linux·运维·excel