Using DNS Well
A checklist, and the misconfigurations to avoid.
Given a domain: what it should have, and what goes wrong.
A setup checklist
Six things, each demonstrated earlier:
| # | Has | Chapter |
|---|---|---|
| 1 | NS records matching the registrar’s delegation |
2 |
| 2 | An A or AAAA at the apex |
3 |
| 3 | MX records, or a null MX if it sends no mail |
3 |
| 4 | SPF, DKIM and DMARC as TXT |
3 |
| 5 | A CAA record naming your certificate authority |
3 |
| 6 | TTLs that match how often you change things | 5 |
Auditing a domain
Five lookups answer most of it:
d=github.com
printf 'NS '; dig +short NS $d | sort | head -1
printf 'MX '; dig +short MX $d | sort -n | head -1
printf 'DMARC '; dig +short TXT _dmarc.$d | grep -oE 'p=[a-z]+' | head -1
printf 'CAA '; dig +short CAA $d | sort | head -1The sixth check is whether the zone is signed — a DS at the parent, chapter 4. Most
large domains have none:
for d in github.com google.com cloudflare.com; do
printf '%-18s ' $d
n=$(dig +short DS $d | wc -l | tr -d ' ')
[ "$n" -gt 0 ] && echo signed || echo unsigned
doneTTL strategy
| Record | TTL | Because |
|---|---|---|
A you may move |
300 | changes settle in five minutes |
A that is stable |
3600 | the usual default |
MX |
86400 | mail routing rarely changes |
NS |
86400 | and the parent’s TTL governs anyway |
| Anything about to change | 300, set days early | chapter 5 |
Read a zone’s own choices from its authoritative server:
for t in A MX NS; do
printf '%-4s ' $t
dig @elliott.ns.cloudflare.com +noall +answer $t example.com \
| awk '{print $2}' | head -1
doneThe number only helps if it was published before the change. Lowering a TTL and changing the record together does nothing.
Records that are not addresses
Most TXT records in a real zone have nothing to do with addressing:
dig +short TXT github.com | wc -l | tr -d ' '| Record | Belongs to |
|---|---|
v=spf1 ... |
email — Email course, chapter 5 |
v=DKIM1 ... at <selector>._domainkey |
|
v=DMARC1 ... at _dmarc |
|
| An opaque string | a vendor proving you own the domain |
Verification records accumulate. Most can be deleted once the vendor has checked them, and a zone full of them is a zone nobody has audited.
Subdomain strategy
Chapter 2’s distinction, as a decision:
| Keep in the zone | Delegate | |
|---|---|---|
| Who edits it | you | the subdomain’s owner |
Needs NS records |
no | yes |
| Suits | www, api, mail |
a cluster, a team, a vendor |
Delegating gives access without giving access to everything — a cluster owning
k8s.example.com cannot touch your MX record.
Common misconfigurations
Six, each with the chapter that explains it:
| Problem | Symptom | Chapter |
|---|---|---|
CNAME at the apex |
the provider rejects it | 3 |
CNAME beside other records |
the other records vanish | 3 |
Registrar delegation ≠ zone NS |
works for some users | 2 |
| Changing a record without lowering the TTL first | a long wait | 5 |
| Trailing dot missing in a zone file | ns1.example.com.example.com. |
7 |
AXFR open to the internet |
your whole zone is public | 7 |
The third is the hardest to see, and this compares both sides:
printf 'parent '
dig @a.gtld-servers.net +noall +authority github.com 2>/dev/null \
| awk '$4=="NS"{print $5}' | sort | head -1
printf 'zone '
dig +short NS github.com | sort | head -1Where to look things up
| For | Use |
|---|---|
| What a record type means | the IANA DNS parameters registry |
| Exact syntax | the RFC — 1035 for the basics, 4034 for DNSSEC |
| Whether a zone validates | dig +dnssec and chapter 4’s +cd test |
| What a resolver sees | dig @1.1.1.1 and dig @8.8.8.8, compared |
An RFC is readable if you skip to the section you need: RFC 1035 §3.2 is the record types, and everything before it is chapter 1’s packet format.
dig answers almost every question in that table. The tool from chapter 1 is the tool
that debugs everything after it.