
Ich möchte eine Fail2Ban-Aktion erstellen, die den Datenverkehr bei einer Sperraktion an eine andere IP umleitet und bei einer Aufhebung der Sperre die Route entfernt.
Datei: iptables-route.conf in /etc/fail2ban/action.d/
# Fail2Ban configuration file
#
#
[INCLUDES]
before = iptables-common.conf
[Definition]
# Option: actionstart
# Notes.: command executed once at the start of Fail2Ban.
# Values: CMD
#
actionstart = <iptables> -N f2b-<name>
<iptables> -A f2b-<name> -j <returntype>
<iptables> -I <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
<iptables> -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT
<iptables> -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT
# Option: actionstop
# Notes.: command executed once at the end of Fail2Ban
# Values: CMD
#
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
<actionflush>
<iptables> -X f2b-<name>
<iptables> -D FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT
<iptables> -D FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT
# Option: actioncheck
# Notes.: command executed once before each actionban command
# Values: CMD
#
actioncheck = <iptables> -n -L <chain> | grep -q 'f2b-<name>[ \t]'
# Option: actionban
# Notes.: command executed when banning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionban = <iptables> -I f2b-<name> 1 PREROUTING -s <ip> -j DNAT --to-destination 188.68.45.124
# Option: actionunban
# Notes.: command executed when unbanning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionunban = <iptables> -D f2b-<name> -s <ip> -j DNAT --to-destination 188.68.45.124
[Init]
Datei apache-route.local in /etc/fail2ban/jail.d/:
[apache-route]
enabled = true
filter = apache-probe
port = http,https
banaction = iptables-route.conf
maxretry = 3
findtime = 1500
bantime = 600
logpath = /var/www/*/userdata/logs/*-access.log
Ich kann es nicht einmal testen, da mir folgende Fehlermeldung angezeigt wird:
Fail2ban-Client neu starten
Keine zugänglichen Konfigurationsdateien für „action.d/iptables-route.conf“ unter /etc/fail2ban gefunden
Aktion „iptables-route.conf“ kann nicht gelesen werden
Fehler im Jail „Apache-Route“. Überspringen...
Ich versuche, es zum Laufen zu bringen, aber ich habe keine Ahnung, warum mir dieser Fehler angezeigt wird
Antwort1
Aktion „iptables-route.conf“ kann nicht gelesen werden
Einfach .conf
aus dem Aktionsnamen entfernen:
-banaction = iptables-route.conf
+banaction = iptables-route
Übrigens. Ihre Aktion sieht für mich ein bisschen falsch aus. Warum nicht einfach standardmäßig iptables-multiport
mit angegebenem (überschriebenem) chain
und blocktype
?
Ich bin mir nicht sicher, was Sie versuchen, aber so etwas wie das hier wäre nicht in Frage gekommen:
banaction = iptables-multiport[chain=PREROUTING, blocktype="DNAT --to-destination 188.68.45.124"]
mach den Job?
Antwort2
Warum wird iptables-multiport nicht einfach standardmäßig mit angegebener (überschriebener) Kette und Blocktyp verwendet?
iptables-multiport fügt die Ausgabeketten nicht hinzu:
-A WEITER -i ens3 -p tcp -m status --status NEU --dport 80 -j AKZEPTIEREN
-A WEITER -i ens3 -p tcp -m status --state NEU --dport 443 -j AKZEPTIEREN
also habe ich beschlossen, eine eigene Aktion zu erstellen, die diese hinzufügt und beim Laden/Entladen entfernt
Ich habe vergessen, dass ich auch ein Postrouting implementieren muss, aber ich muss noch einmal darüber nachdenken, um dies zu archivieren.
Was ich möchte:
Bei einer Sperrung wird die Anfrage an eine andere IP-Adresse weitergeleitet, auf der eine Seite gehostet wird, auf der steht „Sie sind aufgrund zu vieler ungültiger Anfragen gesperrt“, anstatt die Anfrage einfach abzulehnen/zu löschen.