Skip to content

fail2ban auf einem systemd System (Debian 12)

Linux
2 1 231
  • Ich hatte vor längerer Zeit mal das Problem ein fail2ban auf einem Debian 12 zu installieren, das kann man hier nachlesen. Damals hatte ich aufgegeben und Crowdsec installiert. Diesmal hatte ich das Problem anders herum, diesmal ging Crowdsec nicht. Also mal wieder fail2ban ausprobiert.

    Mittlerweile weiß ich, das es was mit dem Wechsel zu systemd und dem Entfernen von rsyslog zu tuen hat. Auch diesmal ging fail2ban nicht. Er meckert über nicht gefundene Logfiles. Wenn man nun das Paket rsyslog installiert, funktioniert alles. Aber.....

    Ich habe dann gesucht und gefunden, das man seit Einführung von systemd rsyslog nicht mehr benötigt. Wenn man das jetzt zusätzlich installiert, würde alles doppelt geloggt. Das wollen wir ja auch nicht 😉

    Server Infos

    root@minio:~# uname -a
    Linux minio 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64 GNU/Linux
    
    root@minio:~# cat /etc/debian_version 
    12.10
    

    Das Problem und seine Lösung

    Beim Arbeiten mit der Datei

    /etc/fail2ban/jail.local

    bin ich auf folgendes gestoßen.

    # "backend" specifies the backend used to get files modification.
    # Available options are "pyinotify", "gamin", "polling", "systemd" and "auto".
    # This option can be overridden in each jail as well.
    #
    # pyinotify: requires pyinotify (a file alteration monitor) to be installed.
    #              If pyinotify is not installed, Fail2ban will use auto.
    # gamin:     requires Gamin (a file alteration monitor) to be installed.
    #              If Gamin is not installed, Fail2ban will use auto.
    # polling:   uses a polling algorithm which does not require external libraries.
    # systemd:   uses systemd python library to access the systemd journal.
    #              Specifying "logpath" is not valid for this backend.
    #              See "journalmatch" in the jails associated filter config
    # auto:      will try to use the following backends, in order:
    #              pyinotify, gamin, polling.
    #
    # Note: if systemd backend is chosen as the default but you enable a jail
    #       for which logs are present only in its own log files, specify some other
    #       backend for that jail (e.g. polling) and provide empty value for
    #       journalmatch. See https://github.com/fail2ban/fail2ban/issues/959#issuecomment-74901200
    backend = auto
    

    Das ist jetzt die Standard Konfiguration, die nicht mit systemd läuft. Diese Standard Konfiguration lief mit rsyslog einwandfrei. Ok, kurzer Hand rsyslog deinstalliert. Den Eintrag

    backend = auto
    

    auf

    backend = systemd
    

    umgestellt.

    sshd

    Mit rsyslog stand es auf

    [sshd]
    
    # To use more aggressive sshd modes set filter parameter "mode" in jail.local:
    # normal (default), ddos, extra or aggressive (combines all).
    # See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
    # mode   = normal
    port    = ssh
    logpath = %(sshd_log)s
    backend = %(sshd_backend)s
    

    Jetzt mit systemd umgeschrieben auf

    [sshd]
    
    # To use more aggressive sshd modes set filter parameter "mode" in jail.local:
    # normal (default), ddos, extra or aggressive (combines all).
    # See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
    # mode   = normal
    port    = ssh
    # logpath = %(sshd_log)s
    # backend = %(sshd_backend)s
    backend = systemd
    

    Lief immer noch nicht 😞 Mal die AI im Netz befragt und es kam.

    apt install python3-systemd
    

    Danach neugestartet und fail2ban loggt die Bösen 🙂

     root@minio:/var/log# fail2ban-client status sshd
     Status for the jail: sshd
     |- Filter
     |  |- Currently failed: 6
     |  |- Total failed:     106
     |  `- Journal matches:  _SYSTEMD_UNIT=sshd.service + _COMM=sshd
     `- Actions
        |- Currently banned: 75
        |- Total banned:     78
        `- Banned IP list:   1.215.240.130 103.52.114.200 103.83.86.165 104.28.162.115 104.28.239.219 104.28.239.220 113.44.199.167 114.130.56.192 118.193.46.102 121.224.78.164 134.209.82.105 137.184.86.214 139.99.170.30 14.103.118.248 14.103.250.90 14.55.144.22 147.182.236.138 152.32.188.56 157.20.237.241 167.172.247.164 185.228.234.171 185.255.91.157 185.93.89.118 186.123.101.50 187.34.212.38 192.3.233.249 202.131.233.35 218.92.0.103 218.92.0.111 218.92.0.112 218.92.0.198 218.92.0.216 218.92.0.217 218.92.0.218 218.92.0.219 218.92.0.220 218.92.0.221 218.92.0.222 218.92.0.223 218.92.0.225 218.92.0.226 218.92.0.227 218.92.0.228 218.92.0.229 218.92.0.230 218.92.0.231 218.92.0.232 218.92.0.233 218.92.0.235 218.92.0.236 218.92.0.237 220.81.148.101 23.26.125.9 27.254.235.1 27.71.27.141 42.100.36.28 46.101.123.194 51.68.199.237 51.75.161.208 51.75.161.70 52.87.142.193 57.129.16.89 64.227.132.163 68.183.220.4 80.94.95.125 80.94.95.189 83.235.16.111 84.235.229.53 91.103.106.118 92.118.39.86 177.85.247.230 183.237.17.60 92.118.39.74 156.236.66.138 182.92.142.76
    

    Ok, funktioniert gut. Jetzt wollte ich das noch für das Minio-UI haben. Das sieht dann so aus.

    [minio-ui]
    enabled   = true
    backend   = auto
    port      = http,https
    filter    = minio-ui
    logpath   = /var/log/nginx/access.log
    maxretry  = 3
    findtime  = 10m
    bantime   = 1h
    

    Hier setzt man das Backend wieder auf auto und das Logfile kommt vom nginx.

    Ich hänge noch ein paar Dinge hier an, falls ich die nochmal brauche.

    Installation

    apt install fail2ban
    apt install python3-systemd
    cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
    

    Konfiguration

    nano /etc/fail2ban/jail.local
    

    fail2ban-client

    fail2ban-client status sshd
    fail2ban-client status minio-ui
    fail2ban-client unban <IP-Adresse>
    

    systemd

    systemctl status fail2ban
    

    Fazit

    Wieder was gelernt. Sollte hier Blödsinn stehen, bitte ich um einen Kommentar, damit ich das anpassen oder auch löschen kann.

    Und, man kann sich auf diesem Server gar nicht mit Passwort am sshd anmelden 😁

  • Auf Debian 13 Trixie fehlt noch folgendes

    apt install python3-setuptools
    
  • FrankMF FrankM hat auf dieses Thema verwiesen
  • Firefox - Cookie Banner blocken

    Linux firefox linux
    1
    0 Stimmen
    1 Beiträge
    214 Aufrufe
    Niemand hat geantwortet
  • Ansible - Hetzner Server erstellen

    Verschoben Ansible ansible linux hcloud
    1
    3
    0 Stimmen
    1 Beiträge
    345 Aufrufe
    Niemand hat geantwortet
  • Hetzner Cloud - Volumes

    Allgemeine Diskussionen linux
    1
    3
    0 Stimmen
    1 Beiträge
    1k Aufrufe
    Niemand hat geantwortet
  • OpenWRT - Zonen

    Verschoben OpenWRT & Ubiquiti ER-X openwrt linux
    2
    3
    0 Stimmen
    2 Beiträge
    696 Aufrufe
    FrankMF
    Es ist was heller geworden [image: 1610188645165-7b86e97c-31a5-44b6-809f-25d9d1c2ee4a-image.png] Die besagte Forward Regel [image: 1610188840619-zonen.png] Diese Forward Regel zieht erst dann, wenn es mehrere Interfaces in einer Zone gibt. Aus der Doku INPUT rules for a zone describe what happens to traffic trying to reach the router itself through an interface in that zone. OUTPUT rules for a zone describe what happens to traffic originating from the router itself going through an interface in that zone. FORWARD rules for a zone describe what happens to traffic passing between different interfaces belonging in the same zone. Das heisst nun, das ein Forwarding zwischen zwei Zonen immer eine spezifische Regel unter Traffic Rules benötigt. Forwarding between zones always requires a specific rule. Somit ist ein Forwarding zwischen zwei Zonen in den Standard Einstellungen nicht erlaubt. Das kann ich hier auch so bestätigen. Das ist ja auch das was ich mit meiner "DMZ"-Zone erreichen möchte. Kein Zugriff auf LAN. Unter Zone ⇒ Forwardings kann man jetzt sehen, das das Forwarding von LAN in Richtung WAN und DMZ erlaubt ist. WAN ist logisch, sonst komme ich ja nicht ins Internet. DMZ habe ich eingestellt, damit ich auch Teilnehmer im DMZ Netz erreichen kann, wenn ich da mal ran muss. [image: 1610189307657-8a548c29-8bc5-4074-8099-66460bcea9a8-image.png] Stelle ich das jetzt so ein. [image: 1610189398985-dca8b393-f613-4cab-a377-ffbc2bb8ddf5-image.png] Dann kann ich von der DMZ Zone aus das LAN erreichen. Aha, so langsam verstehe ich Quelle: https://forum.openwrt.org/t/firewall-zones-and-settings/84369
  • Debian Buster 10 Release

    Linux linux nvidia
    3
    1
    0 Stimmen
    3 Beiträge
    463 Aufrufe
    FrankMF
    Da man ja beim Login auswählen kann, mit was die Session startet, war ich doch jetzt etwas neugierig was überhaupt läuft. [image: 1562484643462-img_20190707_092217.jpg] frank@debian:~$ echo $WAYLAND_DISPLAY frank@debian:~$ loginctl SESSION UID USER SEAT TTY 7 1000 frank seat0 tty2 c1 116 Debian-gdm seat0 tty1 2 sessions listed. frank@debian:~$ loginctl show-session c1 -p Type Type=x11 frank@debian:~$ loginctl show-session c1 Id=c1 User=116 Name=Debian-gdm Timestamp=Sat 2019-07-06 22:43:34 CEST TimestampMonotonic=30094837 VTNr=1 Seat=seat0 TTY=tty1 Remote=no Service=gdm-launch-environment Scope=session-c1.scope Leader=1015 Audit=4294967295 Type=x11 Class=greeter Active=no State=online IdleHint=yes IdleSinceHint=1562446130937731 IdleSinceHintMonotonic=346278596 LockedHint=yes Die Installation der Nvidia Treiber macht da wohl einen x11 Desktop raus. Aber auch nicht weiter schlimm, der Wayland lief ja hier überhaupt nicht. Würde mich aber über interessante Links zum Thema freuen
  • ACER und der UEFI-Booteintrag!

    Linux linux
    1
    0 Stimmen
    1 Beiträge
    242 Aufrufe
    Niemand hat geantwortet
  • Wireguard

    Verschoben Wireguard linux rockpro64 wireguard
    4
    0 Stimmen
    4 Beiträge
    966 Aufrufe
    FrankMF
    Etwas schnellerer Weg den Tunnel aufzubauen, Voraussetzung wireguard modul installiert Keys erzeugt Danach dann einfach ip link add wg0 type wireguard wg setconf wg0 /etc/wireguard/wg0.conf Datei /etc/wireguard/wg0.conf [Interface] PrivateKey = <Private Key> ListenPort = 60563 [Peer] PublicKey = <Public Key Ziel> Endpoint = <IPv4 Adresse Zielrechner>:58380 AllowedIPs = 10.10.0.1/32 Die Rechte der Dateien von wireguard müssen eingeschränkt werden. sudo chmod 0600 /etc/wireguard/wg0.conf Das ganze per rc.local beim Booten laden. Datei /root/wireguard_start.sh ############################################################################################### # Autor: Frank Mankel # Startup-Script # Wireguard # Kontakt: frank.mankel@gmail.com # ############################################################################################### ip link add wg0 type wireguard ip address add dev wg0 10.10.0.1/8 wg setconf wg0 /etc/wireguard/wg0.conf ip link set up dev wg0 Danach Datei ausführbar machen chmod +x /root/wireguard_start.sh In rc.local /root/wireguard_start.sh eintragen - Fertig!
  • Ubuntu Bionic - IP Adresse ändern

    Angeheftet Verschoben Linux linux
    1
    0 Stimmen
    1 Beiträge
    2k Aufrufe
    Niemand hat geantwortet