centos7 安装 fail2ban

yum install -y fail2ban
cp /etc/fail2ban/jail.{conf,local}
cat << EOF > /tmp/sshd.local

[sshd]

enabled = true findtime = 1h maxretry = 5 bantime = 1y ignoreip = 127.0.0.1/8 ::1 192.168.0.0/24 port = ssh logpath = %(sshd_log)s backend = %(sshd_backend)s EOF cp /tmp/sshd.local /etc/fail2ban/jail.d/sshd.local systemctl enable –now fail2ban systemctl restart fail2ban

可接受的缩写标记:

years?, yea?, yy?
months?, mon?
weeks?, wee?, ww?
days?, da, dd?
hours?, hou?, hh?
minutes?, min?, mm?
seconds?, sec?, ss?
  • ? 代表可选标记,因此要以天为单位设置时间,例如 days / day / da / dd / d
  • 可以组合多个标记,格式为空格分隔,不带分隔符,例如:1y6mo 或 1d12h30m
  • 标记 m 和 mm 表示分钟,月份使用缩写 mo 或 mon

参考:https://denisrasulev.medium.com/server-protection-with-fail2ban-bfbe38a775b0