Fail2ban防暴力破解

1、安装

yum install epel-release -y
yum install fail2ban fail2ban-systemd -y
或
sudo apt update
sudo apt install fail2ban -y

2、配置

#新建配置 
sudo vim /etc/fail2ban/jail.d/sshd.local

  写入以下命令:

[sshd]
enabled = true
filter = sshd
findtime = 120
bantime = 120
maxretry = 3
banaction = iptables-allports

[sshd]
enabled = true
filter = sshd
action = iptables[name=sshd-ban, port=ssh, protocol=tcp]
findtime =60
bantime = 60
maxretry = 3

[sshd]
enabled = true
filter = sshd
findtime = 1d
bantime = 4w
maxretry = 3

 保存退出,重启服务:

 

#开机设置并重启
sudo systemctl enable fail2ban.service && sudo systemctl restart fail2ban.service

 说明:

enabled=true 是否启用
ignoreip = 127.0.0.1 忽略的IP
bantime=86400 封锁时间,单位:秒
findtime=600 统计时间范围,在规定时间内满足条件开始执行封锁,单位:秒
maxretry=5 错误次数
port=26613 端口
logpath=/var/log/secure 检测日志路径 

  

3、常用操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//启动
systemctl start fail2ban
//重启
systemctl restart fail2ban
//开机重启
systemctl enable fail2ban
//查看状态
systemctl status fail2ban.service
//查看配置状态
fail2ban-client status
//默认配置
vim /etc/fail2ban/jail.conf
 
//查看攻击者
fail2ban-client status sshd
 
//确保防火墙已开起
systemctl enable firewalld
systemctl start firewalld
 
 
//更新 SELinux 策略
yum update -y selinux-policy*

 

1
2
3
4
5
6
//日志设定文档 
/etc/fail2ban/fail2ban.conf
// 阻挡设定文档
/etc/fail2ban/jail.conf
//具体阻挡内容设定目录 
/etc/fail2ban/filter.d

  

1
2
3
4
5
6
7
8
//查看被禁用的ip
iptables -L -n
 
//查看登陆失败日志
cat /var/log/secure | grep 'Failed password'
 
//解锁ip
fail2ban-client set sshd unbanip IPADDRESS

  

参考文献:https://centoshelp.org/security/fail2ban/

  https://www.howtoforge.com/tutorial/how-to-install-fail2ban-on-centos/

文章出处:http://www.cnblogs.com/anech/p/6867589.html

 

posted @   anech  阅读(4817)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示