fail2ban配置

一、安装
如果是centos7 关闭firewalld 
# systemctl stop firewalld.service
# systemctl disable firewalld.service
# yum install iptables-services iptables -y    
# yum install fail2ban -y

二、配置

/etc/fail2ban/fail2ban.conf 日志设定文档 
/etc/fail2ban/jail.conf 阻挡设定文档 
/etc/fail2ban/filter.d 具体阻挡内容设定目录

# vi /etc/fail2ban/jail.conf

[DEFAULT]                  #全局设置
ignoreip = 127.0.0.1       #忽略的IP列表,不受设置限制
bantime  = 36000             #屏蔽时间,单位:秒
findtime  = 600            #这个时间段内超过规定次数会被ban掉
maxretry = 3               #最大尝试次数
backend = auto             #日志修改检测机制(gamin、polling和auto这三种)

[sshd]                   #单个服务检查设置,如设置bantime、findtime、maxretry和全局冲突,服务优先级大于全局设置。
enabled  = true                        #是否激活此项(true/false)
filter   = sshd                         #过滤规则filter的名字,对应filter.d目录下的sshd.conf
action   = iptables[name=SSH, port=ssh, protocol=tcp]  #动作的相关参数,对应action.d/iptables.conf文件
logpath  = /var/log/secure                    #检测的日志文件path
bantime  = 36000
findtime  = 300
maxretry = 3

# systemctl enable fail2ban.service
# systemctl start fail2ban.service
# service fail2ban start   centos6 启动服务

四、解除fail2ban ban掉的IP 

查询限制列表
# iptables -L --line-numbers
Chain f2b-SSH (1 references)
num  target     prot opt source               destination         
1    REJECT     all  --  192.168.1.33               anywhere             reject-with icmp-port-unreachable
2    RETURN     all  --  anywhere             anywhere 

解除限制

# iptables -D f2b-SSH 1