Centos 7 使用fail2ban防止暴力破解,启动fail2ban服务后重试多次后IP没被禁用

使用yum安装fail2ban


先安装epel

yum -y install epel-release


安装fail2ban

yum -y install fail2ban
 

启动服务

systemctl enable  fail2ban

systemctl start  fail2ban

 

查看版本

fail2ban-client -V
Fail2Ban v0.9.7

Copyright (c) 2004-2008 Cyril Jaquier, 2008- Fail2Ban Contributors
Copyright of modifications held by their respective authors.
Licensed under the GNU General Public License v2 (GPL).

Written by Cyril Jaquier <cyril.jaquier@fail2ban.org>.
Many contributions by Yaroslav O. Halchenko <debian@onerussian.com>.

修改配置文件

vim /etc/fail2ban/jail.conf 

在末尾添加

[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
#sendmail-whois[name=SSH, dest=your@email.com, sender=fail2ban@email.com]
logpath = /var/log/secure
maxretry = 3
bantime = 300
 

重启服务

systemctl restart  fail2ban

在其他服务器

ssh test@192.168.2.62 -p 222

故意输入三次错误密码

再次尝试连接,还是提示输入密码

怎么会没被禁用了,在fail2ban服务器中查看

fail2ban-client status ssh-iptables
显示如下,发现已经添加了规则,

Status for the jail: ssh-iptables
|- Filter
|  |- Currently failed:    0
|  |- Total failed:    6
|  `- File list:    /var/log/secure
`- Actions
   |- Currently banned:    1
   |- Total banned:    2
   `- Banned IP list:    192.168.2.63
 

经过多次重试,发现是配置文件问题,因为我的sshd端口是222而配置文件中

action = iptables[name=SSH, port=ssh, protocol=tcp] 

port使用的是ssh,这个默认是22,再次修改配置文件

action = iptables[name=SSH, port=222, protocol=tcp] 

重启fail2ban服务

systemctl restart  fail2ban

再次到192.168.2.63中重试

ssh test@192.168.2.62 -p 222

故意输入三次错误密码后提示

ssh: connect to host 192.168.2.62 port 222: Connection refused


 这次成功了!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值