A DNS zone transfer over the internet without TSIG is a public bulletin board for your zone contents. With TSIG, the transfer is signed with a shared secret — the primary proves the request came from an authorized peer, the secondary proves the response came from the right primary. This article walks the lifecycle: generate the key, distribute it, configure both ends, verify transfers and dynamic updates work, and rotate the key on a schedule.
How to verify
Before changing anything, confirm whether the existing pair signs transfers and whether the keys match. The fastest check is to do a transfer manually with dig:
dig @primary.example.com example.com AXFR -y hmac-sha256:transfer-key:BASE64SECRET
sudo grep -l "transfer-key" /etc/bind/named.conf*
sudo named-checkconf
sudo journalctl -u named -n 50 --no-pager | grep -E 'TSIG|BADSIG|BADKEY|BADTIME'
If TSIG fails, the journal tells you why: BADKEY (key name mismatch), BADSIG (secret mismatch), BADTIME (clock skew beyond the fudge window).
What’s happening
TSIG (Transaction SIGnature, RFC 8945) is a shared-secret authentication scheme for DNS messages. The two parties agree on:
- A key name (e.g.
transfer-example) — passed in the TSIG record on the wire so the receiver knows which key to use. - An algorithm (
hmac-sha256is the modern choice;hmac-md5is deprecated). - A shared secret — a random byte string base64-encoded in config.
Every TSIG-signed message includes a TSIG RR in the additional section. The TSIG RR contains:
- The key name.
- A timestamp and fudge (default 300 seconds).
- An HMAC over the entire message (request or response).
The receiver looks up the key by name, computes the HMAC, checks the timestamp is within fudge, and accepts or rejects. Any of BADKEY, BADSIG, BADTIME are returned in the response if checks fail.
TSIG is used in three places:
- Zone transfers (AXFR/IXFR) — primary signs response, secondary signs request.
- NOTIFY — primary signs the notify, secondary verifies before refreshing.
- Dynamic updates (RFC 2136) — the update client signs the update message, the primary verifies before accepting.
There is also TKEY (RFC 2930) for negotiating ephemeral keys, but in practice everyone uses a long-lived pre-shared secret.
The procedure
-
Generate a TSIG key. Use
tsig-keygen(modern BIND >= 9.10). It writes a complete key statement to stdout:tsig-keygen -a hmac-sha256 transfer-exampleOutput:
key "transfer-example" { algorithm hmac-sha256; secret "X3K1QxL4...BASE64...=="; };Save this to
/etc/bind/keys/transfer-example.key. Set strict permissions:sudo chmod 0640 /etc/bind/keys/transfer-example.key sudo chown root:bind /etc/bind/keys/transfer-example.key -
Distribute the key. The secret must reach the secondary out-of-band — not by clipboard, not by chat, not in a git repo. Use SSH, a secrets manager (Vault, AWS Secrets Manager), or a sealed-channel secret distribution tool.
-
Configure the primary. In
named.conf.local:include "/etc/bind/keys/transfer-example.key"; server 203.0.113.20 { keys { "transfer-example"; }; }; zone "example.com" { type primary; file "/etc/bind/zones/db.example.com"; allow-transfer { key "transfer-example"; }; allow-update { key "transfer-example"; }; // optional, for dynamic updates also-notify { 203.0.113.20; }; }; -
Configure the secondary. Mirror the include and the
serverclause, then reference the key in the zone:include "/etc/bind/keys/transfer-example.key"; server 203.0.113.10 { keys { "transfer-example"; }; }; zone "example.com" { type secondary; file "/var/cache/bind/db.example.com"; primaries { 203.0.113.10 key transfer-example; }; allow-notify { 203.0.113.10; }; }; -
Validate, reload, and confirm.
named-checkconfwill not catch a wrong base64 secret (the format is fine, the bytes are wrong). Reload both ends, then run a signed AXFR:sudo named-checkconf -z sudo systemctl reload named dig @203.0.113.10 example.com AXFR -y hmac-sha256:transfer-example:BASE64SECRET | tail -
Use TSIG for dynamic updates (optional). A common pattern is to update a DHCP-fed zone via
nsupdate:nsupdate -y hmac-sha256:transfer-example:BASE64SECRET << EOF server 203.0.113.10 zone example.com update delete dynhost.example.com A update add dynhost.example.com 60 A 10.0.5.50 send EOFThe primary verifies the signature against its known key and accepts or rejects.
Rotation procedure
Rotating a TSIG key without downtime requires the peer to know both old and new keys during the transition. Two strategies:
Two-key strategy:
- Generate new key
transfer-example-2. - Add it to both primary and secondary.
- Switch the
primaries { ... key transfer-example-2; }on the secondary first. - Verify transfers still work.
- Remove
transfer-examplefrom both ends.
Multi-key allow-transfer:
allow-transfer { key "transfer-example"; key "transfer-example-2"; };
Both keys are valid on the primary. The secondary uses whichever you set in primaries. Remove the old key after switching.
Run rotation quarterly at minimum. Annually is too long if the secret is shared with third parties.
Common pitfalls
- Clock skew gives BADTIME. TSIG signs with a timestamp; default fudge is 300 seconds. Hosts that drift past this fail. Always run chrony/ntpd and monitor offset.
- Pasting newlines into the secret. The base64 secret is one line. Multi-line copy/paste sometimes inserts a
\nwhich becomes invalid base64. Validate withecho "secret" | base64 -d > /dev/null. - Algorithm mismatch. Both ends must agree.
hmac-sha256on one andhmac-sha1on the other yields BADKEY because the key name is implicitly algorithm-qualified. - Key leak in git. Committing the key statement to a public repo is a security incident. Use
.gitignore, secret managers, and rotate immediately on leak. - Different keys for transfer vs notify. If
also-notifydoes not name the same key, the secondary rejects the NOTIFY with BADKEY. Use the same key for the same peer relationship across all signed channels.
In the engagements we run, TSIG is one of the easier wins — it costs nothing to enable and turns an unauthenticated zone transfer into an authenticated one. We codify the key generation, distribution, and rotation in configuration management, alert on TSIG errors in the journal, and rotate keys on a schedule that matches the broader credential rotation policy. See our managed operations service for the broader operating model.