doku erweitert

This commit is contained in:
scriptos 2025-08-19 00:28:11 +02:00
parent 368f182ae5
commit 08cdcd347d
2 changed files with 175 additions and 18 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2024 scriptos Copyright (c) 2025 scriptos
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

191
README.md
View File

@ -1,33 +1,190 @@
# DNS-Watch # DNS-Watch
Ein Bash-Skript zur Überwachung von DNS-Einträgen (A/AAAA-Records) für definierte Hosts. Ein Bash-Skript zur Überwachung von DNS-Einträgen (A/AAAA-Records) für definierte Hosts. Bei Änderungen werden Benachrichtigungen per **E-Mail** und/oder **ntfy** ausgelöst. Beide Benachrichtigungen sind als Funktionen implementiert und können separat aktiviert/deaktiviert werden.
Bei Änderungen werden Benachrichtigungen per **E-Mail** und/oder **ntfy** ausgelöst.
---
## Features ## Features
- Überwachung beliebiger Hosts und Subdomains - Überwachung beliebiger Hosts/Subdomains
- Unterstützung für **A**- und **AAAA**-Records - Record-Typen: **A** und **AAAA** (konfigurierbar)
- Speicherung des letzten Zustands zur Erkennung von Änderungen - Speicherung des letzten Zustands (Dateien je Host/Typ)
- Benachrichtigung: - Benachrichtigungen:
- **Mail** (konfigurierbar) - **Mail** (konfigurierbar; nutzt ein `mail`-Binary)
- **ntfy** mit **Bearer Token Auth** - **ntfy** mit **Bearer-Token-Auth**
- Logging & Lockfile (verhindert parallele Läufe) - Optionales Logging und Lockfile gegen Parallelstarts
- Konfigurierbar über Variablen im Skript - Eigener DNS-Resolver optional (z. B. 1.1.1.1)
---
## Voraussetzungen ## Voraussetzungen
- `bash` (>= 4.0) - `bash` (>= 4.0)
- `dig` (meist im Paket `dnsutils` oder `bind9-dnsutils`) - `dig` (Paket: `dnsutils` bzw. `bind9-dnsutils`)
- `curl` (für ntfy) - `curl` (für ntfy)
- `mail`-Binary (z. B. via `mailutils` oder `msmtp-mta`) nur falls Mail genutzt wird - `mail`-Binary, z. B. über `mailutils` oder `msmtp-mta` (nur nötig, wenn Mail genutzt wird)
---
## Installation ## Installation
1. Skript ins System legen: 1) Skript ablegen und ausführbar machen:
```bash
sudo cp dns-watch.sh /usr/local/bin/dns-watch.sh sudo cp dns-watch.sh /usr/local/bin/dns-watch.sh
sudo chmod +x /usr/local/bin/dns-watch.sh sudo chmod +x /usr/local/bin/dns-watch.sh
```
2) Optional: Verzeichnisse für State und Log vorab anlegen (werden sonst beim ersten Lauf erstellt):
sudo mkdir -p /var/lib/dns-watch
sudo mkdir -p /var/log && sudo touch /var/log/dns-watch.log
---
## Konfiguration
Öffne den Kopfbereich der Datei `dns-watch.sh` und passe die Variablen an:
- Hosts (Beispiele):
HOSTS=(
"domain.com"
"sub.domain.com"
)
- Record-Typen:
RECORD_TYPES=("A" "AAAA")
- Optionaler Resolver:
DNS_RESOLVER="1.1.1.1" # leer lassen für System-Resolver
- State/Log:
STATE_DIR="/var/lib/dns-watch"
LOG_FILE="/var/log/dns-watch.log" # leer lassen, um nur stdout zu nutzen
- Mail:
MAIL_ENABLED=true
MAIL_TO="mail@domain.com"
MAIL_FROM="noreply@domain.com"
MAIL_SUBJECT_PREFIX="[DNS-Watch]"
MAIL_BIN="/usr/bin/mail"
- ntfy:
NTFY_ENABLED=true
NTFY_SERVER="https://ntfy.sh"
NTFY_TOPIC="dns-watch"
NTFY_TOKEN="DEIN_NTFY_BEARER_TOKEN"
NTFY_TITLE_PREFIX="[DNS-Watch]"
NTFY_PRIORITY="default" # min | low | default | high | max
NTFY_TAGS="satellite,dns"
> Hinweis: Setze `MAIL_ENABLED=false` oder `NTFY_ENABLED=false`, um einzelne Kanäle zu deaktivieren.
---
## Test
Manueller Testlauf:
/usr/local/bin/dns-watch.sh
Beim **ersten Lauf** wird bewusst eine Änderung erzeugt (da noch kein Altzustand existiert) und direkt eine Test-Benachrichtigung versendet.
---
## Automatisierung
### Cron
Alle 10 Minuten prüfen:
*/10 * * * * /usr/local/bin/dns-watch.sh
### Systemd (optional)
Dienstdatei `/etc/systemd/system/dns-watch.service`:
[Unit]
Description=DNS Watch - monitor DNS record changes
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/dns-watch.sh
Nice=5
Timer `/etc/systemd/system/dns-watch.timer`:
[Unit]
Description=Run DNS Watch every 10 minutes
[Timer]
OnBootSec=2m
OnUnitActiveSec=10m
AccuracySec=1m
Unit=dns-watch.service
[Install]
WantedBy=timers.target
Aktivieren:
sudo systemctl daemon-reload
sudo systemctl enable --now dns-watch.timer
---
## Verzeichnisse
- Zustände: `/var/lib/dns-watch/`
- Logdatei (optional): `/var/log/dns-watch.log`
- Lockfile: `/tmp/dns-watch.lock`
---
## Beispielausgabe
DNS-Änderung erkannt
Host: sub.domain.com
Typ: A
Zeit: 2025-08-18T12:34:56+02:00
Alt:
192.0.2.10
Neu:
192.0.2.55
Diese Meldung wird (je nach Konfiguration) per Mail und/oder ntfy verschickt.
---
## Troubleshooting
- `mail: command not found`: Ein Mailer-Paket installieren (z. B. `sudo apt install mailutils` oder `msmtp-mta`).
- `dig: command not found`: `sudo apt install dnsutils` (oder passendes Paket für deine Distribution).
- Keine Benachrichtigung per ntfy: Prüfe `NTFY_SERVER`, `NTFY_TOPIC`, `NTFY_TOKEN` und Netzwerkzugang.
- Rechteproblem beim Schreiben in `/var/lib/dns-watch` oder `/var/log/dns-watch.log`: Skript als root ausführen oder Verzeichnisse mit passenden Rechten anlegen.
---
## Sicherheit
- Lege sensible Daten (z. B. `NTFY_TOKEN`) nach Möglichkeit nicht im Git ab. Alternativ kannst du das Skript so erweitern, dass es Tokens aus Umgebungsvariablen lädt.
- Achte auf sichere Mail- und ntfy-Endpunkte.
---
## Lizenz
MIT License
<p align="center"> <p align="center">