From 2474f6cade62ba937ff714f0aa54555f7ebc18d8 Mon Sep 17 00:00:00 2001 From: Jason McCormick Date: Mon, 2 Nov 2026 20:33:14 -0500 Subject: only update when changed, add daemon --- README.md | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 112 insertions(+), 20 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 9f2392c..f168a18 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,29 @@ A collection of scripts to manage various aspects of using dynamic DNS, usually to cope with dynamic IP addressing -## he-dyndns +## he-dyndns A Python-based script to update dynamic DNS records when using the -Hurricant Electric DNS service at ``dns.he.net``. This code is -designed to ba maximally portable by relying on standard -Python 3 libraries. It is not compatible with Python 2. +Hurricane Electric DNS service at `dns.he.net`. It uses only Python 3's +standard library. + +Unless an address is supplied with `--addr4` or `--addr6`, the script asks +`https://ip.mfamily.org/` for its public address over the selected IP family. +It compares that address with local state and contacts HE only when the address +has changed. IPv4 is selected by default; use `--v6` for IPv6. + +State defaults to `/var/lib/he-dyndns/state.json`. The file contains entries +for multiple records and both address families. Updates are locked and written +atomically, so separate IPv4 and IPv6 cron jobs can share it. State is recorded +only after HE returns `good` or `nochg`. Both address discovery and HE updates +use certificate-validated HTTPS. + +Explicit addresses retain unconditional update behavior and do not read or +write the state file: + +``` +he-dyndns --addr4 192.0.2.10 home.example.com +he-dyndns --addr6 2001:db8::10 home.example.com +``` ## ddns-update-rfc2136 A Python-based script to update DNS records in a master server @@ -22,18 +40,15 @@ get that. If there's no A, you get AAAA. If there's neither, the script will bomb. # he-dyndns Installation / Use -There is really nothing to install unless you need to add -Python3 stock libraries to your system. Copy he-dyndns somewhere useful -such as `/usr/local/bin`. - -For Debian/Ubuntu systems: ``apt install python3-dns python3-dnspython python3-urllib3`` - -For Fedora systems: ``dnf install python3-dns python3-urllib3`` +Copy `he-dyndns` somewhere useful such as `/usr/local/bin`. No third-party +Python modules are required. If it runs as a non-root service account, create +the state directory for that account first, or select a writable path with +`--state-file`. ## Configuration -Unless using the ``--key`` argument, keys for the dyanmic record -are read from ``/etc/he-dyndns.conf`` or from an alternative -location specified by ``--keyfile``. The configuration file +Unless using the `--key` argument, keys for the dynamic record +are read from `/etc/he-dyndns.conf` or from an alternative +location specified by `--keyfile`. The configuration file format is one section [keys] with record = key pairs. For example: ``` @@ -45,21 +60,27 @@ Other configuration sections will be ignored. ## Usage ``` -usage: he-dyndns [-h] [--v4] [--v6] [--addr4 ADDR4] [--addr6 ADDR6] [--key KEY] [--debug] record +usage: he-dyndns [-h] [--v4 | --v6] [--addr4 ADDR4 | --addr6 ADDR6] + [--check-url CHECK_URL] [--state-file STATE_FILE] + [--keyfile KEYFILE] [--key KEY] [--timeout TIMEOUT] [--debug] + record Update Hurricane Electric DNS dynamic record positional arguments: record DNS record to update -optional arguments: +options: -h, --help show this help message and exit --v4 Update IPv4 A record (default) --v6 Update IPv6 AAAA record - --addr4 ADDR4 Update A record with provided IP rather than detected IP - --addr6 ADDR6 Update AAAA record with provided IP rather than detected IP - --keyfile KEYFILE Alternate location for key config file (default /etc/he-dns-secret.conf) - --key KEY HE DDNS key for record (by default read from /etc/he-dns-secret.conf or --keyfile) + --addr4 ADDR4 Use this IPv4 address; bypass discovery/state comparison + --addr6 ADDR6 Use this IPv6 address; bypass discovery/state comparison + --check-url URL Public address service (default https://ip.mfamily.org/) + --state-file FILE Local comparison state (default /var/lib/he-dyndns/state.json) + --keyfile KEYFILE Key config file (default /etc/he-dyndns.conf) + --key KEY HE DDNS key for record; overrides --keyfile + --timeout SECONDS Network timeout in seconds (default 10) --debug Enable debug logging ``` @@ -68,6 +89,77 @@ optional arguments: Returns 0 on success (successful change or no change) or 1 on failure. Failures also include a single line error message. +For example, two cron entries can check both families while sharing the state +file: + +``` +*/5 * * * * /usr/local/bin/he-dyndns home.example.com +*/5 * * * * /usr/local/bin/he-dyndns --v6 home.example.com +``` + +# ip.mfamily.org address service + +`ip-echo-daemon` is the backend for the dual-stack public address check. It +binds to `127.0.0.1:8080` by default and trusts `X-Real-IP` only when the +connection comes from loopback. The included nginx configuration overwrites +that header with nginx's actual peer address. + +The hostname must have both an A record and an AAAA record pointing to the +VPS, and nginx must have a valid certificate for it. The included paths assume +a Let's Encrypt certificate. On the VPS: + +``` +install -m 0755 ip-echo-daemon /usr/local/bin/ip-echo-daemon +install -m 0644 deploy/ip-echo-daemon.service /etc/systemd/system/ip-echo-daemon.service +install -m 0644 deploy/ip.mfamily.org.nginx /etc/nginx/sites-available/ip.mfamily.org +ln -s /etc/nginx/sites-available/ip.mfamily.org /etc/nginx/sites-enabled/ip.mfamily.org +systemctl daemon-reload +systemctl enable --now ip-echo-daemon.service +nginx -t +systemctl reload nginx +``` + +The nginx server block redirects HTTP to HTTPS, listens on IPv4 and IPv6, and +proxies only `/`: + +``` +server { + listen 80; + listen [::]:80; + server_name ip.mfamily.org; + + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl; + listen [::]:443 ssl; + server_name ip.mfamily.org; + + ssl_certificate /etc/letsencrypt/live/ip.mfamily.org/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/ip.mfamily.org/privkey.pem; + + location = / { + proxy_pass http://127.0.0.1:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_pass_request_body off; + proxy_set_header Content-Length ""; + } + + location / { + return 404; + } +} +``` + +Verify both paths from another dual-stack system: + +``` +curl -4 https://ip.mfamily.org/ +curl -6 https://ip.mfamily.org/ +``` + # ddns-update-rfc2136 Installation/Use This script relies on the `netifaces` and `subprocess` libraries that are not always installed by default in Python3. Install those -- cgit v1.2.3