My DNS Notes, Ep. 2 - Resource Records, Zones, and Message Format

networking17 min한국어

#dns#resource-record#dns-zone#edns#networking

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.

owner name variable TYPE 2 bytes CLASS 2 bytes TTL 4 bytes RDLENGTH 2 bytes RDATA variable shop.example.com. A IN 300 4 192.0.2.10 shop.example.com. A IN 300 4 192.0.2.11 Same values form one RRset Same within RRset Differs per RR
RRs with the same owner name, TYPE, and CLASS form one RRset, and only their RDATA differs.
FieldSizeMeaning
owner nameVariable, up to 255 bytesName the RR belongs to
TYPE2 bytesRecord type (A=1, NS=2, CNAME=5, SOA=6, MX=15, TXT=16, AAAA=28)
CLASS2 bytesProtocol family; IN (1) for the Internet
TTL4 bytesTime in seconds the RR may be cached, 0 ~ 2^31-1
RDLENGTH2 bytesLength of the RDATA in bytes
RDATAVariableValue 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.

zone file example.com RRs ns1.example.com authoritative server resolver Caches RRs Load Query message Response message DNS message header question answer authority additional 12 bytes List of RRs
RRs are stored in a zone file, 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 nameTTLTYPERDATARole
example.com.3600SOAns1.example.com. hostmaster.example.com. 2026112501 7200 3600 1209600 300Zone version and timers
example.com.3600NSns1.example.com.Authoritative server
example.com.3600NSns2.example.com.Authoritative server
ns1.example.com.3600A192.0.2.1Name server address
ns2.example.com.3600A198.51.100.1Name server address
shop.example.com.300A192.0.2.10Web server IPv4 address
shop.example.com.300AAAA2001:db8::10Web server IPv6 address
shop.example.com.300HTTPS1 . alpn=h2,h3Advertises HTTP/2 and HTTP/3 support
www.example.com.300CNAMEshop.example.com.Alias
example.com.300HTTPS0 shop.example.com.Apex alias (AliasMode)
example.com.3600MX10 mail.example.com.Inbound mail server
mail.example.com.3600A192.0.2.25Mail server address
example.com.3600TXT"v=spf1 mx -all"SPF policy
example.com.3600CAA0 issue "ca.example.net"CA allowed to issue certificates
Operator Manages example.com .com zone Via registrar ns1 primary ns2 secondary resolver Queries ① Register NS, glue ② Add RRs, serial+1 ③ NOTIFY ④ SOA query serial 2026112501 IXFR query Changed RRs ⑤ shop A? A 192.0.2.10 Same answer from ns1
The operator registers the delegation in the parent zone, and the secondary server, after receiving NOTIFY, checks the SOA serial and receives the changes with IXFR.
  1. Through a registrar, the operator registers the NS RRset of example.com and the A records of ns1 and ns2 in the .com zone
    • Because ns1 and ns2 are under example.com, the registered A records become glue records
  2. The operator puts the RRs above in the zone file on ns1 and raises the SOA serial to 2026112501
  3. ns1 sends a NOTIFY message to ns2
  4. ns2 queries ns1 for the SOA, sees that the serial has increased, and receives the changes with IXFR
  5. Whichever of ns1 and ns2 the 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.

recursive resolver Sends query ns1 authoritative server ① ID 0x3c1a, shop.example.com. IN A RD=0, OPT: payload 1232, DO=1 ② Find shop A RRset in zone ③ ID 0x3c1a, QR=1, AA=1, RCODE=0 ④ answer: A 192.0.2.10, additional: OPT ⑤ Check ID, question; cache 300 s
For a single query from the resolver, ns1 returns an authoritative response with the same ID.
  1. 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
  2. ns1 finds the RRset in the zone whose owner name is shop.example.com. and whose TYPE is A
  3. It puts the same ID and QR=1, AA=1, RCODE=0 (NOERROR) in the response header
  4. It returns the response with the A RR in the answer section and the OPT RR in the additional section
  5. 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
header question shop.example.com. IN A answer shop.example.com. 300 IN A 192.0.2.10 authority (empty) additional OPT UDP payload 1232 DO=1 ID=0x3c1a QR=1 OPCODE=0 AA=1 TC=0 RD=0 RCODE=0 QDCOUNT=1 ANCOUNT=1 NSCOUNT=0 ARCOUNT=1
The response repeats the question from the query, and the answer is carried in the answer section.

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

TYPECodeRDATAPurpose
A132-bit IPv4 addressIPv4 address of the name
AAAA28128-bit IPv6 addressIPv6 address of the name
CNAME5canonical nameOriginal name an alias points to
NS2name server nameAuthoritative servers of the zone, marks delegation
SOA6MNAME, RNAME, five numeric fieldsStart of the zone and its timers
MX15preference, exchangeInbound mail server
TXT16One or more character-stringsText-based policies, verification values
SRV33priority, weight, port, targetHost and port of a service
PTR12domain nameReverse lookup from address to name
CAA257flags, tag, valueRestricts which CAs may issue certificates
SVCB, HTTPS64, 65SvcPriority, TargetName, SvcParamsService 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=spf1 is placed in the TXT of example.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.

FieldExample valueMeaning
MNAMEns1.example.com.Primary server holding the original zone data
RNAMEhostmaster.example.com.Mailbox of the person responsible (the first . stands for @)
SERIAL2026112501Zone version, 32 bits; wraps around to 0 on overflow, so it is compared with sequence space arithmetic
REFRESH7200Interval (seconds) at which a secondary server checks the SOA
RETRY3600Interval (seconds) before retrying a failed refresh
EXPIRE1209600Time (seconds) after which a secondary server that has lost contact with the primary server stops giving authoritative answers
MINIMUM300Negative 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.

With CNAME at example.com With HTTPS AliasMode at example.com SOA NS CNAME shop.example.com. CNAME allows no other RRs at the same name Conflicts with SOA, NS SOA NS A, AAAA (for legacy clients) HTTPS 0 shop.example.com. Applies only to HTTPS queries
A CNAME cannot coexist with other RRs at the same name; an HTTPS AliasMode record can.

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.

KeyMeaningExample
alpnList of supported ALPN protocol IDsalpn=h2,h3
no-default-alpnThe default protocol (http/1.1 for HTTPS) is not supportedNo value
portTCP or UDP port to connect toport=8443
ipv4hint, ipv6hintAddresses usable for connecting while the A and AAAA of TargetName are not yet knownipv4hint=192.0.2.10
mandatoryList of keys the client must understandmandatory=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.

AddressPTR owner name
192.0.2.1010.2.0.192.in-addr.arpa.
2001:db8::100.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.

.com zone NS RRset example.com. NS ns1, ns2 glue record A of ns1, ns2, referrals only zone cut: child zone's NS is authoritative example.com zone SOA, NS authoritative shop, www, mail Zone RRs eu.example.com Own zone if delegated
The NS and glue in the parent zone only mark the delegation; the authoritative data is in the child zone.

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.

ns1 (primary) serial 2026112502 ns2 (secondary) serial 2026112501 1. NOTIFY (OPCODE 4) 2. SOA query 3. SOA serial 2026112502 4. IXFR (serial 2026112501) 5. Changed RRs
NOTIFY only signals a change; the actual transfer is requested by the secondary server after it checks the SOA.
MethodDefined inTransfer unitTransport
NOTIFYRFC 1996, OPCODE 4Change notification onlyUsually UDP
AXFRRFC 5936, QTYPE 252Entire zone, with the same SOA at the start and endTCP only
IXFRRFC 1995, QTYPE 251Changes since the client’s serialUDP 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.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ID QR OPCODE AA TC RD RA Z AD CD RCODE QDCOUNT ANCOUNT NSCOUNT ARCOUNT After header: question, answer, authority, additional sections TC=1: response truncated, retry over TCP
The 12-byte header holds the identifier, the flags, and the item counts of the four sections.
FieldSizeMeaning
ID16 bitsIdentifier chosen by the querier and copied unchanged into the response
QR1 bit0 for a query, 1 for a response
OPCODE4 bits0 QUERY, 4 NOTIFY, 5 UPDATE
AA1 bitAuthoritative answer; the responding server is an authoritative server for the queried name
TC1 bitThe message was truncated because of the size limit of the transport
RD1 bitRecursion desired; set in a query and copied into the response
RA1 bitRecursion available; the server supports recursive queries
Z1 bitReserved, always 0
AD1 bitAuthentic data; the resolver validated all RRsets in the answer and authority sections with DNSSEC
CD1 bitChecking disabled; asks the server to turn off its DNSSEC validation
RCODE4 bitsResponse code
QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT16 bits eachNumber of items in the four sections
RCODENameMeaning
0NOERRORNo error; NODATA if the answer is empty
1FORMERRThe server could not interpret the query
2SERVFAILThe server could not process the query because of an internal problem
3NXDOMAINThe queried name does not exist
4NOTIMPUnsupported kind of query
5REFUSEDRefused 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.

NAME 0 (root) TYPE 41 (OPT) CLASS UDP payload 1232 TTL RCODE, version, flags RDLEN Length RDATA Option list EXTENDED-RCODE 8 bits VERSION 8 bits DO 1 bit Z 15 bits
OPT carries the UDP payload size in CLASS and the DO bit in TTL.
  • 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.

resolver Querying side authoritative Answering side 1. UDP query (payload 1232) 2. UDP response, TC=1 (truncated) 3. TCP query (2-byte length + message) 4. TCP response (max 65,535 bytes)
If a UDP response is truncated, TC=1 is set and the client queries 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