- Go 89.3%
- Shell 5.4%
- Jsonnet 3.4%
- Just 1.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
ci/crow/push/lint Pipeline was successful
Repo Lint failed on lint-report.xml, the JUnit file the Go Lint step writes into the workspace the steps share -- two steps, no ordering between them, so whether the report exists by the time the tree is walked is scheduling. It came out on an unrelated commit because adding a step reshuffled that. Locally it cannot happen: editorconfig-checker checks files tracked by git, and a Crow checkout has no git, so over there it walks the tree instead. Hence the exclude as well as the ignore -- the ignore only speaks for a real checkout. |
||
| .crow | ||
| cmd/pdns-ddns | ||
| deploy/systemd | ||
| internal/ddns | ||
| LICENSES | ||
| scripts | ||
| .editorconfig | ||
| .editorconfig-checker.json | ||
| .gitignore | ||
| .golangci.yml | ||
| AGENTS.md | ||
| CHANGELOG.md | ||
| go.mod | ||
| go.sum | ||
| justfile | ||
| README.md | ||
| renovate.json | ||
| REUSE.toml | ||
pdns-ddns
A tiny HTTP endpoint that receives inadyn-style DDNS updates and turns them into a PowerDNS API call, so a gateway whose WAN address changes can publish its own A record without a third-party DNS provider in the middle.
It speaks the dyndns dialect inadyn and the UniFi firmware already know: basic auth,
a hostname and an myip in the query string, and a good/nochg reply. On the
other side it does one read and, only when the address moved, one
PATCH …/rrsets with changetype: REPLACE.
UniFi WAN (inadyn) --HTTPS + basic auth--> pdns-ddns --X-API-Key--> PowerDNS master
|
`-- SOA serial + NOTIFY --> secondaries
Single static binary, one dependency (go-systemd: activation for socket activation,
daemon for sd_notify, and the golang.org/x/sys/unix the latter calls), no database,
no cache.
Quick start
just build
export DDNS_TOKEN="$(openssl rand -hex 24)"
export DDNS_ZONES="dyn.aether.earth"
export PDNS_URL="http://100.105.58.81:16419" # the master's API
export PDNS_API_KEY="…"
./bin/pdns-ddns -check # validates the config and reaches PowerDNS, then exits
./bin/pdns-ddns &
curl -u "gateway:$DDNS_TOKEN" \
'http://127.0.0.1:8053/nic/update?hostname=home.dyn.aether.earth&myip=203.0.113.9'
# good home.dyn.aether.earth
-check is the one to run in ExecStartPre: it catches a wrong API key at deploy
time instead of on the first WAN IP change, which is the worst possible moment to
find out.
Configuration
Everything comes from the environment.
| Variable | Required | Default | Meaning |
|---|---|---|---|
DDNS_TOKEN |
yes¹ | — | The bearer credential. Compared in constant time. Minimum 16 characters. |
DDNS_TOKEN_PATH |
— | Read the token from this file instead. See secrets. | |
DDNS_ZONES |
yes | — | Comma-separated allowlist of zones this service may write. Everything else is refused before PowerDNS is contacted. |
PDNS_URL |
yes | — | Absolute http(s) URL of the PowerDNS API, e.g. http://100.105.58.81:16419. |
PDNS_API_KEY |
yes¹ | — | Sent as X-API-Key. |
PDNS_API_KEY_PATH |
— | Read the key from this file instead. | |
DDNS_LISTEN |
:8053 |
Listen address. Not consulted while socket-activated, where systemd holds the socket — keep it matching the ListenStream= there anyway. |
|
DDNS_TTL |
300 |
TTL for written RRsets, 30–86400. Applied on write, so changing it only affects the next actual update. | |
DDNS_PATH |
— | Extra URL paths accepted as update endpoints, space or comma separated. /nic/update, /update and / are always on. |
|
DDNS_TRUST_PROXY |
false |
Believe X-Forwarded-For / X-Real-IP when the request sent no address. Set it behind any proxy: without it the peer address is used, which is the proxy's own — refused when that is loopback, silently published when the proxy is on another host. A client can then name the address it wants published, so only behind a proxy you control. |
|
DDNS_LOG_LEVEL |
info |
debug also logs nochg responses. |
|
PDNS_SERVER |
localhost |
The API server name from PowerDNS's api-config/local-address. Only change it if you renamed it. |
|
PDNS_TIMEOUT |
10s |
Per-request timeout. A bare number means seconds. |
¹ Or the *_PATH file, or a credential of the same name in $CREDENTIALS_DIRECTORY.
The update endpoint
GET or POST to /nic/update (plus /update, /, and whatever DDNS_PATH adds).
Parameters. Names are matched case-sensitively, as sent:
| Purpose | Accepted names | Notes |
|---|---|---|
| Hostname | hostname, host, domain, name, yohost |
First non-empty wins. |
| Address | myip, ip, ipv4, ip4, myip6, ip6, ipv6 |
Comma/space separated lists allowed. Every value is parsed and then sorted by family, so an IPv6 address in myip still becomes an AAAA. |
| Neither | — | With no address at all the request's own IP is used — see DDNS_TRUST_PROXY. |
Authentication. HTTP basic auth. The token goes in the password and the
username is ignored — that is what the UniFi DDNS password field and inadyn's
password both produce. A template that fills in only a username is covered too.
Authorization is the only credential accepted; there is no token-in-URL mode.
Replies are the dyndns vocabulary, one line of text/plain. inadyn's generic
plugin already accepts good and nochg as success, so nothing extra is needed in
its config.
| Body | Status | When |
|---|---|---|
good <host> |
200 | An RRset changed. |
nochg <host> |
200 | PowerDNS already had exactly those addresses — nothing was written, so no SOA bump and no NOTIFY. |
badauth |
401 | Missing or wrong credentials. |
notfqdn |
400 | The hostname is missing or is not a usable host name. Also returned when PowerDNS does not have the zone. |
noauth |
401 | Well-formed name, but not under an allowlisted zone. |
badagent |
400 | No usable address, or an address that must not be published (0.0.0.0, multicast). |
dnserr |
500 | PowerDNS refused or could not be reached. Check the service log; the client cannot fix this. |
What is deliberately refused, and why:
- The zone apex. Names must be a strict subdomain of an allowlisted zone. An
apex update would move the domain itself, which is where
NS,MXand the OctoDNS-owned records live.aether.earth→noauth,home.aether.earth→ OK. (inadyn's@spelling for the apex is refused the same way.) - Labels starting with
_, which is how an ACME challenge record is spelled. A writable_acme-challengeis a certificate-minting primitive. 0.0.0.0and multicast. Blackholing the name is worse than refusing the update.- IPv4-in-IPv6 and zoned IPv6 are normalised (
::ffff:1.2.3.4→A,fe80::1%eth0→fe80::1), because none of those forms mean anything in DNS.
Configuring UniFi
UniFi's DDNS client is inadyn: the picker chooses a provider whose update template
is compiled into the firmware, and the optional Server field redirects where that
template is sent. So pick the provider whose template matches this service —
dyndns, whose path is /nic/update?hostname=<host>&myip=<ip> — and point it at
yourself.
Settings → Internet → (WAN) → Dynamic DNS
| Field | Value |
|---|---|
| Service | Custom if your firmware has it, otherwise dyndns |
| Hostname | home.dyn.aether.earth — the FQDN to publish |
| Username | anything (ignored) |
| Password | the DDNS_TOKEN value |
| Server | ddns.aether.earth — your host, no scheme |
Two firmware gotchas, both of which the service is built to absorb:
- The path is not in your control. If your build's template posts somewhere else,
the log prints the exact path it used —
update to unregistered path path=/whatever …— andDDNS_PATH="/whatever"accommodates it. - Some templates put the credential in the username only. Accepted.
UniFi will only do DDNS at all when the WAN address is genuinely public; 10/8,
172.16/12, 192.168/16 and 100.64/10 are refused by the controller itself, so a
CGNAT or Tailscale-only uplink needs the update from somewhere else (an inadyn
instance on a box that does have the address you want published).
Configuring inadyn directly
# /etc/inadyn.conf
period = 300
ssl = yes
custom pdns-ddns {
username = gateway # ignored, present because inadyn wants one
password = <DDNS_TOKEN>
ddns-server = ddns.aether.earth
ddns-path = "/nic/update?hostname=%h&myip=%i"
hostname = home.dyn.aether.earth
}
ddns-path supports %u (username), %p (password), %h (hostname) and %i
(address). Prefer %h and %i and keep the credential in basic auth — an address
substituted into the path is fine, a password is not. No ddns-response line is
needed: good and nochg are in the generic plugin's built-in success set.
For dual stack, myip and ip6 both exist on this endpoint, so a template that can
carry both (ddns-path = "/nic/update?hostname=%h&myip=%i&ip6=%i", with allow-ipv6 = true
and an IPv6 checkip) updates A and AAAA in one request. REPLACE covers the whole
RRset each time, so an address that stops being sent is removed rather than left behind.
OctoDNS: exempt these names, or they get deleted
This is the one integration step that is not optional. In
homelab/dns the YAML in
zones/ is the entire truth for a plain zone, and just dns::dns-doit deletes
whatever it does not recognise. A record this service wrote is exactly that. Until
the exemption below is in place, the next DNS sync removes your DDNS records.
Add the NameRejectlistFilter processor that ships with OctoDNS itself to
dns/octodns.config.yaml and attach it to every zone whose names this service
writes:
processors:
# Labels written by pdns-ddns through the PowerDNS API. The yaml is not the truth for
# them, and a record the yaml does not know about is otherwise pruned as a stranger.
ddns:
class: octodns.processor.filter.NameRejectlistFilter
# Patterns are matched against record.name, which is relative to the zone: the label
# of home.dyn.aether.earth inside aether.earth. is "home.dyn", not the FQDN.
rejectlist:
- /(^|\.)dyn$/
zones:
aether.earth.:
sources:
- config
- stalwart
processors:
- ddns # anywhere in the list; it removes records, it does not rewrite them
- meta
- spf
- acme
- periods
targets:
- pdns
Leave include_target at its default of true. The filter drops the label from the
desired zone and from the existing target zone, so it is invisible to the comparison
and no delete is planned. Setting it to false would leave the record visible on the
target side only, which is precisely the delete you are trying to avoid.
Two more things worth doing while you are there:
- Keep a DDNS label out of the YAML. A record that appears in
zones/*.yamland is also written by this service will be corrected back to the YAML value on the next sync. Give DDNS its own slice of the namespace (*.dyn.<zone>) and never hand-write a record there. - Set a low TTL for those names. Since they are not in the YAML,
DDNS_TTLis the only thing setting it — and it applies on write, so pick it once and leave it. 300 is a sane default for a home WAN address.
Verify before trusting it: write a record through the API, run just dns::dns (plan
only, no --doit), and confirm the plan contains no delete for that label.
If a processor standing between you and a pruning bug is not to your taste, the
alternative is a real delegation: create dyn.aether.earth as its own PowerDNS zone
that is not in domains.list / octodns.config.yaml, and put one NS record for it
in the parent. OctoDNS then cannot see inside it at all, and DDNS_ZONES becomes
dyn.aether.earth.
PowerDNS side of the house
PDNS_API_KEY is the PowerDNS superkey (api-config), which can rewrite any zone
on the master. This service only ever sends one PATCH shape, but the key does not
know that, so:
- Keep the API on a address only the service can reach — the master's Tailscale IP with the API bound there, or a firewall rule. It should not be reachable from a laptop.
- Make
DDNS_TOKENlong. It, not the PowerDNS key, is the credential a WAN-facing endpoint authenticates with. 32+ hex characters fromopenssl rand -hex 24. - Keep
DDNS_ZONESas narrow as the use case allows — one delegated subzone is the right answer, not every domain on the box. - The master handles the serial and the
NOTIFY; nothing here needs to poke at secondaries. Writes go to the master, never a secondary (a secondary answers401/422to API writes, and in a hidden-master layout it is not the source of truth anyway).
Deploying
The binary is CGO_ENABLED=0, so it runs on a scratch container, a router, or a
Debian box with nothing installed. Static, so the pre-AVX2 workers in the cluster are
fine too.
The release archive is the whole download: the binary, the unit set, and this README.
Unpack it and units=systemd; from a checkout instead, go build and
units=deploy/systemd. Either way those two directories hold the same five files, and
the unit set is the recommended starting point rather than something to trim later:
| File | Install as |
|---|---|
pdns-ddns.service |
/etc/systemd/system/pdns-ddns.service |
pdns-ddns.service.d/60-ip-access-list.conf |
optional drop-in, read the header first |
pdns-ddns.socket |
optional — socket activation |
pdns-ddns.socket.d/60-ip-access-list.conf |
the ingress half, only with the socket unit |
pdns-ddns.env.example |
/etc/pdns-ddns/env, mode 0600 — non-secret settings only |
# from the release archive
tar xzf pdns-ddns-v0.1.0-linux-amd64.tar.gz && cd pdns-ddns-v0.1.0-linux-amd64
install -m 0755 pdns-ddns /usr/local/bin/pdns-ddns
units=systemd
# from a checkout instead
# go build -trimpath -ldflags "-s -w" -o /usr/local/bin/pdns-ddns ./cmd/pdns-ddns
# units=deploy/systemd
install -d -m 0755 /etc/pdns-ddns /etc/credstore
$EDITOR /etc/pdns-ddns/env
printf '%s' "$DDNS_TOKEN" > /etc/credstore/pdns-ddns.ddns_token
printf '%s' "$PDNS_API_KEY" > /etc/credstore/pdns-ddns.pdns_api_key
chmod 600 /etc/credstore/pdns-ddns.*
install -m 0644 "$units"/pdns-ddns.service /etc/systemd/system/
systemd-analyze verify /etc/systemd/system/pdns-ddns.service # must say nothing
systemctl daemon-reload && systemctl enable --now pdns-ddns
systemd-analyze security pdns-ddns.service
journalctl -u pdns-ddns -b # the sources it read secrets from are in the first line
systemctl enable --now pdns-ddns is the self-bound deployment. To go socket-activated
instead, systemctl enable pdns-ddns.socket and then systemctl restart pdns-ddns.service
— and see socket activation for why the word restart there is doing
work.
Secrets: three places, in this order
| Source | How you set it | Why it ranks here |
|---|---|---|
| Explicit file | DDNS_TOKEN_PATH, PDNS_API_KEY_PATH |
You said exactly where; wins over everything. |
| systemd credential | LoadCredential=ddns_token:…, pdns_api_key:… |
Non-swappable memory, readable only by the service user, not inherited by children, released when the unit stops. |
| Environment | DDNS_TOKEN, PDNS_API_KEY |
Works everywhere, and is the weakest: it sits in the process environment for the life of the unit, visible to any child process and to whoever can read /proc/<pid>/environ. |
pdns-ddns -check prints which source won for each secret, and never a value. A file named
by a *_PATH variable that the group or the world can read logs a warning with the
chmod 600 fix rather than refusing to start — a DNS outage is a worse outcome than a mode
bit, but the warning is the point of it. Credentials are judged on the world bit only,
because 0440 is what systemd gives them: under DynamicUser= the group bit is how a
non-root service reads the file at all. So leave $CREDENTIALS_DIRECTORY alone — chmod 600
there takes the group bit away, the secret goes unreadable, and the unit fails to start.
On a machine with a TPM2, keep them encrypted at rest:
printf '%s' "$DDNS_TOKEN" | systemd-creds encrypt --name=ddns_token - \
/etc/credstore.encrypted/pdns-ddns.ddns_token.cred
then switch the two LoadCredential= lines to LoadCredentialEncrypted=.
What the unit actually does
Verified on systemd 262: systemd-analyze verify is silent and
systemd-analyze security scores it 1.0 (OK). The whole test suite and a live
update cycle were both run inside the identical SystemCallFilter/namespace set, so
the policy is not aspirational — the service provably works under it, and peaks at
about 10M against the 96M cap.
The parts worth knowing about, rather than skimming past:
DynamicUser=+PrivateUsers=— a uid from the 60000 pool per start, nothing on disk owned by it, no persistent user to compromise.SystemCallFilter=@system-serviceplus a blacklist, withSystemCallErrorNumber=EPERMso one unexpected syscall degrades into a logged failure instead of a SIGSYS-killed process.RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX— the AF_UNIX is for exactly one thing: sd_notify's socket. Drop it and the unit never starts, becauseType=notifywaits forever for aREADY=1that cannot be sent. The rest is as tight as it gets:CGO_ENABLED=0means no NSS and no nscd socket, and there is no AF_PACKET.LimitCORE=0— a core dump of this process would contain both secrets in plaintext. (RestrictCoreDump=andDumpEnable=do not exist insystemd.exec, whatever a blog post told you; this is the knob.)MemoryDenyWriteExecute=— safe because Go has no JIT. Re-test it the day anyone adds cgo.ExecStartPre=… -checkfails the start on a bad config or an unreachable PowerDNS. Prefix it with-if a PowerDNS outage at boot should not block startup.ExecDigest=(systemd ≥ 254) pins the binary's SHA-256 so a swapped binary does not execute at all. Uncomment it and pastesha256sum.Type=notify+WatchdogSec=60s— see "Notifying systemd". The durations form one ladder and have to stay in order: the 10s drain inside the binary, thenTimeoutStopSec=15s, thenWatchdogSec=60s.- The five findings the auditor still reports are all inherent or backwards:
PrivateNetwork=,AF_INETandRootImage=are what being a network service means;char-rtc:rappears becauseProtectClock=yesdenies hardware-clock writes; and the non-localhostIPAddressAllow=entry is the PowerDNS master. - There is no kernel LSM underneath, and no unit can add one. Arch ships no
AppArmor (no kernel support, no
apparmoruserspace) and its systemd is built-SELINUX, soAppArmorProfile=andSELinuxContext=have nothing to attach to and the sandbox above is the access-control layer. Which is the argument for the two controls that still exist outside the namespace set:ExecDigest=to pin the binary, and the IP access list to bound what a hijacked process can reach.
Notifying systemd
The service speaks sd_notify, so systemd knows three things it would otherwise guess.
-
READY=1once the listeners are bound and answering, not atfork(). WithType=notifythat is the momentsystemctl startreports success — which is why anExecStart=that cannot exec, or aDDNS_LISTENalready in use, is now a failed start rather than an active unit that serves nothing. -
STATUS=…, sosystemctl status pdns-ddnsshows the last update attempt instead of nothing:Status: "2026-11-15T15:20:14-07:00 noauth home.example.net from 127.0.0.1"Refused attempts are reported too, which is the point: a gateway sending the wrong token looks entirely healthy from the replies alone until
badauthis all you can see. No secret is in the line — the token is in anAuthorizationheader, and the handler never puts one in what it reports. -
WATCHDOG=1at halfWatchdogSec=, and only while a listener is serving. If the main loop wedges, or every listener disappears, the pings stop; systemd then sendsWatchdogSignal=(SIGABRT by default), marks the unitresult 'watchdog', andRestart=on-failurebrings it back.
Verified on systemd 262 rather than assumed: a frozen process was killed with
Watchdog timeout (limit 10s)! after surviving 27s of a 10s timeout, the datagrams were
captured on a socket (READY=1, WATCHDOG=1 at half the interval, STATUS= after an
update, STOPPING=1 on SIGTERM with no ping after it), and with AF_UNIX removed from
RestrictAddressFamilies= the start times out with
socket: address family not supported by protocol in the journal.
Two ways this bites:
ProtectHome=yesbreaks notify in a user unit. The user manager's notify socket lives at/run/user/$UID/systemd/notify, andProtectHome=masks/run/user/. The system instance is unaffected — its socket is/run/systemd/notify— so the shipped unit is fine, but a copy pasted into~/.config/systemd/user/needsProtectHome=noor it waits forTimeoutStartSec=and then fails.WatchdogSec=0turns it off, per-drop-in, without touching the binary. Nothing is sent unless systemd asks ($WATCHDOG_USEC), so there is no cost to leave on.
Socket activation
pdns-ddns.socket is the optional half of the deployment: systemd binds the port and
hands the descriptor to the service, instead of the service binding it.
# $units is systemd/ from the release archive, deploy/systemd/ from a checkout
install -m 0644 "$units"/pdns-ddns.socket /etc/systemd/system/
install -d -m 0755 /etc/systemd/system/pdns-ddns.socket.d
install -m 0644 "$units"/pdns-ddns.socket.d/60-ip-access-list.conf \
/etc/systemd/system/pdns-ddns.socket.d/
systemd-analyze verify /etc/systemd/system/pdns-ddns.socket # must say nothing
systemctl daemon-reload
systemctl enable pdns-ddns.socket
systemctl restart pdns-ddns.service # restart, not start: while a self-bound instance
# is up, systemd refuses the socket outright
systemctl status pdns-ddns.socket # "Listening on 127.0.0.1:8053"
ss -ltnp 'sport = :8053' # held by systemd, not by pdns-ddns
journalctl -u pdns-ddns -b # listen_ignored=true, sockets=tcp://127.0.0.1:8053
What it is worth — measured on systemd 262, not asserted:
- An update arriving during a restart is not lost.
ss -ltenreports the same socket inode acrosssystemctl restart pdns-ddns.service: systemd keeps its own copy of the socket and hands that one over each time. Stop the service and the port stays listening, so a connection completes into the accept queue — and that pending connection is itself what starts the service again. Self-bound, the same window ends inECONNREFUSEDand the gateway's retry policy decides how long the record stays stale. - The bind happens outside the sandbox: handed a descriptor, the service performs no
bind()orlisten()at all. That is what letsSocketBindDeny=be set without breaking it, and what lets the endpoint sit on a privileged port withoutCAP_NET_BIND_SERVICE— the "socket-activated front end" the service unit tells you to use for:443is this file. - On a host that never receives an update, the binary never runs.
The service carries Wants=/After= on the socket unit, and that ordering is load-bearing
rather than tidy: a service that starts while its socket is not yet listening binds
DDNS_LISTEN itself, and systemd then refuses to bring the socket unit up at all
(Socket service pdns-ddns.service already active, refusing.). With the two lines in place,
enabling either unit produces the same arrangement. With no socket unit installed they are
silent no-ops, which is what keeps the service-only deployment working.
Two behaviours worth knowing before you debug it:
- The binary reads
$LISTEN_PID/$LISTEN_FDSitself (go-systemd'sactivation) and refuses to start on a hand-off it cannot make sense of — a descriptor that is not a TCP socket, a count above 64 — instead of falling back ontoDDNS_LISTEN. The fallback would be binding every interface, quietly. -checksays nothing about activation:ExecStartPre=is not the main process, and systemd passes descriptors to the main process only. Thelisteningline is what reports it.
IPAccounting= does not propagate between the two units, and traffic on the listening
socket is counted to the socket unit and never to the service — which is why both units set
it.
And the part to confirm on your own host: under socket activation the IP access list belongs
on both units. systemd.resource-control(5) says the socket unit's list governs the
sockets associated with it, and that the service's list does not touch sockets passed in via
activation — which is what makes "any client in, master only out" expressible at all: the
socket unit gets the ingress side, the service the egress side. What it does not say is
which list covers the sockets accept() creates inside the service, and systemd's own
advice in that paragraph is to replicate the lists, so treat the split as documented
behaviour and confirm it with the commands in
pdns-ddns.socket.d/60-ip-access-list.conf. A --user instance confirms nothing about any
of it: the cgroup-BPF features — IPAddressAllow=/IPAddressDeny= and SocketBindDeny= —
are not enforced in user units at all (measured on systemd 262, where IPAddressDeny=any
let a refused address straight through).
The IP access list is bidirectional — read before enabling it
IPAddressDeny=any does not mean "no egress". A packet matches when it is sent to
or received from an address in the list, and systemd cannot distinguish direction.
So inside one unit you cannot say "any client may reach me, but I may only call
PowerDNS", which is the first thing you would want:
- Behind a local TLS proxy (nginx, haproxy,
tailscale serve): setDDNS_LISTEN=127.0.0.1:8053, install the drop-in, and allow loopback plus the master's/32. This is the intended deployment. - Reached directly by the gateway: leave the drop-in uninstalled. The client's source address is precisely the thing that changes — that is what DDNS is for — so no allowlist can name it. Filter at the network boundary instead.
- Socket-activated: the split becomes expressible, because the two units each get a list — the socket unit's covers who may connect, the service's covers what it may call. That is what both drop-ins are for; read the socket one's header before installing it.
A hostname in PDNS_URL costs an extra allowance either way: with CGO_ENABLED=0 the
binary resolves it itself, over UDP and TCP 53, so a list naming only the master's /32
blocks the lookup as well as the query.
If you enable it and the service goes quiet, the filter is the reason:
journalctl -u pdns-ddns -b before anything else.
TLS
The service speaks plain HTTP; terminate TLS in front of it and bind it to loopback.
tailscale serve --bg http://127.0.0.1:8053 is the shortest path if the gateway can
reach you over the tailnet. Set DDNS_TRUST_PROXY=true only when a proxy in front sets
X-Forwarded-For — otherwise a client picks the address it wants published. Behind a reverse proxy has the nginx version.
Behind a reverse proxy
Share the HTTPS port you already have instead of exposing another one: the service stays plain HTTP on loopback and nginx carries the certificate.
# inside the https server block for aether.earth
location = /dyndns { return 301 /dyndns/; } # /dyndns is what people type
location /dyndns/ {
proxy_pass http://127.0.0.1:8053/; # the trailing slash is the whole trick
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# /etc/pdns-ddns/env
DDNS_LISTEN=127.0.0.1:8053
DDNS_TRUST_PROXY=yes # the proxy sets X-Real-IP, and it is a proxy you control
The gateway's DDNS URL is then https://aether.earth/dyndns/nic/update?hostname=<host>&myip=<wanip>.
Leave myip in even though the service can infer an address: the firmware knows its own WAN
address, and a request that states it needs nothing from the proxy.
Measured against nginx 1.30.6 with exactly these blocks, not reasoned about:
- The trailing slash on
proxy_passis the whole configuration. With it,/dyndnsis stripped and the service answers at/nic/updateas it always has. Without it the service receives/dyndns/nic/update, repliesnotfqdn, and logsupdate to unregistered path path=/dyndns/nic/update— read that line before changing anything else, it says which of the two you are running. location = /dyndns { return 301 /dyndns/; }is not decoration:location /dyndns/does not match/dyndns, so the URL people naturally type 404s at nginx.- The loopback bind is the access control. nginx 404s anything outside
/dyndns/, but a service whose prefix has been stripped cannot tell a proxied request from a direct one —curl http://127.0.0.1:8053/nic/updatebehaves identically. KeepingDDNS_LISTENon127.0.0.1is what makes the proxy the only way in. - nginx's
access_logis the path record now. A typo'd/dyndns/nic/updatreaches the journal aspath=/nic/updat, because the prefix was gone before we saw it. The access log still holds the real URL; leave it on for this location. - With
DDNS_TRUST_PROXY=yesand the headers above, an update that sends nomyippublishes the address the proxy named (X-Forwarded-For: 203.0.113.77→addresses=203.0.113.77, measured). With it off the same request is refused instead — see below. - If nginx lives on another host,
DDNS_TRUST_PROXY=yesis not optional. The refusal below catches a same-host proxy (127.0.0.1, too obviously wrong to publish). A remote proxy's address looks like a perfectly ordinary WAN address, so with the setting off an update that omitsmyippublishes the proxy. Or keep the setting off and make every client sendmyip— UniFi and inadyn both do.
Why an inferred loopback is refused. When nothing is sent in myip, the address used is
the request's own — which behind a proxy is the proxy's. Publishing 127.0.0.1 as a WAN
record is a failure nobody notices until someone needs the name, so an address the service
inferred for itself is refused with badagent/400 when it is loopback, unspecified,
link-local or multicast, and the journal names both ways out: send myip=, or set
X-Real-IP and DDNS_TRUST_PROXY=yes. An explicit myip=127.0.0.1 still publishes; a
request that names an address means it, and that is how LAN testing works.
Development
just test # go test ./...
just cover # coverage summary
just lint # gofmt, vet, golangci-lint, editorconfig-checker, typos, reuse
just run # build and run, reading .env
just dist # reproducible archives in dist/
internal/ddns holds everything: zone.go (allowlist and name validation),
pdns.go (the PowerDNS client), handler.go (the protocol), config.go (the
environment), activation.go (the socket-activation hand-off), notify.go (the
sd_notify half). cmd/pdns-ddns/main.go is wiring only. The tests run the whole HTTP
surface against fake_pdns_test.go, a stand-in PowerDNS that records the PATCHes it
received, so the assertions are about the PATCH body. Descriptor passing gets the same
hand-off as systemd's: activation_test.go re-execs the test binary with listeners in
ExtraFiles, which is how fds land at 3 and up. The sd_notify wire format goes to a
recorder, and the two claims only a real systemd can settle — that the watchdog kills a
stalled process, that READY=1 gates the start — are measured and written up in
"Notifying systemd".
CI is Crow CI via .crow/: lint runs format, vet,
tests with -race, golangci-lint, editorconfig-checker, typos and reuse lint;
release builds dist/ and publishes it to the Forgejo release for the tag
(scripts/build-dist.sh, scripts/upload-release.sh). Each archive is the whole
deployment: pdns-ddns, the systemd/ unit set copied from deploy/systemd/,
README.md, CHANGELOG.md, and the license text of everything linked in —
AGPL-3.0-or-later for this code, Apache-2.0 for go-systemd, BSD-3-Clause plus the
patent grant for golang.org/x/sys.
git tag v0.1.0 && git push origin v0.1.0 # → release with linux/amd64 + arm64 assets
References
- inadyn and
inadyn.conf(5)— thecustom {}provider and its%specifiers - PowerDNS HTTP API — the
PATCH …/rrsetsshape - UniFi Gateway – Dynamic DNS — the provider list and the Server field
- OctoDNS processors —
NameRejectlistFilter, the exemption above homelab/dns— the OctoDNS setup that owns everything else in these zonessystemd.socket(5)—ListenStream=,Accept=, and the trigger/polling limits that apply toAccept=nosd_listen_fds(3)— the$LISTEN_PID/$LISTEN_FDSprotocol, and why you must notshutdown(2)a socket the manager still holdssystemd.resource-control(5)—IPAddressAllow=/IPAddressDeny=, including the socket-unit/service-unit split