How to run DuckDNS on Raspberry Pi?
Here’s a clean, reliable way to run DuckDNS on a Raspberry Pi. You can use either a tiny systemd timer (my pick) or a classic cron job. Both call DuckDNS’s HTTPS update API.
0) Get your DuckDNS domain + token
-
Sign in at DuckDNS, add a subdomain, copy your token.
-
DuckDNS update API (HTTPS) accepts:
https://www.duckdns.org/update?domains=<DOMAINS>&token=<TOKEN>[&ip=][&ipv6=][&verbose=true]
Leaveip=
blank to auto-detect IPv4; addipv6=
if you want to set IPv6 explicitly.
Option A — systemd service + timer (every 5 minutes)
1) Make the updater script
Paste (edit the two variables):
Then:
2) Create a service + timer
Enable + test:
Option B — cron job (official DuckDNS method)
Create the same script (e.g., ~/duckdns/duck.sh
) that calls the DuckDNS update URL with your domains
and token
, then run it via cron every 5 minutes. The DuckDNS install page shows the Linux-cron approach and using curl
for the HTTPS update.
Example:
A Raspberry Pi–specific walk-through of the same idea (script + cron) is here if you want a reference.
Optional — Docker instead of scripts
If you’re already using Docker/Compose on the Pi, the LinuxServer.io duckdns
container will auto-update your IP. Their docs show the required environment variables (SUBDOMAINS
, TOKEN
) and a simple compose file.
IPv6 notes (if you want AAAA records updated)
DuckDNS supports setting IPv6 explicitly via &ipv6=<addr>
in the same update call. Combine that with a one-liner that extracts your Pi’s global IPv6 (see the commented line in the script above). If you omit ipv6=
, only A (IPv4) is updated; adding ipv6=
sets AAAA too.
Verify it worked
-
Run your updater once manually and look for
OK
in the output/log. -
Check your domain at
https://www.duckdns.org
—the current IP(s) should match your WAN/IPv6.
Troubleshooting
-
No updates? Manually run the script and print the URL/response (
--verbose=true
helps). API syntax reference is on DuckDNS’s spec page. -
Cron didn’t fire? Ensure the cron daemon is installed/running (see DuckDNS “linux cron” section), or just use the systemd timer above.
-
Behind CGNAT? DuckDNS still updates, but inbound ports from the internet won’t reach your Pi; use a VPN (e.g., WireGuard) or a reverse tunnel instead.
评论
发表评论