Running NSD as an Authoritative Nameserver with Zone Transfer to a Secondary

A single authoritative DNS server is a single point of failure for every player trying to resolve the game lobby hostname. If the node’s resolver process dies or the machine is rebooting after a kernel update, clients get SERVFAIL and the launcher shows a connection error that looks like an outage. Running two nameservers is not optional for anything public, and NSD is a good fit because it is small, memory-safe and answers purely from zone files.

The interesting part is keeping the secondary in sync. NSD does not do AXFR by default for a primary it serves, and the transfer must be gated on the right address, authenticated where possible, and monitored so the secondary’s serial expires before anyone notices. This is the whole configuration.

Installing and defining the primary zone

Install NSD from the distribution package, then create a zone file under /etc/nsd/zones/. The only fields that must be exactly right for transfer are the SOA serial, the MNAME, and the NS records for both servers. Keep the serial in a numeric form you increment deliberately rather than a date-based value you might repeat.

$TTL 3600
@   IN SOA ns1.example.net. hostmaster.example.net. (
        2026110401 ; serial
        7200       ; refresh
        900        ; retry
        1209600    ; expire
        300 )      ; minimum
@       IN NS  ns1.example.net.
@       IN NS  ns2.example.net.
@       IN A   203.0.113.10
ns1     IN A   203.0.113.10
ns2     IN A   198.51.100.20
lobby   IN A   203.0.113.10
world   IN A   203.0.113.11
api     IN A   203.0.113.12

nsd.conf for the primary

The primary needs to allow transfers from the secondary’s exact address only. Use a network prefix if you run several secondaries in the same range, and never open transfers to the world — an open AXFR is a free zone dump for anyone who asks. The provide-xfr option takes a source prefix and an optional TSIG key name.

server:
    ip-address: 203.0.113.10
    port: 53
    hide-version: yes
    verbosity: 1

remote-control:
    control-enable: yes

key:
    name: xfr-key
    algorithm: hmac-sha256
    secret: "BASE64SECRETREPLACEME"

zone:
    name: example.net
    zonefile: "/etc/nsd/zones/example.net.zone"
    provide-xfr: 198.51.100.20 xfr-key
    notify: 198.51.100.20 xfr-key

Configuring the secondary

The secondary does not need a zone file at all; NSD writes its own copy, stores it in the configured database directory and treats it as read-only. The critical settings are the primary address and the request-xfr line, which must name the same key. If the key name mismatches, the secondary silently retries every retry interval and logs a reset.

zone:
    name: example.net
    zonefile: "/var/lib/nsd/example.net.zone"
    allow-notify: 203.0.113.10 xfr-key
    request-xfr: AXFR 203.0.113.10 xfr-key

acl:
    name: allow-transfer
    action: deny
    nokey: xfr-key

Reload with nsd-control reload and check nsd-checkzone output first. A syntax error loads on the primary and fails on the secondary, leaving two servers with different answers — the worst state during an incident.

Timers that decide how long a stale zone survives

The SOA timer set is the real availability design. Refresh is how often the secondary polls; retry is how soon it tries again after a failure; expire is how long it keeps serving data after it can no longer reach the primary. A zone with a 12-hour expire will serve stale records for half a day after the primary dies, which is usually too long for a game service with rotating endpoints.

TimerSmall zone (game lobby)Large or change-heavy zoneWhat it controls
Refresh600 s1800 sPoll frequency
Retry120 s300 sBackoff after failure
Expire86400 s604800 sStale serving window
Minimum300 s3600 sNegative caching

Verifying that transfer actually happened

Do not assume. Ask the secondary directly, bypassing the recursive resolver on your workstation, and compare the serial it answers with the primary. Both should return the same SOA serial for the zone, and the answer must come from the secondary’s own address.

dig @203.0.113.10 example.net SOA +short
dig @198.51.100.20 example.net SOA +short
dig @198.51.100.20 lobby.example.net A +short
nsd-control zone-status

A mismatch means the secondary has not transferred. Check nsd-control zone-status for the last transfer time, then verify the key material and the source address seen by the primary. Address translation in front of the secondary is the most common cause of a silent failure — the primary sees a NAT address and rejects the transfer.

Publishing both servers at the registrar

Both NS records must be in the delegation at the registrar, and both addresses should be reachable from the public internet on UDP and TCP 53. A secondary in the same rack as the primary survives a process crash but not a power event, so place it in a different facility. If you keep everything on one provider, at minimum use a different subnet and a different power feed.

Serve the game infrastructure on dedicated nodes in separate racks and the DNS secondaries follow naturally from that topology. One node answering DNS in-region and one out-of-region also gives you a crude latency benefit for large player populations.

Monitoring, NOTIFY and rollback

Alert when the serial difference between primary and secondary exceeds zero for more than 15 minutes, and alert when nsd-control zone-status reports an expired zone. NOTIFY makes propagation near-instant, but it is UDP and unacknowledged, so the refresh timer is your safety net. Test NOTIFY by bumping the serial and watching the secondary log the transfer within the refresh window.

Keep the previous zone file version on both hosts and know the rollback command. If a bad change publishes, restoring the prior file and incrementing the serial is faster than debugging with players offline. See the secondaries in a separate facility for the topology that survives a rack failure.

Leave a Reply