Learning center

Only large DNS answers fail: truncation and blocked TCP port 53

When a DNS answer does not fit the UDP size the client advertised, the server sets the TC bit and the client must retry over TCP port 53. If a firewall, security group or proxy blocks TCP 53, or the client library never retries over TCP, only the large answers fail: names with many addresses, long TXT records, DNSSEC responses. Query the same name over UDP without the retry and then over TCP to see which half breaks.

The symptom#

Most names resolve, and a few fail every time from one network:

  • A name behind a large load balancer or service discovery record with many addresses fails, while a name with one address works.
  • TXT lookups, such as domain verification or SPF checks, fail or return nothing.
  • A signed zone fails from a validating resolver while unsigned names work, because signatures make answers larger.
  • Pods built on an old Alpine image fail to resolve a name that other images resolve.

Size, not the name, is the common factor.

Why size matters#

RFC 1035 limits plain UDP DNS messages to 512 octets and defines the TC (truncation) bit: the message was truncated because it was longer than the transport allows. EDNS(0), RFC 6891, lets a client advertise a larger UDP payload size so more answers fit without TCP. When the answer still does not fit, the server truncates it and sets TC, and the client is expected to retry over TCP. RFC 1035 · RFC 6891 · RFC 7766

RFC 7766 makes TCP support a required part of a full DNS implementation for both authoritative and recursive servers, and it warns that failure to support TCP, or blocking DNS over TCP at the network layer, will probably result in resolution failure or application-level timeouts. DNSSEC made truncation at 512 bytes commonplace. RFC 7766

So there are two ways for the retry to fail:

  • The TCP path is blocked: a security group, network ACL, firewall or forwarder allows UDP 53 and not TCP 53, between the client and its resolver or between a resolver and the next server.
  • The client never retries. Kubernetes documents that musl, as shipped in Alpine 3.17 and earlier, did not fall back to TCP, so any DNS answer above 512 bytes failed. Kubernetes DNS known issues

Query over UDP, then TCP#

dig retries over TCP by default when it sees TC. +ignore turns that retry off so you can see the truncated reply, +bufsize sets the advertised UDP size, and +tcp sends the query over TCP from the start. The statistics at the end of dig's output include the size of the reply. dig manual

# Inside the failing container or host, against the resolver it uses
cat /etc/resolv.conf

# UDP only, no TCP retry: look for the tc flag in the header
dig @RESOLVER_IP NAME A +notcp +ignore
dig @RESOLVER_IP NAME A +notcp +ignore +bufsize=512

# TCP from the start
dig @RESOLVER_IP NAME A +tcp

# The default behavior: UDP, then TCP if truncated
dig @RESOLVER_IP NAME A

If the TCP query hangs, check whether TCP 53 opens at all:

nc -vz -w 3 RESOLVER_IP 53

Repeat the pair against the next hop when you can reach it, such as the resolver your resolver forwards to, to find which leg drops TCP.

Read the result#

UDP with +ignore+tcpDefaultPoints to
Answer, no tcAnswerAnswerNot size; look elsewhere
tc setTimes outTimes outTCP 53 blocked on this leg
tc setAnswerAnswerDNS path is fine; the client library does not retry over TCP
tc setSERVFAILSERVFAILThe resolver cannot use TCP to the next server
No replyAnswerAnswerUDP is the broken half, often a fragmented large reply that is dropped

The third row is the old-musl case. dig in the same container works because dig has its own resolver code; the application's library does not retry. Compare with getent ahosts NAME in a glibc image, or check the image's base version.

Where TCP 53 is commonly blocked#

Look for rules that name UDP 53 alone:

  • Security groups and network ACLs written for "DNS" with only UDP. Route 53 Resolver outbound endpoints, for example, need a security group that allows both TCP and UDP on port 53 to the target resolvers. Resolver outbound endpoints
  • Firewalls between a cloud network and on-premises DNS servers that receive forwarded queries.
  • Kubernetes NetworkPolicies that allow egress to the cluster DNS on UDP 53 and forget TCP.
  • Custom resolvers or forwarders configured to listen on UDP only.

A worked example#

This example is illustrative. The orders service resolves inventory.example.internal, which a service-discovery system publishes with 120 A records, one per instance. From Tuesday, after a NetworkPolicy change, lookups fail with timeouts; payments.example.internal, with two records, still resolves.

Query from an orders podResult
+notcp +ignore, inventoryNOERROR, tc flag, 0 answers
+tcp, inventorytimed out
+tcp, paymentstimed out
nc -vz -w 3 10.96.0.10 53timed out
Same nc from a pod in another namespaceconnected

The truncated reply shows the answer did not fit. TCP to the cluster DNS fails from this namespace only, and for every name, not only the large one; small names never needed TCP, so nobody noticed. The new policy allows egress to port 53 over UDP only. The DNS servers and the record are fine.

In a second case, the same 120-record name fails only in the checkout service. +tcp works from a checkout pod, and getent ahosts fails. The image is built on Alpine 3.16. dig succeeded because it retries over TCP itself; the application's resolver does not. Rebuilding on a newer base image is the fix, not a network change.

Limits#

+bufsize changes what you advertise, not what the server will send or what the path can carry. A server can still truncate below your value, and a path that drops fragmented UDP can lose large replies that never set TC. dig's default reply handling hides truncation, which is why the checks use +ignore.

The leg that fails may be beyond your resolver. If your client's queries go through CoreDNS, then the VPC resolver, then a forwarder, TCP has to work on each leg that handles a truncated answer. For the reading of SERVFAIL and timeouts in general, see NXDOMAIN, SERVFAIL or no answer; signed zones that fail for signature reasons are covered in DNSSEC SERVFAIL. For the method across dependency layers, see runtime dependency failures.

Questions#

Does DNS use TCP?

Yes. TCP is required for a full DNS implementation, and clients use it when a UDP answer is truncated, as well as for zone transfers. Allow both TCP and UDP on port 53 wherever DNS traffic flows.

Why does dig work while my application fails to resolve the same name?

dig retries over TCP when the reply is truncated. Some resolver libraries, such as musl in older Alpine releases, did not. Run dig with +notcp +ignore to see whether the answer is truncated, then test the application's own lookup.

How do I know a DNS answer was truncated?

Query over UDP with dig +notcp +ignore and look for the tc flag in the header. Without +ignore, dig retries over TCP and shows you the full answer instead.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading