使用fail2ban防止网站ssh暴力破解

yum update -y
yum install epel-release -y
yum install fail2ban -y
(yum install nano -y)

启动并设置开机自启
systemctl start fail2ban && systemctl enable fail2ban
查看状态
systemctl status fail2ban

在主配置文件创建本地副本
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

[root@VM606583F24B41474 fail2ban]# ls
action.d fail2ban.d jail.conf jail.local paths-fedora.conf
fail2ban.conf filter.d jail.d paths-common.conf

编辑本地副本
sudo vim /etc/fail2ban/jail.local

[DEFAULT]
ignoreip = 127.0.0.1/8
bantime = 86400
findtime = 600
maxretry = 5
banaction = firewallcmd-ipset
action = %(action_mwl)s

ignoreip:白名单,不拦截,多个使用,分隔
bantime:拦截后禁止访问的时间,单位:秒
findtime:检查的时间访问,单位:秒
maxretry:最大失败次数, 在检查时间内达到次数就拦截
banaction:屏蔽ip的方法,firewallcmd-ipset使用fiewallld屏蔽

重启服务
systemctl restart fail2ban

ssh防御,防暴力破解
sudo rm -rf /etc/fail2ban/jail.d/*

nano /etc/fail2ban/jail.d/sshd.local

# 启用抗攻击防护模式–防护策略敏感度最高
# 正常(默认)、ddos、额外或 aggressive (攻击性 全部组合)。
## normal (default), ddos, extra or aggressive (combines all).
mode = aggressive

# 禁止 IP 的持续时间(以秒为单位)。负数-1为“永久”禁止。
## 864000秒为10天
bantime = 864000
## 如果在“findtime”秒内未找到匹配,则计数器设置为零。默认 600s
findtime = 1200
# ssh登录失败阈值默认为 3
maxretry = 1
# 指定封禁的端口,默认为0:65535,也就是所有端口,但可以在jail中设定
port = ssh
# 使用哪个工具方法阻止IP
## firewall防火墙: firewallcmd-ipset
## iptables防火墙: iptables 或 iptables-multiport
## 拉黑到/etc/hosts.deny: hostsdeny
banaction = iptables-multiport
hostsdeny
# 日志路径
logpath = %(sshd_log)s
# 指定用于修改日志文件的后端
#backend = %(sshd_backend)s
backend = systemd

[sshd]

enabled = true

mode = normal

backend =systemd

查看封锁列表
fail2ban-client status

查看ssh封锁情况
fail2ban-client status sshd

------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容