赞
踩
#如果您已经安装iptables建议先关闭 service iptables stop #查看Firewalld状态 firewall-cmd --state #启动firewalld systemctl start firewalld #设置开机启动 systemctl enable firewalld.service
#放行22端口 firewall-cmd --zone=public --add-port=80/tcp --permanent #重载配置 firewall-cmd --reload #查看已放行端口 firewall-cmd --zone=public --list-ports
#CentOS内置源并未包含fail2ban,需要先安装epel源 yum -y install epel-release #安装fial2ban yum -y install fail2ban
#新建配置 vi /etc/fail2ban/jail.local #默认配置 [DEFAULT] ignoreip = 127.0.0.1/8 bantime = 86400 findtime = 600 maxretry = 5 #这里banaction必须用firewallcmd-ipset,这是fiewalll支持的关键,如果是用Iptables请不要这样填写 banaction = firewallcmd-ipset action = %(action_mwl)s
ignoreip:IP白名单,白名单中的IP不会屏蔽,可填写多个以(,)分隔 bantime:屏蔽时间,单位为秒(s) findtime:时间范围 maxretry:最大次数 banaction:屏蔽IP所使用的方法,上面使用firewalld屏蔽端口
[sshd] enabled = true filter = sshd port = 22 action = %(action_mwl)s logpath = /var/log/secure
[sshd]:名称,可以随便填写 filter:规则名称,必须填写位于filter.d目录里面的规则,sshd是fail2ban内置规则 port:对应的端口 action:采取的行动 logpath:需要监视的日志路径
[DEFAULT] ignoreip = 127.0.0.1/8 bantime = 86400 findtime = 600 maxretry = 5 banaction = firewallcmd-ipset action = %(action_mwl)s [sshd] enabled = true filter = sshd port = 22 action = %(action_mwl)s logpath = /var/log/secure
#需要先新建一个nginx日志匹配规则 vi /etc/fail2ban/filter.d/nginx-cc.conf #填写如下内容 [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
#需要先新建一个nginx日志匹配规则 vi /etc/fail2ban/filter.d/wordpress.conf #填写如下内容 [Definition] failregex = ^ -.* /wp-login.php.* HTTP/1\.." ignoreregex =
[wordpress] enabled = true port = http,https filter = wordpress action = %(action_mwl)s maxretry = 20 findtime = 60 bantime = 3600 logpath = /usr/local/nginx/logs/access.log
#启动 systemctl start fail2ban #停止 systemctl stop fail2ban #开机启动 systemctl enable fail2ban #查看被ban IP,其中sshd为名称,比如上面的[wordpress] fail2ban-client status sshd #删除被ban IP fail2ban-client set sshd delignoreip 192.168.111.111 #查看日志 tail /var/log/fail2ban.log
转载于:https://www.cnblogs.com/59111618qq/p/10130974.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。