Skip to content

fail2ban auf einem systemd System (Debian 12)

Linux
  • 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 😁

  • Standby Problem mit Mediatek MT7921e

    Linux linux mediatek mt7921e
    1
    0 Stimmen
    1 Beiträge
    236 Aufrufe
    Niemand hat geantwortet
  • NodeBB - v3.3.0

    NodeBB nodebb linux
    1
    0 Stimmen
    1 Beiträge
    130 Aufrufe
    Niemand hat geantwortet
  • VSCodium - Meldungen trailing-whitespaces

    Linux vscodium vscode linux
    1
    3
    0 Stimmen
    1 Beiträge
    138 Aufrufe
    Niemand hat geantwortet
  • NodeBB - Update auf v1.18.6

    NodeBB nodebb nodejs linux
    1
    1
    0 Stimmen
    1 Beiträge
    160 Aufrufe
    Niemand hat geantwortet
  • OpenWRT - Zonen

    Verschoben OpenWRT & Ubiquiti ER-X openwrt linux
    2
    3
    0 Stimmen
    2 Beiträge
    652 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
  • Kopia - APT Repository verfügbar

    Kopia kopia linux
    1
    0 Stimmen
    1 Beiträge
    227 Aufrufe
    Niemand hat geantwortet
  • Restic - forget --keep-last 3 --prune

    Restic linux restic
    2
    0 Stimmen
    2 Beiträge
    663 Aufrufe
    FrankMF
    Ich habe mich damit noch ein wenig beschäftigt, die letzten drei zu behalten, ist nicht so optimal. Da es viele Optionen bei dem Befehl gibt, hier ein Ausschnitt Flags: -l, --keep-last n keep the last n snapshots -H, --keep-hourly n keep the last n hourly snapshots -d, --keep-daily n keep the last n daily snapshots -w, --keep-weekly n keep the last n weekly snapshots -m, --keep-monthly n keep the last n monthly snapshots -y, --keep-yearly n keep the last n yearly snapshots habe ich das ein wenig so angepasst, das ich denke es passt für mich. restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune Damit behalte ich auch die jeweils eines pro Monat. Und die letzten drei. Das sieht dann so aus. root@debian:~# ./backup2.sh repository 2f3f6147 opened successfully, password is correct Files: 38 new, 100 changed, 13268 unmodified Dirs: 0 new, 1 changed, 0 unmodified Added to the repo: 10.166 GiB processed 13406 files, 50.324 GiB in 3:24 snapshot 849f614c saved repository 2f3f6147 opened successfully, password is correct Applying Policy: keep the last 3 snapshots, 3 monthly snapshots snapshots for (host [debian], paths [/home/frank]): keep 5 snapshots: ID Time Host Tags Reasons Paths ------------------------------------------------------------------------------------ a7251cfd 2019-11-28 17:00:01 debian monthly snapshot /home/frank 283d4027 2019-12-31 17:00:01 debian monthly snapshot /home/frank ae2b96ec 2020-01-01 21:47:46 debian last snapshot /home/frank 079e00a6 2020-01-02 17:00:01 debian last snapshot /home/frank 849f614c 2020-01-03 21:08:45 debian last snapshot /home/frank monthly snapshot ------------------------------------------------------------------------------------ 5 snapshots remove 26 snapshots: ID Time Host Tags Paths ------------------------------------------------------------------ 896f16c2 2019-11-07 22:23:40 debian /home/frank b21bcf6d 2019-11-11 17:00:01 debian /home/frank f89248fb 2019-11-12 17:00:01 debian /home/frank 123ab546 2019-11-13 17:00:01 debian /home/frank b82d87d0 2019-11-18 17:00:01 debian /home/frank 040b0ab7 2019-11-19 17:00:01 debian /home/frank 7221d8ef 2019-11-20 17:00:01 debian /home/frank 84132a25 2019-11-21 17:00:01 debian /home/frank b558a52c 2019-11-25 17:00:01 debian /home/frank e5cc0c3e 2019-12-02 17:00:01 debian /home/frank 22423fa5 2019-12-03 17:00:01 debian /home/frank 39df1ab9 2019-12-04 17:00:01 debian /home/frank 98843457 2019-12-05 17:00:01 debian /home/frank b0cdd4b6 2019-12-09 17:00:01 debian /home/frank 828414f9 2019-12-10 17:00:01 debian /home/frank e34a27c3 2019-12-11 17:00:01 debian /home/frank 6e488c3b 2019-12-12 17:00:01 debian /home/frank 17898403 2019-12-16 17:00:01 debian /home/frank 1973305a 2019-12-17 17:00:01 debian /home/frank 9553bedd 2019-12-18 17:00:01 debian /home/frank fedf749d 2019-12-19 17:00:01 debian /home/frank 8e7cb876 2019-12-23 17:00:01 debian /home/frank 0bd0d102 2019-12-25 17:00:01 debian /home/frank 13d348b0 2019-12-26 17:00:01 debian /home/frank c7d960aa 2019-12-30 17:00:01 debian /home/frank f6ea9118 2020-01-01 17:00:01 debian /home/frank ------------------------------------------------------------------ 26 snapshots 26 snapshots have been removed, running prune counting files in repo building new index for repo [0:35] 100.00% 7806 / 7806 packs repository contains 7806 packs (46537 blobs) with 41.110 GiB processed 46537 blobs: 0 duplicate blobs, 0 B duplicate load all snapshots find data that is still in use for 5 snapshots [0:01] 100.00% 5 / 5 snapshots found 32654 of 46537 data blobs still in use, removing 13883 blobs will remove 0 invalid files will delete 715 packs and rewrite 752 packs, this frees 5.027 GiB [2:28] 100.00% 752 / 752 packs rewritten counting files in repo [0:01] 100.00% 6571 / 6571 packs finding old index files saved new indexes as [d137b425 f7caee99 a6e9711a] remove 35 old index files [1:13] 100.00% 1467 / 1467 packs deleted done using temporary cache in /tmp/restic-check-cache-916655151 repository 2f3f6147 opened successfully, password is correct created new cache in /tmp/restic-check-cache-916655151 create exclusive lock for repository load indexes check all packs check snapshots, trees and blobs read all data [7:47] 100.00% 6571 / 6571 items duration: 7:47 no errors were found root@debian:~# Am Ende seht ihr noch, wie Restic alle Files testet. Mein Script sieht jetzt so aus. #!/bin/bash # Script um mit Restic Daten automatisiert zu sichern! # Dient zum Sichern der Homepartition auf dem ROCKPro64 NAS! # Was soll gesichert werden? backup_pfad=/home/frank # Programm Start restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ backup $backup_pfad --exclude-file=excludes.txt restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune # Testen restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ check --read-data Das dann schön mit einem Cronjob laufen lassen und die Datensicherung ist erledigt
  • nginx konfigurieren

    NodeBB nodebb nginx linux
    1
    0 Stimmen
    1 Beiträge
    655 Aufrufe
    Niemand hat geantwortet