会挽雕弓如满月,西北望,射天狼。|

园龄:粉丝:关注:

使用fail2ban防止SSH暴力破解

简介

Fail2Ban 是一个针对恶意行为进行自动防御的开源软件。它监视日志文件中的恶意行为,并采取相应的措施。

安装

yum install fail2ban -y

启动

systemctl start fail2ban
systemctl enable fail2ban

配置

vi /etc/fail2ban/jail.local

[sshd]
# true表示启用,false表示禁用。
enabled = true  

# 指定ssh端口,根据实际修改
port = ssh

# 过滤器,过滤规则文件为 /etc/fail2ban/filter.d/sshd.conf
filter = sshd   

# 指定包含SSH日志条目的日志文件路径
logpath = /var/log/secure   

# 指定范围时间内允许登录失败的次数 
maxretry = 5           

# 指定计算的范围时间为为1小时
findtime = 3600            

# 指定ban的时间
bantime = -1

# 指定要忽略的ip
ignoreip = 

# 指定ban的动作,port的值根据ssh端口修改
action = iptables[name=SSH, port=ssh, protocol=tcp]

vi /etc/fail2ban/filter.d/sshd.conf

找到 ignoreregex = ,配置如下:

ignoreregex = .* [0-9a-fA-F]{6} from <HOST>.*

生效配置

systemctl restart fail2ban

检查

fail2ban-client status sshd 能看到sshd的过滤信息就是正常。

本文作者:武平宁

本文链接:https://www.cnblogs.com/dewan/p/17774361.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   武平宁  阅读(126)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起