背景
随着硬件,网络,越来越好,爆破成本越来越低,保险起见还是搞个措施防一下
安装
yum install fail2ban
#or
apt install fail2ban
配置
# 开机启动
systemctl enable fail2ban
# 启动
systemctl start fail2ban
# 查看状态
systemctl status fail2ban
# 默认配置文件
vim /etc/fail2ban/jail.conf
# 重载配置文件
fail2ban-client reload
# 查看状态
fail2ban-client status
# sshd相关配置
[sshd]
enabled = true
port = ssh
logpath = /var/log/auth.log
bantime = 86400 # 单独设置封禁时间(秒),这里为 1 天
findtime = 600 # 600秒内
maxretry = 5 # 失败次数
# 自定义添加配置
[custom_service]# 自定义名称
enabled = true # 开启状态
port = 12345 # 监听端口
logpath = /var/log/my_custom_service.log #日志路径
bantime = 86400 # 封禁时间 1 天
findtime = 600 # 10分钟内
maxretry = 5 # 最大失败次数 5 次
# 一些指令
# 手动测试banip
fail2ban-client set sshd banip 156.xxx.xxx.xxx
# 解封
fail2ban-client set sshd unbanip 156.251.176.227
# 查看配置项
fail2ban-client get sshd bantime