自动阻止连接失败过多的IP地址
#安装
apt-get install fail2ban -y
#centos
dnf install fail2ban
systemctl status fail2ban
systemctl restart fail2ban
systemctl enable fail2ban
配置说明:https://blog.csdn.net/culun797375/article/details/108824510
apt install iptabls rsyslog -y
# vi /etc/fail2ban/jail.conf
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local #默认支持此配置
[DEFAULT]
#ignoreip = 127.0.0.1/8 ::1 #永远不会被禁止的IP地址白名单, 在每个IP地址之间留一个空格, 可以忽略此项
bantime = 10m # 禁止IP地址的时间(m代表分钟), h小时, 值-1将永久禁止IP
findtime = 10m # 尝试失败的,过滤时长(秒)
maxretry = 5 # 允许失败次数
[sshd]
enabled = true #添加此项
filter = sshd
maxretry = 3 #错误次料
bantime = 600 #秒
#bantime = 10m #禁止时间 10分钟
#port = ssh
port = 1234 #如果改了端口注意修改此项
#重新载入配置
fail2ban-client reload
[DEFAULT]
#禁用默认
#banaction = iptables-multiport
#banaction_allports = iptables-allports
# 使用ufw防火墙
banaction = ufw # 使用ufw防火墙(未测试成功)
banaction = ufw[application=$(app), blocktype=reject]
#nftables防火墙配置(测试成功)
banaction = nftables-multiport
banaction_allports = nftables-allports
fail2ban-client status
#查看当前被禁止登陆的ip
fail2ban-client status sshd
fail2ban-client status ssh-iptables
cat /var/log/fail2ban.log
#取消ban某个ip
fail2ban-client set ssh-iptables unbanip 42.34.45.78
https://github.com/fail2ban/fail2ban/discussions/3575