My DNS Notes, Ep. 2 - Resource Records, Zones, and Message Format
#dns#resource-record#dns-zone#edns#networking
Contents
A resource record (RR) is the unit of data that DNS stores and answers with: one record that binds a type, a class, a TTL, and a value to a single name.
For example, the IPv4 address of shop.example.com is one RR, shop.example.com. 300 IN A 192.0.2.10. The RR is defined in the example.com zone file, and when a resolver sends a query, the authoritative server returns the same RR in the answer section of a DNS message.
RRs and the message format were defined by RFC 1034 and RFC 1035, and later documents such as RFC 2181, RFC 6891, and RFC 7766 corrected their interpretation and extended their features.
1. What Is a Resource Record?
Registering a name in DNS means adding an RR to a zone.
An RR consists of an owner name, TYPE, CLASS, TTL, and RDATA, and when it is carried in a message, an RDLENGTH field giving the length of the RDATA is placed in front of the RDATA.
| Field | Size | Meaning |
|---|---|---|
| owner name | Variable, up to 255 bytes | Name the RR belongs to |
| TYPE | 2 bytes | Record type (A=1, NS=2, CNAME=5, SOA=6, MX=15, TXT=16, AAAA=28) |
| CLASS | 2 bytes | Protocol family; IN (1) for the Internet |
| TTL | 4 bytes | Time in seconds the RR may be cached, 0 ~ 2^31-1 |
| RDLENGTH | 2 bytes | Length of the RDATA in bytes |
| RDATA | Variable | Value whose format depends on TYPE and CLASS |
An RR with a TTL of 0 is used only for the transaction in progress and is not cached.
RFC 1035 defined the TTL as a signed 32-bit integer, but RFC 2181 clarified it as an unsigned value with a maximum of 2^31-1.
A set of RRs with the same owner name, CLASS, and TYPE is called an RRset.
If shop.example.com has two A records, the two RRs form one A RRset, and a query is answered with the entire RRset.
If an RRset does not fit in a response, the response must be marked as truncated, and all RRs in an RRset must have the same TTL.
RRs are managed in units of zones.
A zone is the part of the namespace that one operator is responsible for, and the apex, the top name of the zone, must have an SOA RR and an NS RRset.
An authoritative server reads the zone data to answer queries, and queries and responses use the same DNS message format.
How zones are divided is covered in 3.5 Delegation and Glue, and the message structure in 3.7 Message Format.
2. Usage Example
The example company has registered the domain example.com and publishes the web service shop.example.com.
It runs two name servers, ns1.example.com and ns2.example.com.
ns1 is the primary server that holds the original zone data, and ns2 is the secondary server that receives copies of the zone.
2.1 Publishing Records in a Zone
The example.com zone file defines the following RRs.
CLASS is IN for all of them, so it is omitted from the table.
| owner name | TTL | TYPE | RDATA | Role |
|---|---|---|---|---|
example.com. | 3600 | SOA | ns1.example.com. hostmaster.example.com. 2026112501 7200 3600 1209600 300 | Zone version and timers |
example.com. | 3600 | NS | ns1.example.com. | Authoritative server |
example.com. | 3600 | NS | ns2.example.com. | Authoritative server |
ns1.example.com. | 3600 | A | 192.0.2.1 | Name server address |
ns2.example.com. | 3600 | A | 198.51.100.1 | Name server address |
shop.example.com. | 300 | A | 192.0.2.10 | Web server IPv4 address |
shop.example.com. | 300 | AAAA | 2001:db8::10 | Web server IPv6 address |
shop.example.com. | 300 | HTTPS | 1 . alpn=h2,h3 | Advertises HTTP/2 and HTTP/3 support |
www.example.com. | 300 | CNAME | shop.example.com. | Alias |
example.com. | 300 | HTTPS | 0 shop.example.com. | Apex alias (AliasMode) |
example.com. | 3600 | MX | 10 mail.example.com. | Inbound mail server |
mail.example.com. | 3600 | A | 192.0.2.25 | Mail server address |
example.com. | 3600 | TXT | "v=spf1 mx -all" | SPF policy |
example.com. | 3600 | CAA | 0 issue "ca.example.net" | CA allowed to issue certificates |
- Through a registrar, the operator registers the NS RRset of
example.comand the A records ofns1andns2in the.comzone- Because
ns1andns2are underexample.com, the registered A records become glue records
- Because
- The operator puts the RRs above in the zone file on
ns1and raises the SOA serial to2026112501 ns1sends a NOTIFY message tons2ns2queriesns1for the SOA, sees that the serial has increased, and receives the changes with IXFR- Whichever of
ns1andns2the resolver queries, it receives the same authoritative answer
2.2 Answering a Query
A recursive resolver queries ns1 to find the IPv4 address of shop.example.com.
- The resolver sends a query message over UDP
- header: ID
0x3c1a, QR=0, OPCODE=0 (QUERY), RD=0 - question section:
shop.example.com. IN A - additional section: OPT RR, UDP payload size 1232, DO=1
- header: ID
ns1finds the RRset in the zone whose owner name isshop.example.com.and whose TYPE is A- It puts the same ID and QR=1, AA=1, RCODE=0 (NOERROR) in the response header
- It returns the response with the A RR in the answer section and the OPT RR in the additional section
- The resolver checks that the ID and question section of the response match the query, and caches the A RR for its TTL of 300 seconds
Querying www.example.com for A returns a CNAME RR and the A RR of shop.example.com in the answer section.
When ns1 finds a CNAME at www, it copies the CNAME RR into the answer section and restarts the lookup at the canonical name, shop.example.com.
Querying cart.example.com, which is not in the zone, returns RCODE=3 (NXDOMAIN) with the SOA RR in the authority section.
The resolver caches the “does not exist” answer for 300 seconds, the smaller of the SOA’s TTL and its MINIMUM field.
3. Core Structure
3.1 Record Types
| TYPE | Code | RDATA | Purpose |
|---|---|---|---|
| A | 1 | 32-bit IPv4 address | IPv4 address of the name |
| AAAA | 28 | 128-bit IPv6 address | IPv6 address of the name |
| CNAME | 5 | canonical name | Original name an alias points to |
| NS | 2 | name server name | Authoritative servers of the zone, marks delegation |
| SOA | 6 | MNAME, RNAME, five numeric fields | Start of the zone and its timers |
| MX | 15 | preference, exchange | Inbound mail server |
| TXT | 16 | One or more character-strings | Text-based policies, verification values |
| SRV | 33 | priority, weight, port, target | Host and port of a service |
| PTR | 12 | domain name | Reverse lookup from address to name |
| CAA | 257 | flags, tag, value | Restricts which CAs may issue certificates |
| SVCB, HTTPS | 64, 65 | SvcPriority, TargetName, SvcParams | Service endpoints and connection parameters |
A name with a CNAME cannot have any other data (DNSSEC records are the only exception).
The rule keeps the data of the alias and the canonical name from diverging, and lets a cached CNAME be used as-is for queries of other TYPEs.
Because the apex must have SOA and NS, example.com itself cannot have a CNAME.
HTTPS AliasMode, used when the apex needs an alias, is covered in 3.3 SVCB and HTTPS.
The RDATA of NS and the exchange of MX must not point to an alias either; they must be names that have A or AAAA records.
MX servers are tried starting from the lowest preference.
The RDATA of TXT is a list of character-strings, each a 1-byte length followed by a string of up to 255 bytes.
Mail authentication policies are stored in TXT.
- SPF: A policy starting with
v=spf1is placed in the TXT ofexample.com. The dedicated SPF RR type (99) saw almost no deployment, so SPF version 1 does not use it - DKIM: The public key for signature verification is placed in the TXT of
selector._domainkey.example.com - DMARC: The receiver-side handling policy is placed in the TXT of
_dmarc.example.com
The owner name of an SRV record is prefixed with service and protocol labels, as in _imaps._tcp.example.com.
A client connects to the target with the lowest priority first, and among targets with the same priority, picks one with probability proportional to its weight.
A target of . means the service is not available at that name.
CAA is a record a CA checks before issuing a certificate.
If shop.example.com has no CAA RRset, the CA searches upward through example.com and then com, up to just below the root.
issue specifies the CA allowed to issue ordinary certificates, issuewild the CA allowed to issue wildcard certificates, and iodef the address that receives reports of policy violations.
A CA that does not understand a tag with flags value 128 (critical) must not issue the certificate.
3.2 SOA
Each zone has one SOA RR at its apex, which defines the zone’s primary server and the synchronization timers for secondary servers.
| Field | Example value | Meaning |
|---|---|---|
| MNAME | ns1.example.com. | Primary server holding the original zone data |
| RNAME | hostmaster.example.com. | Mailbox of the person responsible (the first . stands for @) |
| SERIAL | 2026112501 | Zone version, 32 bits; wraps around to 0 on overflow, so it is compared with sequence space arithmetic |
| REFRESH | 7200 | Interval (seconds) at which a secondary server checks the SOA |
| RETRY | 3600 | Interval (seconds) before retrying a failed refresh |
| EXPIRE | 1209600 | Time (seconds) after which a secondary server that has lost contact with the primary server stops giving authoritative answers |
| MINIMUM | 300 | Negative caching TTL (seconds) |
MINIMUM was originally the minimum TTL applied to every RR in the zone.
RFC 2308 dropped the minimum TTL meaning and redefined MINIMUM as the TTL of negative answers.
The TTL of an NXDOMAIN or NODATA response is the smaller of the TTL of the SOA in the authority section and its MINIMUM.
In a zone file, the default TTL for RRs that omit the TTL is set by the $TTL directive, not by MINIMUM.
A secondary server transfers the zone again only when SERIAL increases, so SERIAL must be raised every time the zone is edited.
The 2026112501 in the example is the date followed by a sequence number for that day.
3.3 SVCB and HTTPS
RFC 9460 defines the SVCB RR (64), which announces service endpoints and connection parameters in a single query, and the HTTPS RR (65), its HTTPS-specific variant.
The RDATA consists of three parts: SvcPriority, TargetName, and SvcParams.
A SvcPriority of 0 means AliasMode, which delegates the service to the name in TargetName.
Unlike CNAME, AliasMode applies only to that service and does not affect resolution of other TYPEs, so it can also be placed at the apex.
A SvcPriority of 1 or more means ServiceMode, and lower values take precedence.
If the TargetName in ServiceMode is ., the owner name itself is the endpoint.
SvcParams take the following keys.
| Key | Meaning | Example |
|---|---|---|
alpn | List of supported ALPN protocol IDs | alpn=h2,h3 |
no-default-alpn | The default protocol (http/1.1 for HTTPS) is not supported | No value |
port | TCP or UDP port to connect to | port=8443 |
ipv4hint, ipv6hint | Addresses usable for connecting while the A and AAAA of TargetName are not yet known | ipv4hint=192.0.2.10 |
mandatory | List of keys the client must understand | mandatory=port |
If the scheme is https and the port is 443, the owner name of the HTTPS RR is the host name itself.
For other ports, port and scheme labels are prefixed, as in _8443._https.shop.example.com.
Clients that do not know the HTTPS RR query only A and AAAA, so even with HTTPS AliasMode at the apex, the A and AAAA records stay in place.
TLS certificate validation is based on the original host name, not the TargetName.
3.4 Reverse Zone
PTR RRs are used for reverse lookup, which finds a name from an address.
An IPv4 address becomes a name under in-addr.arpa with its octets in reverse order, and an IPv6 address a name under ip6.arpa with its hexadecimal nibbles in reverse order.
| Address | PTR owner name |
|---|---|
192.0.2.10 | 10.2.0.192.in-addr.arpa. |
2001:db8::10 | 0.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa. |
Reversing the address puts the network part on the right of the name, that is, higher in the tree.
That is why 2.0.192.in-addr.arpa can be split off as a single zone and delegated to whoever was allocated the 192.0.2.0/24 block.
The PTR for 10.2.0.192.in-addr.arpa is stored not in the example.com zone but in the zone delegated for the address block.
3.5 Delegation and Glue
A domain is example.com and every name below it, and a zone is the part of it that one set of authoritative servers is responsible for.
If eu.example.com is delegated to other servers, it still belongs to the domain example.com but is removed from the zone example.com.
The boundary between the two zones is called a zone cut.
Delegation is done by adding an NS RRset for the child zone name to the parent zone.
example.com. NS ns1.example.com. in the .com zone marks the zone cut.
The NS RRset at a zone cut belongs to the child zone, so the authoritative data is the NS RRset in the example.com zone, not the parent’s copy.
When a resolver queries for shop.example.com, the .com server returns a referral.
A referral has AA=0 and an empty answer section, and carries the NS RRset of example.com in the authority section.
If the NS target ns1.example.com is inside the example.com zone, a cycle arises: finding the address of ns1 requires asking ns1.
A glue record is an address record of a name server kept in the parent zone to break the cycle.
The .com zone holds the A and AAAA records of ns1.example.com and ns2.example.com and sends them in the additional section of the referral.
Glue is not authoritative data of the parent zone and is used only in referrals.
If a name server is outside the child zone, like ns.example.net, that name is resolved separately without glue.
3.6 Zone Transfer
A secondary server receives the entire zone or the changes from the primary server and answers with the same data.
Transfers are triggered either by polling the SOA every REFRESH interval or by a NOTIFY sent from the primary server.
| Method | Defined in | Transfer unit | Transport |
|---|---|---|---|
| NOTIFY | RFC 1996, OPCODE 4 | Change notification only | Usually UDP |
| AXFR | RFC 5936, QTYPE 252 | Entire zone, with the same SOA at the start and end | TCP only |
| IXFR | RFC 1995, QTYPE 251 | Changes since the client’s serial | UDP first, TCP if large |
A secondary server that receives a NOTIFY queries a known primary server for the SOA and compares serials.
The answer section of a NOTIFY is only a hint, so its contents are not applied to the zone data directly.
An IXFR query includes the serial the secondary server holds, and the primary server sends either the changes or the entire zone.
If a UDP IXFR response does not fit in a single packet, the primary server returns only the current SOA, and the secondary server retries over TCP.
An AXFR response can be split across multiple messages; the first message starts with the SOA and the last message ends with the same SOA.
A single DNS message over TCP is at most 65,535 bytes because of its 2-byte length field.
3.7 Message Format
Queries, responses, NOTIFY, and zone transfers all use the same message format.
A message consists of a 12-byte header and four sections: question, answer, authority, and additional.
| Field | Size | Meaning |
|---|---|---|
| ID | 16 bits | Identifier chosen by the querier and copied unchanged into the response |
| QR | 1 bit | 0 for a query, 1 for a response |
| OPCODE | 4 bits | 0 QUERY, 4 NOTIFY, 5 UPDATE |
| AA | 1 bit | Authoritative answer; the responding server is an authoritative server for the queried name |
| TC | 1 bit | The message was truncated because of the size limit of the transport |
| RD | 1 bit | Recursion desired; set in a query and copied into the response |
| RA | 1 bit | Recursion available; the server supports recursive queries |
| Z | 1 bit | Reserved, always 0 |
| AD | 1 bit | Authentic data; the resolver validated all RRsets in the answer and authority sections with DNSSEC |
| CD | 1 bit | Checking disabled; asks the server to turn off its DNSSEC validation |
| RCODE | 4 bits | Response code |
| QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT | 16 bits each | Number of items in the four sections |
| RCODE | Name | Meaning |
|---|---|---|
| 0 | NOERROR | No error; NODATA if the answer is empty |
| 1 | FORMERR | The server could not interpret the query |
| 2 | SERVFAIL | The server could not process the query because of an internal problem |
| 3 | NXDOMAIN | The queried name does not exist |
| 4 | NOTIMP | Unsupported kind of query |
| 5 | REFUSED | Refused for policy reasons (e.g. a zone transfer that is not allowed) |
The question section consists of QNAME, QTYPE, and QCLASS, and the other three sections are lists of RRs.
The answer section holds the answer to the query, the authority section holds RRs pointing to authoritative servers, and the additional section holds RRs that help process the answer.
When a name repeats within a message, every occurrence after the first is replaced by a 2-byte pointer whose top 2 bits are 11, pointing to the earlier position.
3.8 EDNS(0)
RFC 1035 limited UDP DNS messages to 512 bytes or less.
Responses with DNSSEC signatures easily exceed 512 bytes, so EDNS(0) in RFC 6891 defined a way to negotiate larger UDP responses.
EDNS(0) does not add a new header; instead it places a single OPT pseudo-RR (TYPE 41) in the additional section.
OPT reuses the RR fields with different meanings.
- CLASS: UDP payload size the requester can receive. Values below 512 are treated as 512
- TTL: The top 8 bits are EXTENDED-RCODE, which extends RCODE to 12 bits, the next 8 bits are VERSION (currently 0), the next 1 bit is DO, and the remaining 15 bits are Z
- RDATA: List of options, each made of OPTION-CODE, OPTION-LENGTH, and OPTION-DATA
Sending the DO (DNSSEC OK) bit set to 1 means the resolver can accept DNSSEC RRs such as RRSIG.
If DO is 0, the server does not include DNSSEC RRs in the response unless they were explicitly queried.
A message must contain only one OPT; if there are two or more, FORMERR is returned.
A response to a query with OPT also contains OPT, and OPT is never cached or placed in a zone file.
RFC 6891 recommends a fallback that starts the payload size at 4096 bytes and, on failure, lowers it to 1280 ~ 1410 bytes and then to 512 bytes.
A UDP response that exceeds the path MTU causes IP fragmentation, and firewalls that block fragments drop the response.
3.9 TCP Fallback
If a UDP response exceeds the requester’s payload size (512 bytes without EDNS(0)), the server truncates the response and sets TC=1.
A client that receives TC=1 sends the same query again over TCP.
RFC 7766 redefined TCP as a transport equal to UDP rather than a fallback.
- All implementations support TCP: Authoritative servers, recursive resolvers, and stub resolvers must all support both UDP and TCP
- TCP may be used first: A client may query over TCP without trying UDP first, and reuses an open connection if one exists
- Pipelining: A client sends multiple queries without waiting for responses, and since the server may answer in the order processing finishes, responses are matched by ID
- Response on the same transport: The server responds over the transport the query arrived on, and over the same connection for TCP
RFC 7766 notes that NXDOMAIN responses from DNSSEC-signed zones that use NSEC3 almost always exceed 512 bytes.
If TCP on port 53 is blocked, the retry after a TC=1 response fails, and the client never receives the large response.
References
- RFC 1034 (Domain Names - Concepts and Facilities): https://www.rfc-editor.org/rfc/rfc1034
- RFC 1035 (Domain Names - Implementation and Specification): https://www.rfc-editor.org/rfc/rfc1035
- RFC 2181 (Clarifications to the DNS Specification): https://www.rfc-editor.org/rfc/rfc2181
- RFC 2308 (Negative Caching of DNS Queries): https://www.rfc-editor.org/rfc/rfc2308
- RFC 3596 (AAAA, ip6.arpa): https://www.rfc-editor.org/rfc/rfc3596
- RFC 2782 (SRV): https://www.rfc-editor.org/rfc/rfc2782
- RFC 8659 (CAA): https://www.rfc-editor.org/rfc/rfc8659
- RFC 6844 (CAA type code assignment): https://www.rfc-editor.org/rfc/rfc6844
- RFC 9460 (SVCB, HTTPS): https://www.rfc-editor.org/rfc/rfc9460
- RFC 7208 (SPF): https://www.rfc-editor.org/rfc/rfc7208
- RFC 6376 (DKIM): https://www.rfc-editor.org/rfc/rfc6376
- RFC 7489 (DMARC): https://www.rfc-editor.org/rfc/rfc7489
- RFC 9499 (DNS Terminology): https://www.rfc-editor.org/rfc/rfc9499
- RFC 5936 (AXFR): https://www.rfc-editor.org/rfc/rfc5936
- RFC 1995 (IXFR): https://www.rfc-editor.org/rfc/rfc1995
- RFC 1996 (NOTIFY): https://www.rfc-editor.org/rfc/rfc1996
- RFC 2136 (UPDATE): https://www.rfc-editor.org/rfc/rfc2136
- RFC 4035 (DNSSEC protocol, AD and CD bits): https://www.rfc-editor.org/rfc/rfc4035
- RFC 6895 (DNS header bit and RCODE registries): https://www.rfc-editor.org/rfc/rfc6895
- RFC 6891 (EDNS(0)): https://www.rfc-editor.org/rfc/rfc6891
- RFC 3225 (DO bit): https://www.rfc-editor.org/rfc/rfc3225
- RFC 7766 (DNS over TCP): https://www.rfc-editor.org/rfc/rfc7766