“For DNS, I only need to open UDP port 53, right?”
This is actually a common misunderstanding. It is also the starting point of hard-to-diagnose failures such as “everything works except a few domains” or “name resolution fails once in a while after we enabled DNSSEC.”
Through Part 3 we followed the “flow” of how a caching DNS server looks for an answer. In Part 4 we change perspective and look at what is inside a DNS message and how it is carried over UDP and TCP. This is also the foundation you need to read dig output.
▶ This part is also available as a YouTube video (about 19 min) (it is also embedded at the end of this article).
- The structure of a DNS message
- Header flags
- UDP and TCP
- How TCP fallback came about, and the “512-byte wall”
- EDNS(0) and the OPT pseudo-record
- Fragmentation and DNS Flag Day 2020
- Problems caused by firewalls and devices on the path
- DNS Cookies
- Response codes (RCODE)
- Extended DNS Errors (EDE)
- Think about it
- Summary
- Watch the video
- The DNS Fundamentals series (12 parts)
The structure of a DNS message
DNS queries and responses are both exchanged in the same DNS message format.

| Part | What it holds |
|---|---|
| Header (12 bytes) | The ID that matches queries to responses, flags, the response code (RCODE), and the number of entries in each section |
| Question | The name, type, and class that were asked. Copied unchanged into the response |
| Answer | The records that answer the question |
| Authority | NS records of the delegated servers, or the SOA record when the answer is “does not exist” |
| Additional | Glue A/AAAA records for the NS host names, and the EDNS OPT pseudo-record |
“QUESTION SECTION,” “ANSWER SECTION,” and the rest of dig’s output are these five parts, displayed as they are (Part 8). In a query the Answer and Authority parts are empty, and often only OPT appears in Additional. Queries and responses have the same shape; what differs is the flags and the contents of each part.
Key points
• A message has five parts: header, question, answer, authority, additional
• Authority holds the delegated NS records, or the SOA when there is “no such data”
• Additional holds glue and the EDNS OPT pseudo-record
Header flags
The flags in the header are some of the most frequently used information when you isolate a failure.
| Flag | Name | Meaning | When to look at it |
|---|---|---|---|
| QR | Query/Response | 0 = query, 1 = response | Always set on responses |
| AA | Authoritative Answer | The answer comes from the authoritative DNS server itself | Whether the answer came from a cache or from an authoritative server |
| TC | TrunCation | The response did not fit and was truncated | A signal to retry over TCP |
| RD | Recursion Desired | Recursive query requested | Normally 1 for stub resolvers |
| RA | Recursion Available | Recursive queries are accepted | 0 on authoritative-only servers |
| AD | Authentic Data | DNSSEC validation succeeded | Responses from validating resolvers (Part 9) |
| CD | Checking Disabled | Please do not perform DNSSEC validation | Isolating validation failures (dig +cd, Resolve-DnsName -DnssecCd) |
Here is how this looks in real dig output.
$ dig www.example.com # ask the caching DNS
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
$ dig @ns1.example.com www.example.com +norec # ask the authoritative DNS directly
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
An answer from a caching DNS server does not carry aa, while asking the authoritative DNS directly does. This is the first thing to check when you are separating “the authoritative answer differs from the cached answer.” The numbers after the flags line are the entry counts of each section.
Note that PowerShell’s Resolve-DnsName does not display flags, so use dig on Linux or similar when you need to see them.
UDP and TCP
DNS uses port 53 and communicates over both UDP and TCP.

Normal queries use UDP. One round trip is enough, so it is light and fast.
When a response does not fit in UDP, the server returns a response with the TC bit set in the header, and the client repeats the same query over TCP. This is called TCP fallback. Zone transfers (Part 7) also use TCP.
TCP is not an occasional spare
This is the key to the misunderstanding at the start.
- RFC 7766 (2016): requires all general-purpose implementations to support both UDP and TCP
- RFC 9210 (2022): asks operators not to block TCP
On firewalls, allow UDP/53 and TCP/53 both between the client and the caching DNS and between the caching DNS and the authoritative DNS. If TCP/53 is closed on either side, the result is a hard-to-see failure in which only large responses fail.
Key points
• Normally UDP; if the response does not fit, check the TC bit and retry over TCP
• TCP support is mandatory (RFC 7766) and must not be blocked (RFC 9210)
• Allow UDP/53 and TCP/53 on both segments
How TCP fallback came about, and the “512-byte wall”
Why is it designed this way? Let’s go back through a little history.

- 1983 (RFC 883) and 1987 (RFC 1034/1035): DNS communicated over either UDP or TCP, and UDP messages were limited to 512 bytes at most. The basis for 512 is the 576-byte datagram that every host must be able to receive according to RFC 791 (512 bytes of data plus 64 bytes of header); the limit was set at a size that is guaranteed to arrive in a single packet.
- 1989 (RFC 1123): queries must always be sent over UDP first, and if the response is truncated, retried over TCP. The aim was to reduce the processing load for DNS, which exchanges small pieces of data frequently. This is TCP fallback.
- 2010 (RFC 5966): made TCP support mandatory, and relaxed “UDP first” to “UDP should be tried first (SHOULD).”
- 2016 (RFC 7766, replacing 5966): stated explicitly that starting with TCP is allowed (MAY). RFC 9210 in 2022 added operational requirements.
The “512-byte wall”
Because UDP is tried first and the query is redone over TCP only after truncation, the number of round trips doubles for a single name resolution. As DNSSEC and IPv6 spread and responses grew, this inefficiency became a real problem. This is the “512-byte wall.” What appeared to solve it is EDNS(0), explained next.
You can try it yourself. If you go back to the 512-byte limit with +noedns, a large TXT or MX response triggers TCP fallback.
$ dig +noedns example.com TXT
;; Truncated, retrying in TCP mode.
(omitted)
;; SERVER: 192.0.2.53#53(192.0.2.53) (TCP)
In PowerShell, Resolve-DnsName -TcpOnly queries over TCP from the start. In a packet capture you can also see a TCP connection start right after a UDP response with the TC bit set.
EDNS(0) and the OPT pseudo-record
EDNS(0) (RFC 6891) is a mechanism that extends DNS through the OPT pseudo-record in the Additional section.

When the client announces “I can receive up to this size over UDP,” the server replies over UDP even above 512 bytes. What is interesting is that it borrows the fields of an existing record format to carry the extension information.
| OPT field | Meaning in an ordinary record | How OPT uses it |
|---|---|---|
| NAME | The name | Root (empty) |
| TYPE | The type | 41 (OPT) |
| CLASS | The class (IN) | The UDP size the sender can receive (e.g., 1232 bytes) |
| TTL | How long to cache | Extended RCODE, EDNS version (0), and the DO bit (a request for DNSSEC data) |
| RDATA | The value | Options (COOKIE, EDE, NSID, Client Subnet, Padding, and others) |
In dig it appears like this.
$ dig www.example.com
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
With DNS Flag Day 2019 on February 1, 2019, major resolvers stopped working around servers that do not respond correctly to EDNS. In other words, old authoritative DNS servers that cannot handle EDNS properly have been failing name resolution since that point. Note that Resolve-DnsName does not show the contents of OPT.
Fragmentation and DNS Flag Day 2020
Once EDNS(0) made large UDP responses possible, IP fragmentation became the next problem.

A UDP response larger than the path MTU (normally 1500 bytes on Ethernet, and smaller on VPNs and the like) is split at the IP level. The second and later fragments have no UDP header, so firewalls and NAT devices tend to drop them, and cache poisoning techniques that forge fragments are also known.
So DNS Flag Day 2020 on October 1, 2020 recommended setting the EDNS buffer size to 1232 bytes.
The 1232 calculation
1280 (IPv6 minimum MTU) − 40 (IPv6 header) − 8 (UDP header) = 1232
At this size the response arrives without fragmentation on almost every path. Responses that do not fit are carried over TCP, so allowing TCP/53 is a prerequisite. BIND and Unbound (1.12.0 and later) default to 1232.
Key points
• Large UDP responses are fragmented by IP, and the fragments tend to be dropped
• The recommended buffer size is 1232 bytes (1280 − 48, Flag Day 2020)
• Responses that do not fit are carried over TCP. Allowing TCP/53 is a prerequisite
Problems caused by firewalls and devices on the path
Turning the discussion so far into symptoms you see in the field gives the following.
| Symptom | Common cause | Remedy |
|---|---|---|
| Only large responses (DNSSEC, long TXT, many MX) fail | TCP/53 is closed | Allow both UDP/53 and TCP/53 |
| Only UDP responses over 512 bytes do not arrive | An old device’s DNS inspection limit is still 512 bytes (e.g., Cisco ASA’s message-length maximum 512) | Change the setting to follow the size announced via EDNS (e.g., ASA’s message-length maximum client auto) |
| Only certain domains time out occasionally | Fragments of split UDP packets are being dropped | Set the buffer to 1232 and allow TCP |
| FORMERR is returned, or EDNS does not get through | A DNS proxy or ALG in a router or similar does not understand or strips OPT | Disable the DNS proxy or ALG, or update the device |
| Return responses are dropped | Return traffic is allowed only for source port 53 | The source port is random (RFC 5452). Allow it statefully |
When a firewall drops a UDP response, the client receives nothing and gets a timeout. A response code such as REFUSED comes back only when the DNS server itself responded.
You can check path support by comparing dig +bufsize=1232 with +bufsize=4096 (a feature not available in the standard Windows commands, so do this on Linux or similar), or with ISC’s EDNS Compliance Tester (ednscomp.isc.org).
DNS Cookies
UDP has no connection setup, so it has a weakness: queries with a forged source IP address, or forged responses, are easy to inject. DNS Cookies (RFC 7873, 2016) lightly compensate for this weakness using an EDNS option.

- The client attaches a client cookie (8 bytes) to the query
- The server attaches a server cookie to the response
- From then on, both are attached to each query
This lets the server confirm “this is a peer that really talked to this address before,” and the client confirm “this response is a genuine response to my own query.” It reduces reflection attacks with a forged source and forged responses from off the path.
RFC 9018 (2021) standardized how server cookies are generated so they can be used even in anycast deployments (Part 7) that mix multiple products. In dig you can check the ; COOKIE: line.
Response codes (RCODE)
The RCODE is the first thing to look at in incident response.
| Value | Name | Meaning | Common causes |
|---|---|---|---|
| 0 | NOERROR | Processed normally | Even zero answers is NOERROR (see NODATA below) |
| 1 | FORMERR | The query format could not be interpreted | Old servers or DNS proxies that cannot understand the EDNS OPT |
| 2 | SERVFAIL | Processing failed on the server side | Cannot reach the authoritative DNS, DNSSEC validation failure |
| 3 | NXDOMAIN | The name itself does not exist | Misspelled name, not registered, asking the wrong server |
| 4 | NOTIMP | The requested function is not implemented | A kind of query that is not supported |
| 5 | REFUSED | Refused by policy | Denied by an ACL, or asked an authoritative DNS about a name it is not responsible for |
| (none) | NODATA | Not an RCODE but a name for a state | The name exists but that type does not (NOERROR with zero answers) |
Note in particular that NODATA is not an RCODE. It refers to the state where the RCODE is NOERROR, there are zero answers, and the SOA is in the Authority section. When you see “NOERROR but no answer,” it means the name exists but there is no record of that type.
Values 6 to 10 (YXDOMAIN and others) are used by dynamic updates (Part 7), and 16 and above are codes extended through EDNS. How each kind of response looks in dig is covered in Part 8.
Extended DNS Errors (EDE)
SERVFAIL says only that “something failed on the server side,” so it does not tell you the cause. EDE (Extended DNS Errors, RFC 8914, 2020) was introduced for this. It returns the reason for SERVFAIL and similar errors in an EDNS option.
| INFO-CODE | Name | Meaning |
|---|---|---|
| 3 | Stale Answer | Answered from an expired cache entry (serve-stale) |
| 6 | DNSSEC Bogus | DNSSEC validation failed |
| 7 | Signature Expired | The signature has expired |
| 9 | DNSKEY Missing | There is no DNSKEY matching the DS |
| 15 / 17 | Blocked / Filtered | Blocked by the resolver’s policy |
| 18 | Prohibited | The querier is not allowed |
| 22 | No Reachable Authority | Cannot reach the authoritative DNS servers |
| 23 | Network Error | An error occurred communicating with the authoritative DNS |
If you query a public resolver for the test domain dnssec-failed.org, EDE comes back like this (excerpt).
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 34492
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags: do; udp: 1232
; EDE: 9 (DNSKEY Missing): (no SEP matching the DS found for dnssec-failed.org.)
With this, you can tell from the response alone whether the cause is “a DNSSEC failure” or “the authoritative server cannot be reached.” Make it a habit to check EDE first when you see SERVFAIL.
Think about it
- Is DNS TCP/53 allowed on the firewalls in your environment? Check each of client ⇔ caching DNS and caching DNS ⇔ authoritative DNS.
- You receive a report that “name resolution is slow once in a while, but only for some domains.” Based on this article, what causes can you think of?
- When your internal caching DNS returns SERVFAIL, what information (flags, EDE, results from another resolver) should you look at to get more clues about the cause?
Hint: Changing options such as dig +bufsize=512, +tcp, +norec, and +cd and comparing the results shows you at which stage things fail. In PowerShell, -TcpOnly, -NoRecursion, and -DnssecCd play the same roles.
Summary
- A DNS message has five parts: header, question, answer, authority, and additional. dig’s display corresponds to them directly
- aa means an authoritative answer, TC is the signal to retry over TCP, and ad means DNSSEC validation succeeded
- DNS requires TCP too. Allow UDP/53 and TCP/53 on both segments
- The EDNS buffer is 1232 bytes. Anything beyond that is carried over TCP
- NODATA is not an RCODE. When you see SERVFAIL, check the reason with EDE
Starting next time, we look at the kinds and syntax of resource records, the contents of the message, over two parts.
Watch the video
This part is also explained in a YouTube video (about 19 min).
All parts of the series are in the DNS Fundamentals playlist on YouTube.
The DNS Fundamentals series (12 parts)
All 12 parts with a reading guide: DNS Fundamentals
- What Is DNS? How Name Resolution Works and Its Three Key Players
- The domain name hierarchy and delegation
- How name resolution works
- DNS messages and transport (this article)
- Resource records, part 1
- Resource records, part 2
- Running authoritative DNS servers
- Investigating with commands
- DNS security
- DNS in the cloud and on corporate networks
- DNS troubleshooting
- DNS design exercises
This series is the English edition of 【DNS入門】, originally written in Japanese.


コメント