Servus,
ich nutze ipv64.net mit mehreren Subdomains auf unterschiedlichen DNS Adressen. Um jetzt nur bestimmte Einträge eines Ziels (externe IP) zu aktualisieren, habe ich einen Docker Container gebaut.
Ich würde mich freuen, wenn ihr mir hier Kritik, Vorschläge, Kommentare da lassen würdet ![]()
Erst einmal nötige Ordner und Files erstellen
mkdir ipv64_updater
cd ipv64_updater
mkdir logs
mkdir data
touch data/domains.txt
touch data/last_ip.txt
nun das docker-compose-file erstellen und den folgenden Text einfügen.
nano docker-compose.yml
services:
ddns-ipv64:
image: alpine:latest
container_name: ddns-ipv64
volumes:
- ./data:/data
# - ./data/domains.txt:/data/domains.txt
# - ./data/last_ip.txt:/data/last_ip.txt
- ./entrypoint.sh:/entrypoint.sh
- ./logs:/logs
environment:
- TZ=Europe/Berlin
- AUTH_TOKEN=<YOUR_Security_Level_2_key>
restart: unless-stopped
command: sh -c "apk add --no-cache curl jq && sh /entrypoint.sh"
den AUTH_TOKEN findet ihr auf eurer Domainseite nach den Subdomains.
Jetzt das eigentliche Skript erstellen und den Text einfügen
nano entrypoint.sh
#!/bin/sh
set -e
# =====================
# Konfiguration
# =====================
DOMAINS_FILE="/data/domains.txt"
LOG_FILE="/logs/ip_change.log"
LAST_IP_FILE="/data/last_ip.txt"
AUTH_TOKEN="${AUTH_TOKEN}"
CHECK_INTERVAL=60 # Sekunden zwischen IP-Checks
API_URL="https://ipv4.ipv64.net/update.php"
# =====================
# Initialisierung
# =====================
echo "$(date '+%Y-%m-%d %H:%M:%S') - DDNS Script gestartet" | tee -a "$LOG_FILE"
# Lade letzte bekannte IP
if [ -f "$LAST_IP_FILE"]; then
last_ip=$(cat "$LAST_IP_FILE")
else
last_ip=""
fi
# =====================
# Funktionen
# =====================
get_current_ip() {
curl -s-4 https://api64.ipify.org
}
update_domain() {
local domain="$1"
local ip="$2"
echo "$(date '+%Y-%m-%d %H:%M:%S') - Aktualisiere $domain auf $ip" | tee -a "$LOG_FILE"
response=$(curl -s "${API_URL}?domain=${domain}&ip=${ip}&key=${AUTH_TOKEN}")
# Prüfen auf Status
status=$(echo "$response" | jq -r '.status')
info=$(echo "$response" | jq -r '.info')
if ["$status"="ok"]; then
if ["$info"="nochg"]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - $domain bereits auf $ip, keine Änderung nötig" | tee -a "$LOG_FILE"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - Update erfolgreich für $domain: $info" | tee -a "$LOG_FILE"
fi
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - FEHLER: Update fehlgeschlagen für $domain: $response" | tee -a "$LOG_FILE"
fi
}
# =====================
# Hauptschleife
# =====================
while true; do
current_ip=$(get_current_ip)
if [ -z "$current_ip"]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - WARNUNG: Konnte aktuelle IP nicht ermitteln" | tee -a "$LOG_FILE"
elif ["$current_ip"!="$last_ip"]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - IP Änderung erkannt: $last_ip → $current_ip" | tee -a "$LOG_FILE"
last_ip="$current_ip"
echo "$last_ip">"$LAST_IP_FILE"
# Update alle Domains
while IFS= read -r domain || [ -n "$domain"]; do
[ -z "$domain"] && continue
update_domain"$domain" "$current_ip"
done <"$DOMAINS_FILE"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - IP unverändert: $current_ip" | tee -a "$LOG_FILE"
fi
sleep$CHECK_INTERVAL
done
nun noch das domains-file erstellen und die gewünschten URLs eintragen. Beispiel: deinesubdomain.meinedomain.dns64.de
nano data/domains.txt
subdomain.domain
2ndsubdomain.domain
nun mit docker compose up das ganze starten und die domains sollten die IP des rechners im Netz bekommen.