# 安装fail2ban
yum -y install fail2ban
# 启动
systemctl start fail2ban
# 查看状态
systemctl status fail2ban
# 设置开机启动
systemctl enable fail2ban
# 检查版本
fail2ban-client -V
# 编辑配置文件
vi /etc/fail2ban/jail.local
# jail.local
[DEFAULT]
ignoreip = 127.0.0.1 # 忽略本机,不会被封禁
bantime = -1 # 封禁时间(秒)(-1 = 永久)
findtime = 3600 # 统计时间窗口:1 小时
maxretry = 4 # 1 小时内失败 5 次,结合上方封禁时间进行永久封禁
backend = auto # 自动选择日志读取方式
[sshd]
enabled = true # 启用 SSH 防暴力破解保护
filter = sshd # 使用内置 sshd 日志过滤规则
action = iptables[ # 使用 iptables 阻止 IP
name=SSH,
port=22, # SSH 实际端口
protocol=tcp
]
logpath = /var/log/secure # SSH 日志位置)
maxretry = 4 # SSH 单独的最大失败次数设置
bantime = -1 # 封禁永久
配置后需要重启服务
systemctl restart fail2ban
如果需要手动解禁
# 查看已封禁的IP
fail2ban-client status sshd
# 将1.2.3.4替换为需要解禁的ip
fail2ban-client set sshd unbanip 1.2.3.4
# 安装fail2ban
yum -y install fail2ban
# 启动
systemctl start fail2ban
# 查看状态
systemctl status fail2ban
# 设置开机启动
systemctl enable fail2ban
# 检查版本
fail2ban-client -V
# 编辑配置文件
vi /etc/fail2ban/jail.local
# jail.local
[DEFAULT]
ignoreip = 127.0.0.1 # 忽略本机,不会被封禁
bantime = -1 # 封禁时间(秒)(-1 = 永久)
findtime = 3600 # 统计时间窗口:1 小时
maxretry = 4 # 1 小时内失败 5 次,结合上方封禁时间进行永久封禁
backend = auto # 自动选择日志读取方式
[sshd]
enabled = true # 启用 SSH 防暴力破解保护
filter = sshd # 使用内置 sshd 日志过滤规则
action = iptables[ # 使用 iptables 阻止 IP
name=SSH,
port=22, # SSH 实际端口
protocol=tcp
]
logpath = /var/log/secure # SSH 日志位置)
maxretry = 4 # SSH 单独的最大失败次数设置
bantime = -1 # 封禁永久
配置后需要重启服务
systemctl restart fail2ban
如果需要手动解禁
# 查看已封禁的IP
fail2ban-client status sshd
# 将1.2.3.4替换为需要解禁的ip
fail2ban-client set sshd unbanip 1.2.3.4