# DDNS-Utils A collection of scripts to manage various aspects of using dynamic DNS, usually to cope with dynamic IP addressing ## he-dyndns A Python-based script to update dynamic DNS records when using the 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 that is RFC2136-compliant and supports TSIG-based updates. This script is a wrapper around nsupdate(1). Properly configured TSIG keys are needed. ## RouterOS Script for Address List Updates (ros-ddns-addrlist) A small RouterOS script for Mikrotik RouterOS to query a DNS name and put that IP address into an AddressLis. Note that the ``:resolve`` function doesn't support RR types. If there's an A you get that. If there's no A, you get AAAA. If there's neither, the script will bomb. # he-dyndns Installation / Use 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 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: ``` [keys] dynamic.example.com = 123412341234 ``` Other configuration sections will be ignored. ## Usage ``` usage: he-dyndns [-h] [--v4 | --v6] [--addr4 ADDR4 | --addr6 ADDR6] [--check-url CHECK_URL] [--state-file STATE_FILE] [--initialize-state] [--keyfile KEYFILE] [--key KEY] [--timeout TIMEOUT] [--debug] record Update Hurricane Electric DNS dynamic record positional arguments: record DNS record to update options: -h, --help show this help message and exit --v4 Update IPv4 A record (default) --v6 Update IPv6 AAAA record --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) --initialize-state Discover and store the current IPv4 and IPv6 addresses, then exit without updating HE --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 ``` ## Return Values Returns 0 on success (successful change or no change) or 1 on failure. Failures also include a single line error message. To seed both address families without reading an HE key or attempting an HE update: ``` he-dyndns --initialize-state home.example.com ``` Both discoveries must succeed before the state file is changed. 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 `/`. It serves `/.well-known/` directly from `/var/www/html` for ACME challenges. All service error bodies contain only the numeric status code and a newline, never HTML; see the full configuration in `deploy/ip.mfamily.org.nginx` for the error mappings: ``` server { listen 80; listen [::]:80; server_name ip.mfamily.org; location ^~ /.well-known/ { root /var/www/html; } location / { 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 ^~ /.well-known/ { root /var/www/html; } 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 ""; proxy_intercept_errors on; } location / { return 404 "404\n"; } } ``` 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 modules from `apt`, `dnf`, or `pip` as appropriate for your system. Copy `ddns-update-rfc2136` somewhere useful such as `/usr/local/bin`. ## Configuration The script expects there to be a file `/etc/ddns-RECORD.key` for every `record` being updated containing *only* the TSIG key for that record. For example, updating the record `foo.example.com` should have a file named `/etc/ddns-foo.example.com.key` available with that RR's key. It's possible to specify `--keyfile` to select an alternate location. Make sure that the key file is properly protected so only authorized users can view the contents. ## General Use This script finds the appropriate IP address from the interface specified in the `interface` position and then updates the record `record` in the zone `zone` on server `server`. For IPv4, each address is on a unique sub interface - e.g. eth0 vs eth0:0. To use the IP address other than the main interface's, specify the sub interface as show by `ifconfig` or `ip addr list` (see global secondary addresses) For IPv6, the script will take the numerically first address assigned to the interface. If there is no IPv6 address other than a link-scope address (i.e. an fe80:: address), then it will use the link-scope address - however that's probably not what's really desired. The script defaults to IPv6 addresses because that's what the original issue it was written for was solved to address and it's long past time the Internet has a v6-first attitude. It is not necessary to use the `--v6` flag, but it's included for pretty completeness. ## Example Usage To /usr/local/bin/ddns-update-rfc2136 enp1s0 foo.example.com example.com 192.0.2.2 ## Usage ``` usage: ddns-update-rfc2136 [-h] [--v4] [--v6] [--addr4 ADDR4] [--addr6 ADDR6] [--ttl TTL] [--keyfile KEYFILE] [--debug] interface record zone server Update dynamic DNS records using RFC2136 positional arguments: interface interface to obtain IP from (for IPv6, takes the numerically first global address on the interface) record DNS record to update zone Zone name to update (e.g. example.com) server Server to update (IP or FQDN) optional arguments: -h, --help show this help message and exit --v4 Update IPv4 A record --v6 Update IPv6 AAAA record (default) --addr4 ADDR4 Update A record with provided IP rather than detected IP (causes 'interface' to be ignored) --addr6 ADDR6 Update AAAA record with provided IP rather than detected IP (causes 'interface' to be ignored) --ttl TTL TTL to assign to record (default 300) --keyfile KEYFILE Alternate location for key config file (default /etc/ddns-RECORD.key where RECORD is the record name provided as the argument) --debug Enable debug logging ```