On this page
- Why would a server with a static IP run dynamic DNS?
- How do you allow signed updates on the DNS server?
- How do you install nsupdate on the updating server?
- How do you send and verify an update by hand?
- How does the server learn the home address?
- How do you run the update on a schedule?
- Where does ddclient fit in?
- Can you build simple DNS failover the same way?
- Questions
Why would a server with a static IP run dynamic DNS?
Because the records it updates are not its own. Every BitcoinVPS server keeps the same dedicated IPv4 and IPv6 address for its whole life, so the A and AAAA records for the server itself are set once, as shown in the DNS records tutorial. Dynamic updates matter for addresses that do move:
- A home or office line whose public address changes when the router reconnects. The VPS can see that address (for example as the endpoint of a WireGuard peer) and keep
home.example.netcurrent. - Simple failover, where a health check on the VPS moves
www.example.netfrom a main host to a standby when the main host stops answering. - Hosting your own dynamic DNS service, so home routers and small devices update names in a zone you control.
All three need a zone that accepts authenticated updates. This guide uses the standard RFC 2136 update protocol with TSIG keys, which BIND and other authoritative servers support. Many DNS providers offer an HTTP update API instead; the same scripts work if you replace the nsupdate call with the request their documentation describes.
How do you allow signed updates on the DNS server?
On the authoritative server (set up as in the BIND guide), create a TSIG key and give it permission to change exactly one name. On Ubuntu and Debian:
sudo tsig-keygen -a hmac-sha256 ddns-home | sudo tee /etc/bind/ddns-home.key
sudo chown root:bind /etc/bind/ddns-home.key
sudo chmod 640 /etc/bind/ddns-home.keyInclude the key and replace any allow-update line in the zone with a narrow policy in /etc/bind/named.conf.local:
include "/etc/bind/ddns-home.key";
zone "example.net" {
type primary;
file "/var/lib/bind/db.example.net";
update-policy {
grant ddns-home name home.example.net. A AAAA;
};
};The zone file must live where the server can write, because BIND keeps a journal next to it; on Debian and Ubuntu that is /var/lib/bind. On Rocky and Alma, the paths are /etc/named.conf, /var/named/dynamic/ and the group named. Check and reload:
sudo named-checkconf
sudo rndc reloadHow do you install nsupdate on the updating server?
nsupdate comes with the BIND client utilities. On Ubuntu and Debian:
sudo apt update
sudo apt install -y bind9-dnsutils
nsupdate -VOn Rocky Linux 9 and AlmaLinux 9:
sudo dnf install -y bind-utils
nsupdate -VCopy the key file from the DNS server to the updating server (they can be the same machine) and lock it down, because anyone holding it can change that record:
sudo install -d -m 700 /etc/ddns
sudo install -m 600 ddns-home.key /etc/ddns/ddns-home.keyTSIG signatures carry a timestamp and are rejected when the clocks differ by more than five minutes, so make sure both machines sync time; the time sync guide covers chrony and timesyncd.
How do you send and verify an update by hand?
Feed nsupdate a short script: choose the server and zone, delete the old record, add the new one with a low TTL and send.
sudo nsupdate -k /etc/ddns/ddns-home.key <<'EOF'
server ns1.example.net
zone example.net
update delete home.example.net. A
update add home.example.net. 60 A 203.0.113.50
send
EOFNo output means success. Ask the authoritative server directly, so no cache gets in the way:
dig @ns1.example.net home.example.net A +shortThe answer should be the new address. A REFUSED error means the policy does not grant that name or type, NOTAUTH or BADKEY points at the key name or secret, and BADTIME means clock drift. The dig guide explains how to check what resolvers elsewhere see.
How does the server learn the home address?
If the home router or a small machine at home keeps a WireGuard tunnel to the VPS, the server already knows the current home address: it is the endpoint of that peer. A small script reads it, compares it with DNS and updates only on change. Save it as /usr/local/bin/ddns-home:
#!/bin/sh
set -eu
KEY=/etc/ddns/ddns-home.key
NAME=home.example.net.
PEER=PASTE_HOME_PEER_PUBLIC_KEY
NOW=$(wg show wg0 endpoints | awk -v p="$PEER" '$1 == p {print $2}' | sed 's/:[0-9]*$//')
case "$NOW" in ""|*[!0-9.]*) exit 0;; esac
OLD=$(dig @ns1.example.net "$NAME" A +short)
[ "$NOW" = "$OLD" ] && exit 0
nsupdate -k "$KEY" <<EOF
server ns1.example.net
zone example.net
update delete $NAME A
update add $NAME 60 A $NOW
send
EOF
logger -t ddns-home "home.example.net now $NOW"The case line skips empty or non IPv4 values, such as a peer that has not connected yet. Make it executable with sudo chmod 755 /usr/local/bin/ddns-home and run it once by hand. The WireGuard server guide shows how to set up the tunnel itself.
How do you run the update on a schedule?
A systemd timer is easy to inspect and logs to the journal. Create /etc/systemd/system/ddns-home.service:
[Unit]
Description=Update home.example.net from WireGuard endpoint
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/ddns-homeAnd /etc/systemd/system/ddns-home.timer:
[Unit]
Description=Run ddns-home every two minutes
[Timer]
OnBootSec=1min
OnUnitActiveSec=2min
[Install]
WantedBy=timers.targetEnable it and look at the result:
sudo systemctl daemon-reload
sudo systemctl enable --now ddns-home.timer
systemctl list-timers ddns-home.timer
journalctl -t ddns-home -n 20The systemd guide explains units and timers in more depth.
Where does ddclient fit in?
ddclient is the classic dynamic DNS client: it detects the current address, remembers the last one it sent and retries on failure. It runs on the machine whose address changes, so in this setup it belongs on a home machine, while the VPS supplies two things it needs: an address echo endpoint and the zone that accepts updates. On the VPS, add a location to an existing nginx server block that simply returns the caller's address:
location = /ip {
default_type text/plain;
return 200 "$remote_addr\n";
}On the home machine, install ddclient (sudo apt install ddclient, or from EPEL with sudo dnf install ddclient) and check its version with apt policy ddclient or rpm -q ddclient. Release 3.11 and newer use separate IPv4 and IPv6 settings; a minimal /etc/ddclient.conf for the nsupdate method looks like this:
daemon=300
usev4=webv4, webv4=https://app.example.net/ip
protocol=nsupdate
server=ns1.example.net
login=/usr/bin/nsupdate
password=/etc/ddclient/ddns-home.key
zone=example.net
ttl=60
home.example.netOlder 3.10 releases use use=web, web=https://app.example.net/ip instead of the usev4 line. Test once in the foreground with sudo ddclient -daemon=0 -debug -verbose -noquiet, then sudo systemctl enable --now ddclient.
Can you build simple DNS failover the same way?
Yes, with clear limits. A timer on the VPS checks the main host with curl and, after several failures in a row, rewrites the record to the standby address. Grant the key the name you switch, for example grant ddns-fo name www.example.net. A;, and keep the TTL at 60 seconds. The core of the check:
if ! curl -sf --max-time 5 -o /dev/null --resolve www.example.net:443:198.51.100.24 https://www.example.net/health; then
echo "main host failed" | logger -t ddns-fo
fiCount failures in a state file so one slow answer does not flip the record, and switch back by hand after you have checked the main host. Resolvers and browsers may keep the old address for a while after the change, so expect a minute or more of disruption, not an instant cut over. For the health check itself, the curl guide shows more options.
Questions about Dynamic DNS updates from a server
Do I need dynamic DNS for my VPS address?
No. The server keeps its dedicated IPv4 and IPv6 for as long as it exists, so normal static A and AAAA records are right for it.
Why is the record not changing for other people right away?
Resolvers cache answers for the TTL that was set before the change. Lower the TTL to 60 seconds well before you rely on fast updates, and query the authoritative server with dig @ns1.example.net to see the real state.
Can I update AAAA records too?
Yes. Grant AAAA in the policy and add update add home.example.net. 60 AAAA 2001:db8:4f2a::50 lines. Many home lines change their IPv6 prefix as well, so update both records together.
Is TSIG safe over the internet?
TSIG signs the update so nobody can forge or alter it, but it does not encrypt it. The content of a DNS record is public anyway, so that is usually fine. Keep the key file private.
What if my DNS provider has its own API?
Keep the detection and comparison parts of the script and replace the nsupdate block with the provider's documented HTTP call, usually a curl request with an API token in a header.
More in Networking and diagnostics
- FreeRADIUS with PostgreSQL
- IPv6 on your server
- The ip command
- DNS lookups with dig
- Listening ports with ss and netstat
- Test ports and transfer data with netcat
- Trace network paths with mtr
- Capture packets with tcpdump
- Live bandwidth with iftop and nethogs
- HTTP requests with curl
- Latency graphs with SmokePing
- Traffic analysis with ntopng
- Check which ports are reachable