SkillPilotAI

DNS records and zones

A zone is the part of the DNS namespace one team manages through one zone file, and every line of that file is a record. Knowing what each record type does (A, AAAA, CNAME, MX, TXT, NS, SOA, SRV, CAA, PTR) and how zones are copied between servers is the base of every DNS task.

82.1 Why is it used?

  • All data of example.com lives in one zone file on its authoritative server (ns1); queries are answered from it.
  • Different record types answer different questions: where is the website, where does email go, who may issue certificates.
  • Every zone has at least two authoritative servers, so the domain keeps resolving if one goes down; zone transfer keeps them in sync.
  • Reverse DNS (PTR) lets a mail server check that an IP really belongs to the sender's domain.

82.2 Record types

RecordMapsExample (lab)
AName -> IPv4www -> 192.168.102.80
AAAAName -> IPv6www -> 2001:db8::80
CNAMEAlias -> real name (no IP of its own)shop -> www.example.com.
MXDomain -> mail server, with priority (lower tried first)10 mail, 20 mail2
TXTFree text: SPF, DKIM, domain verification"v=spf1 mx -all"
NSZone -> its authoritative serversns1, ns2
SOAZone header: primary, admin email, serial, timersns1 admin 2026110901 ...
SRVService -> priority, weight, port, host_sip._tcp 10 60 5060 sip
CAAWhich CA may issue certificates0 issue "letsencrypt.org"
PTRIP -> name (reverse DNS)25.102.168.192.in-addr.arpa -> mail

82.3 The zone file

Lab: BIND primary n082-ns1 192.168.102.53, secondary n082-ns2 192.168.102.54, client 192.168.102.100. $TTL sets the default TTL, then the SOA, then every other record.

Output
$TTL 3600@ IN SOA ns1.example.com. admin.example.com. (    2026110901 ; serial    3600 600 86400 300 )@     IN NS    ns1.example.com.@     IN NS    ns2.example.com.ns1   IN A     192.168.102.53www   IN A     192.168.102.80www   IN AAAA  2001:db8::80shop  IN CNAME www.example.com.@     IN MX    10 mail.example.com.mail  IN A     192.168.102.25@     IN TXT   "v=spf1 mx -all"_sip._tcp IN SRV 10 60 5060 sip.example.com.@     IN CAA   0 issue "letsencrypt.org"
Output
$ named-checkzone example.com /etc/bind/example.com.zonezone example.com/IN: loaded serial 2026110901OK
  • @ means the zone apex (example.com itself).
  • named-checkzone validates the file before you reload; always run it after an edit.

82.4 Querying records with dig

Terminal
dig +noall +answer www.example.com Adig +noall +answer www.example.com AAAAdig +noall +answer shop.example.com Adig +noall +answer example.com MX
Output
$ dig +noall +answer www.example.com Awww.example.com.   3600  IN  A     192.168.102.80$ dig +noall +answer www.example.com AAAAwww.example.com.   3600  IN  AAAA  2001:db8::80$ dig +noall +answer shop.example.com Ashop.example.com.  3600  IN  CNAME www.example.com.www.example.com.   3600  IN  A     192.168.102.80$ dig +noall +answer example.com MXexample.com.  3600  IN  MX  10 mail.example.com.example.com.  3600  IN  MX  20 mail2.example.com.
  • +noall +answer prints only the answer section. Each line: name, TTL, class IN, type, value.
  • Asking A for shop returns the CNAME first, then the A record of www (the server follows the alias).
Terminal
dig +noall +answer example.com TXTdig +noall +answer _sip._tcp.example.com SRVdig +noall +answer example.com CAAdig +short @8.8.8.8 google.com MXdig +short @8.8.8.8 google.com CAA
Output
$ dig +noall +answer example.com TXTexample.com.  3600  IN  TXT  "v=spf1 mx -all"$ dig +noall +answer _sip._tcp.example.com SRV_sip._tcp.example.com. 3600 IN SRV 10 60 5060 sip.example.com.$ dig +noall +answer example.com CAAexample.com.  3600  IN  CAA  0 issue "letsencrypt.org"$ dig +short @8.8.8.8 google.com MX10 smtp.google.com.$ dig +short @8.8.8.8 google.com CAA0 issue "pki.goog"
MX: how an email finds its server
  1. 1.Sender mail server -> ns1: MX? example.com

  2. 2.ns1 -> sender: 10 mail.example.com, 20 mail2.example.com

  3. 3.Sender tries the lowest number first: mail (priority 10)

  4. 4.If mail is down, the email automatically goes to mail2 (priority 20)

82.5 NS and SOA

Terminal
dig +noall +answer example.com NSdig +noall +answer +multiline example.com SOA
Output
$ dig +noall +answer example.com NSexample.com.  3600  IN  NS  ns2.example.com.example.com.  3600  IN  NS  ns1.example.com.$ dig +noall +answer +multiline example.com SOAexample.com. 3600 IN SOA ns1.example.com. admin.example.com. (        2026110901 ; serial        3600       ; refresh (1 hour)        600        ; retry (10 minutes)        86400      ; expire (1 day)        300        ; minimum (5 minutes)        )
SOA fieldMeaning
serialVersion of the zone; must go up on every change
refreshHow often the secondary checks the primary's serial
retryWait before retrying after a failed check
expireAfter this long without contact the secondary stops serving the zone
minimumNegative caching TTL: how long an NXDOMAIN stays cached

82.6 Reverse DNS (PTR) and dig -x

  • Reverse zone name: first three octets backwards + in-addr.arpa, e.g. 102.168.192.in-addr.arpa.
  • A receiving mail server asks "PTR? 25.102.168.192.in-addr.arpa"; if the name does not match the sender, many servers mark the email as spam.
Terminal
dig +noall +answer -x 192.168.102.80dig +noall +answer -x 192.168.102.25dig -x 192.168.102.99 | \  grep -E 'status|AUTHORITY'
Output
$ dig +noall +answer -x 192.168.102.8080.102.168.192.in-addr.arpa. 3600 IN PTR www.example.com.$ dig +noall +answer -x 192.168.102.2525.102.168.192.in-addr.arpa. 3600 IN PTR mail.example.com.$ dig -x 192.168.102.99 | grep -E 'status|AUTHORITY';; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 7609;; flags: qr aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1;; AUTHORITY SECTION:

82.7 Zone transfer: AXFR allowed vs denied

  • The secondary (ns2) checks the primary's SOA serial and copies the whole zone with AXFR over TCP.
  • An unknown client must not get AXFR: the full zone list is a ready map for an attacker.
  • Lock it down with allow-transfer (secondary IPs only) and TSIG keys.
Terminal
# n082-ns1 named.conf (options)allow-transfer { 192.168.102.54; };# n082-pc: clientdig @192.168.102.53 example.com AXFR# n082-ns2: secondarydig @192.168.102.53 example.com AXFR# n082-ns1: named loggrep -E 'transfer|AXFR' /tmp/named.log
Output
pc$ dig @192.168.102.53 example.com AXFR; <<>> DiG 9.18.25 <<>> @192.168.102.53 example.com AXFR;; global options: +cmd; Transfer failed.ns2$ dig @192.168.102.53 example.com AXFRexample.com. 3600 IN SOA ns1.example.com. admin.example.com. 2026110901 3600 600 86400 300example.com. 3600 IN TXT "v=spf1 mx -all"example.com. 3600 IN MX  10 mail.example.com....;; SERVER: 192.168.102.53#53(192.168.102.53) (TCP);; XFR size: 18 records (messages 1, bytes 505)ns1$ grep -E 'transfer|AXFR' /tmp/named.logclient @0x7b83cf60c230 192.168.102.54#38615 (example.com): transfer of 'example.com/IN': AXFR started (serial 2026110901)client @0x7b83cf60c230 192.168.102.54#38615 (example.com): transfer of 'example.com/IN': AXFR ended: 1 messages, 18 recordsclient @0x7b83cf5e2100 192.168.102.100#42075 (example.com): zone transfer 'example.com/AXFR/IN' denied

82.8 NOTIFY, serial and IXFR

How a change reaches the secondary
  1. 1.Admin adds api A 192.168.102.90 on ns1 and bumps serial to 2026110902

  2. 2.rndc reload example.com

  3. 3.ns1 -> ns2: NOTIFY serial 2026110902

  4. 4.ns2 sees a higher serial and requests a transfer (IXFR for changes, AXFR for all)

  5. 5.ns2 now serves the new zone (19 records)

No NOTIFY? The secondary checks by itself after the SOA refresh time

Terminal
# n082-ns1: record add, serial upgrep -E 'serial|^api' \  /etc/bind/example.com.zonerndc reload example.com# n082-ns2: secondary loggrep -E 'notify|transfer|IXFR' \  /tmp/named.log | tail -6# n082-pc: query the secondarydig +noall +answer @192.168.102.54 \  api.example.com A
Output
ns1$ grep -E 'serial|^api' /etc/bind/example.com.zone    2026110902 ; serialapi   IN A     192.168.102.90ns1$ rndc reload example.comzone reload queuedns2$ grep -E 'notify|transfer|IXFR' /tmp/named.log | tail -6client @0x710d36b6a250 192.168.102.53#50962: received notify for zone 'example.com'zone example.com/IN: notify from 192.168.102.53#50962: serial 2026110902zone example.com/IN: transferred serial 2026110902transfer of 'example.com/IN' from 192.168.102.53#53: Transfer completed: 1 messages, 19 records, 486 bytes, 0.004 secs (121500 bytes/sec) (serial 2026110902)pc$ dig +noall +answer @192.168.102.54 api.example.com Aapi.example.com.  3600  IN  A  192.168.102.90

82.9 Common mistakes

  • Editing the zone but not raising the serial: the secondary skips the transfer, so users get the new record from ns1 and the old answer from ns2.
  • Putting a CNAME at the apex (example.com): a CNAME name cannot have other records, and the apex always has SOA and NS. Use an A record or the provider's ALIAS / CNAME flattening.
  • Leaving AXFR open to everyone: anyone can dump the whole zone.
  • Forgetting PTR for a mail server IP: outgoing mail lands in spam.

82.10 Interview tips

  • Zone transfer: secondary copies the zone from the primary, whole zone with AXFR or only changes with IXFR, over TCP 53.
  • NOTIFY plus the SOA serial decide when the copy happens; refresh/retry/expire are the fallback timers.
  • Secure it: allow-transfer limited to secondary IPs, plus TSIG keys.
  • Know MX priority (lower wins), CNAME rules (alone on its name, not at apex) and SOA minimum = negative caching TTL.