# To use more aggressive sshd modes set filter parameter "mode" in jail.local: # normal (default), ddos, extra or aggressive (combines all). # See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details. #mode = normal port = ssh logpath = %(sshd_log)s backend = %(sshd_backend)s # 新增下面几行 enabled = true # 秒 bantime = 86400 # 最大错误次数 maxretry = 3 # 如果主机在最后“findtime”秒内生成了“maxretry”,则该主机将被禁止 findtime = 10m
将 fail2ban 服务添加到开机自启动项
1
systemctl enable fail2ban
启动 fail2ban 服务
1
systemctl start fail2ban
查看服务状态
1
systemctl status fail2ban.service
查看 fail2ban 状态
1
fail2ban-client status
查看 sshd jail 状态
1
fail2ban-client status sshd
注意 默认的配置是 当 restart / reload fail2ban 服务时,被 ban 的 ip 列表将会被清除。
# Option: actionstop # Notes.: command executed at the stop of jail (or at the end of Fail2Ban) # Values: CMD # actionstop = <_ipt_del_rules> # 删除 <actionflush> 行 <actionflush> <iptables> -X f2b-<name>
重新加载 fail2ban 服务
1
systemctl reload fail2ban
手动添加向fail2ban 添加 禁止的 ip
1
fail2ban-client set sshd 8.8.8.8 4.4.4.4 114.114.114.114