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

  1. Sign in at DuckDNS, add a subdomain, copy your token

  2. DuckDNS update API (HTTPS) accepts:
    https://www.duckdns.org/update?domains=<DOMAINS>&token=<TOKEN>[&ip=][&ipv6=][&verbose=true]
    Leave ip= blank to auto-detect IPv4; add ipv6= if you want to set IPv6 explicitly. 


Option A — systemd service + timer (every 5 minutes)

1) Make the updater script

sudo mkdir -p /usr/local/lib/duckdns sudo nano /usr/local/lib/duckdns/update.sh

Paste (edit the two variables):

#!/usr/bin/env bash DOMAINS="yourdomain1,yourdomain2" # comma-separated, no .duckdns.org TOKEN="your-token" # Optional: detect a global IPv6 (uncomment next line if you want IPv6 set too) # IPV6_ADDR=$(ip -6 addr show scope global | awk '/inet6/{print $2; exit}' | cut -d/ -f1) URL="https://www.duckdns.org/update?domains=${DOMAINS}&token=${TOKEN}&ip=&verbose=true" # If you set IPV6_ADDR above, append: &ipv6=${IPV6_ADDR} curl -s "$URL" | logger -t duckdns

Then:

sudo chmod +x /usr/local/lib/duckdns/update.sh

2) Create a service + timer

sudo nano /etc/systemd/system/duckdns.service
[Unit] Description=DuckDNS updater [Service] Type=oneshot ExecStart=/usr/local/lib/duckdns/update.sh
sudo nano /etc/systemd/system/duckdns.timer
[Unit] Description=Run DuckDNS updater every 5 minutes [Timer] OnBootSec=30s OnUnitActiveSec=5min AccuracySec=30s Unit=duckdns.service [Install] WantedBy=timers.target

Enable + test:

sudo systemctl daemon-reload sudo systemctl enable --now duckdns.timer systemctl list-timers | grep duckdns sudo systemctl start duckdns.service && journalctl -u duckdns.service -n 20 --no-pager

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:

mkdir -p ~/duckdns nano ~/duckdns/duck.sh
#!/usr/bin/env bash echo url="https://www.duckdns.org/update?domains=yourdomain&token=your-token&ip=&verbose=true" \ | curl -s -k -o ~/duckdns/duck.log -K -
chmod 700 ~/duckdns/duck.sh (crontab -l; echo "*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1") | crontab -

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.

评论

此博客中的热门博文

How To Connect Stm32 To PC?

Detailed Explanation of STM32 HAL Library Clock System

How to add a GPS sensor to ESP32 for Wokwi?