Loading

fail2ban和firewalld防cc攻击

1. yum安装fail2ban:
 
yum -y install epel-release
yum -y install fail2ban
systemctl start fail2ban
 
2.配置文件:
fail2ban的配置文件路径:/etc/fail2ban
 
  fail2ban安装目录:/usr/share/fail2ban
 
  日志文件:/var/log/fail2ban.log
 
  达到阈值之后的执行的动作的配置文件: action.d/
 
  包含所有的过滤规则:filter.d/
 
在配置时,我们应该避免修改由fail2ban安装创建的文件,我们应该去编写具有.local扩展名的新文件。在.local新文件里配置的内容会覆盖jail.conf内容里相同的值
 
3.进入/etc/fail2ban创建jail.local文件,配置同一IP,在10分钟内,如果连续超过5次错误,则使用firewalld将他IP 扳了
 
[DEFAULT]
ignoreip = 127.0.0.1/8 ##指定某个IP可以无视fail2ban规则(白名单),添加多个IP时用空格间隔
bantime = 86400 ##IP禁止的时间(单位:s)
findtime = 600 ##过滤的时间(s)
maxretry = 5 ##连续超过几次错误
 
 
banaction = firewallcmd-ipset ##使用firewalld防火墙屏蔽端口
action = %(action_mwl)s
 
[sshd] ##防止ssh爆破
enabled = true ##开启
filter = sshd ##开启规则
port = 22 ##开启端口 : 如果更改了远程端口需要填写改动的端口
action = %(action_mwl)s
logpath = /var/log/secure ##日志目录
 
 
4.nginx防止cc攻击,使用fail2ban监控nginx日志,匹配短时间内频繁请求的IP,并用firewalld屏蔽
 
进入/etc/fail2ban/filter.d/创建一个conf文件匹配规则,这里创建的 nginx-cc.conf
在60s内,同一IP达到20次请求,则将其IP ban 1小时
 
[Definition]
failregex = -.*- .*HTTP/1.* .* .*$
ignoreregex =
 
[nginx-cc]
enabled = true
port = http,https
filter = nginx-cc
action = %(action_mwl)s
maxretry = 20
findtime = 60
bantime = 3600
logpath = /usr/local/nginx/logs/access.log
 
 
5.fail2ban常用命令:
 
systemctl start fail2ban ##启动
 
systemctl stop fail2ban ##停止
 
systemctl enable fail2ban ##开机启动
 
fail2ban-client status sshd ##查看被扳IP
 
fail2ban-client set sshd delignoreip IP ##删除被扳IP
 
fail2ban-client set sshd unbanip IP ##强制删除被扳IP
 
tail /var/log/fail2ban.log 查看日志
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

posted @ 2020-12-25 13:49  bathing  阅读(354)  评论(0)    收藏  举报
Live2D