Salut,
Perso j'ai utilisé Gemini pour configurer et peaufiner fail2ban pour mon domoticz
Mon souhait était de blacklister directement tout le sous-réseau /24 d'une adresse IP intrusive
Par exemple :
2026-04-05 12:26:58.999 Error: Error parsing http request address: ::ffff:66.132.195.109
entraîne le bannissement de 66.132.195.* pendant 10 jours
Si il y a récidive, alors le bannissement est multiplié par 2
Ca fonctionne très bien
Pour exemple mon jail.local :
Code : Tout sélectionner
[DEFAULT]
allowipv6 = auto
backend = systemd
ignoreip = 127.0.0.1/8 ::1 192.168.1.0/24
# Bantime progressif global
bantime.increment = true
bantime.factor = 2
bantime.maxtime = 60d
bantime.rndtime = 1d
# --------------------------------------------------------
[sshd]
enabled = true
maxretry = 3
findtime = 600
bantime = 7d
# --------------------------------------------------------
# --------------------------------------------------------
[domoticz-parseerror]
enabled = true
filter = domoticz-parseerror
logpath = /home/pi/temp/domoticz.log
maxretry = 1
findtime = 86400
# Très agressif
bantime = 10d
action = iptables-ban-subnet[name=domoticz-parseerror, port="80,443,8080"]
backend = auto
# --------------------------------------------------------
Code : Tout sélectionner
cat iptables-ban-subnet.local
[Definition]
actionstart = /sbin/iptables -N fail2ban-<name>
/sbin/iptables -A fail2ban-<name> -j RETURN
/sbin/iptables -I <chain> -p <protocol> $([ ! "<port>" = "<known/tcp/ports>" ] && printf -- "-m multiport --dports <port>") -j fail2ban-<name>
actionstop = /sbin/iptables -D <chain> -p <protocol> $([ ! "<port>" = "<known/tcp/ports>" ] && printf -- "-m multiport --dports <port>") -j fail2ban-<name>
/sbin/iptables -F fail2ban-<name>
/sbin/iptables -X fail2ban-<name>
actioncheck = /sbin/iptables -n -L <chain> | grep -q 'fail2ban-<name>'
# Action de bannissement : au lieu de bannir l'IP, nous prenons le /24
# L'IP est passée dans <ip>, nous la convertissons en réseau /24
actionban = ip_address="<ip>"
subnet=$(echo "$ip_address" | sed 's/\.[0-9]\+$/.0\/24/')
/sbin/iptables -I fail2ban-<name> 1 -s "$subnet" -j <blocktype>
actionunban = ip_address="<ip>"
subnet=$(echo "$ip_address" | sed 's/\.[0-9]\+$/.0\/24/')
/sbin/iptables -D fail2ban-<name> -s "$subnet" -j <blocktype>
[Init]
name = default
chain = INPUT
port = ssh
protocol = tcp
blocktype = REJECT --reject-with icmp-port-unreachable
# blocktype = DROP