The Domain Name System (DNS) uses both UDP and TCP, operating over port 53 for each transport protocol. Standard DNS queries default to UDP to keep lookup latency minimal and server overhead low, while DNS automatically shifts to—or directly initiates—TCP whenever message sizes exceed safe UDP limits, zone data must be replicated reliably, or a server needs to verify that a client’s source IP address is genuine.
Understanding where UDP ends and TCP begins is critical for network engineers, system administrators, and security teams. Treating DNS as a strictly UDP-based protocol leads to misconfigured firewalls, intermittent lookup timeouts on modern security-hardened domains, and broken load-balancing architectures.
Table of Contents
When and Why DNS Uses UDP vs. TCP on Port 53
Classic DNS relies on a dual-transport model on port 53, selecting the protocol based on the transaction’s size, statefulness, and reliability requirements. The workflow follows a predictable progression:
Defaulting to UDP for Fast, Stateless Lookups
A typical hostname lookup is a short, self-contained exchange: one small request packet and one small response packet. Over UDP, a recursive resolver sends a query to port 53 and receives an answer in a single round-trip time (1 RTT) totaling just two packets. Because UDP is connectionless, DNS servers avoid the latency of a TCP three-way handshake (SYN,SYN-ACK,ACK) and do not have to allocate kernel memory to track millions of concurrent client connection states.Detecting Truncation (
TC=1) on Oversized Replies
When an authoritative server or recursive resolver assembles a DNS response that exceeds the allowed UDP payload ceiling, it cannot safely send the full answer in one UDP datagram. Instead, the server sets the Truncated (TC) flag (TC=1) in the 12-byte DNS header and returns a partial or empty UDP response to signal that the complete record set requires a stream-oriented transport.Retrying Over TCP to Retrieve the Full Payload
Upon receiving a response withTC=1, a compliant DNS client discards the incomplete UDP answer, opens a TCP connection to port 53 on the same server, and re-issues the query. DNS over TCP prepends a two-byte (16-bit) length field to every message, allowing responses up to 65,535 bytes while guaranteeing ordered, lossless delivery via TCP acknowledgments and retransmission.Starting Directly on TCP for Zone Transfers and Stateful Sessions
Certain operations bypass UDP altogether and initiate TCP immediately:- Zone Transfers (
AXFRandIXFR): Replicating full (AXFR) or incremental (IXFR) DNS zone files between primary and secondary authoritative servers requires guaranteed integrity across potentially megabytes of record data, making TCP mandatory. - Persistent Pipelined Resolvers: Stub or forwarding resolvers configured with DNS Stateful Operations (DSO) or persistent TCP connection pools send queries straight over established TCP streams to amortize handshake costs across thousands of lookups.
While UDP keeps everyday browsing snappy, TCP acts as the mandatory safety net that ensures large or mission-critical DNS transactions never fail due to datagram constraints.
How EDNS(0), DNSSEC, and Large TXT Records Trigger TCP Fallback
The truncation fallback described above used to be rare, but modern DNS extensions and bloated resource records now push routine queries onto TCP every day. How often a lookup crosses that threshold depends on four sequential protocol factors:
The Legacy 512-Byte UDP Ceiling
Early DNS specifications restricted UDP messages to 512 bytes so packets would fit inside the 576-byte minimum IPv4 reassembly buffer of 1980s routers without fragmenting. Any response larger than 512 bytes immediately triggeredTC=1and a TCP retry.EDNS(0) Buffer Size Negotiation
To reduce TCP fallbacks as IPv6 (AAAA) records and larger zones emerged, Extension Mechanisms for DNS (EDNS(0)) introduced anOPTpseudo-record in the DNS Additional section. Clients use theOPTrecord’s class field to advertise a larger UDP receive buffer—historically up to 4,096 bytes—and the responder caps its UDP reply at the smaller of the two endpoints’ advertised buffers.IP Fragmentation Hazards and the 1,232-Byte Consensus
Sending 4,096-byte UDP datagrams across networks with a standard 1,500-byte Ethernet MTU (or the 1,280-byte IPv6 minimum MTU) forces routers or hosts to split the reply into IP fragments. Stateful firewalls and NAT gateways frequently drop fragmented UDP packets—causing slow timeouts instead of clean TCP retries—and predictable fragment IDs expose resolvers to cache-poisoning attacks. Following the 2020 DNS Flag Day operational consensus, major implementations (BIND, Unbound, PowerDNS, and Knot DNS) standardized default EDNS(0) UDP buffers at 1,232 bytes (1,280-byte minimum IPv6 MTU minus a 40-byte IPv6 header and an 8-byte UDP header) to prevent fragmentation entirely.Payload Inflation from DNSSEC and Stacked
TXTRecords
With safe UDP payloads constrained to 1,232 bytes, modern DNS responses cross the ceiling routinely:- DNSSEC: Cryptographic signatures (
RRSIG), public key sets (DNSKEY), and authenticated denial-of-existence records (NSEC/NSEC3) add hundreds or thousands of bytes to standard answers. - Apex
TXTSprawl: Organizations routinely stackSPFmail policies,DKIMkeys, and multiple SaaS domain-verification tokens (TXTrecords for Google, Microsoft, Atlassian, and security scanners) at their root domain, easily exceeding 1,232 bytes and forcingTC=1retries over TCP.
Keeping EDNS(0) buffers around 1,232 bytes eliminates fragile UDP fragmentation on the wire, intentionally shifting oversized DNSSEC and TXT answers onto reliable TCP streams.
UDP Spoofing, Amplification Attacks, and TCP Handshake Mitigation
Beyond packet size limits, DNS servers also leverage TCP as an active defense against network-layer abuse made possible by UDP’s statelessness.
Source IP Spoofing Over Connectionless UDP
Because UDP lacks a session setup phase, a DNS server receiving a UDP packet on port 53 has no cryptographic or state-based proof that the source IP address in the packet header actually sent the query. Attackers exploit this by forging a target victim’s IP address as the source and flooding open resolvers or authoritative servers with spoofed queries.Reflection and Bandwidth Amplification
When an attacker pairs spoofed UDP queries withEDNS(0)and queries records carrying large DNSSEC orTXTpayloads, a 60-byte forged request can elicit a 1,232- to 4,000-byte UDP reply sent directly to the victim. Multiplied across thousands of servers, this reflection technique amplifies attack bandwidth by 20x to 60x+.Response Rate Limiting (RRL) and
TC=1Slip
Dropping all high-rate UDP queries outright risks blackholing legitimate users sitting behind large carrier-grade NATs or enterprise proxies. Instead, authoritative servers deploy Response Rate Limiting (RRL) configured with aslipratio (commonlyslip 2). Rather than sending full answers or dropping every rate-limited packet silently, the server responds to every $N$th rate-limited query with a tiny UDP header carrying theTC=1flag and zero answer payload—eliminating any amplification factor.Proving Client Authenticity via the TCP Handshake
When a spoofed victim IP receives an unsolicitedTC=1packet, it ignores it, ending the exchange cleanly. When a genuine recursive resolver receivesTC=1, it initiates a TCP three-way handshake (SYN→SYN-ACK→ACK). Completing that handshake requires echoing randomized TCP sequence numbers, proving the client controls its source IP address before the DNS server transmits the full response.
By selectively forcing suspicious UDP traffic onto TCP, operators neutralize spoofed amplification floods while preserving uninterrupted resolution for real clients.
IETF RFC Specifications for DNS over UDP and TCP
The transport behaviors, fallback mechanics, and network mandates described above are formally standardized across five core Internet Engineering Task Force (IETF) documents:
- RFC 1035 (Domain Names — Implementation and Specification, Section 4.2): Defines the baseline protocol architecture for DNS over UDP (Section 4.2.1) and TCP (Section 4.2.2) on port 53. Establishes the legacy 512-byte UDP payload limit, the
TCheader bit, and the mandatory two-octet length field framing DNS messages over TCP streams. - RFC 1123 (Requirements for Internet Hosts — Application and Support, Section 6.1.3.2): Establishes early host compliance rules, requiring all DNS resolvers and servers to support UDP queries, mandating TCP for zone transfers, and recommending (“SHOULD”) TCP support for truncated standard queries.
- RFC 7766 (DNS Transport over TCP — Implementation Requirements): Obsoletes RFC 5966 and formally updates RFC 1035 and RFC 1123. Upgrades DNS-over-TCP support from optional (“SHOULD”) to mandatory (“MUST”) for all compliant recursive resolvers and authoritative name servers. Defines persistent TCP connection reuse, in-flight query pipelining, and out-of-order response processing.
- RFC 7828 (The edns-tcp-keepalive EDNS0 Option): Specifies the
edns-tcp-keepaliveoption code, enabling DNS clients and servers to negotiate dynamic idle timeouts on persistent TCP connections and avoid premature socket teardown. - RFC 9210 (DNS Transport over TCP — Operational Requirements, BCP 235): Codifies Best Current Practice for network operators, mandating that enterprise networks, ISPs, firewalls, and middleboxes permit DNS traffic over both UDP and TCP on port 53 without arbitrary TCP filtering.
Under current IETF standards, any DNS software implementation or network path that blocks or omits TCP port 53 is officially non-compliant.
Do Encrypted DNS Protocols (DoT, DoH, and DoQ) Use TCP or UDP?
While RFC 7766 and RFC 9210 govern classic plaintext DNS on port 53 (often called Do53), modern encrypted DNS standards redesign transport selection altogether to provide confidentiality and integrity. Notice how recent standards have evolved from TCP-based TLS wrappers back toward UDP via QUIC:
| Protocol | Transport Layer | Default Port | IETF Standard | Connection & Latency Behavior |
|---|---|---|---|---|
| Classic DNS (Do53) | UDP (default) & TCP (fallback / AXFR) | 53 | RFC 1035 / RFC 7766 | Stateless 1-RTT lookups over UDP; switches to stateful TCP streams on TC=1 or zone transfers. |
| DNS over TLS (DoT) | TCP only | 853 | RFC 7858 | Wraps DNS streams in TLS 1.2/1.3 over dedicated TCP port 853; requires connection reuse to offset handshake cost and suffers from TCP head-of-line blocking on packet loss. |
| DNS over HTTPS (DoH — HTTP/2) | TCP | 443 | RFC 8484 | Tunnels DNS queries inside standard HTTPS over TCP; blends with web traffic through restrictive firewalls while sharing HTTP/2’s TCP-level head-of-line blocking limitation. |
| DNS over HTTPS (DoH — HTTP/3) | UDP (via QUIC) | 443 | RFC 8484 / RFC 9114 | Runs HTTPS over QUIC datagrams on UDP; supports 0-RTT/1-RTT encrypted session resumption and independent stream multiplexing without head-of-line blocking. |
| DNS over QUIC (DoQ) | UDP (via QUIC) | 853 | RFC 9250 | Runs DNS directly over QUIC on UDP without HTTP framing overhead; pairs UDP low latency with built-in TLS 1.3 encryption, anti-spoofing address validation tokens, and arbitrary payload sizes. |
QUIC-based protocols (DoQ and HTTP/3 DoH) effectively resolve DNS’s forty-year TCP-versus-UDP trade-off by delivering encryption, spoofing resistance, and large-message streaming directly atop UDP.
Firewall Rules for Port 53: Should You Allow Both TCP and UDP?
Even as encrypted DNS grows on ports 443 and 853, port 53 remains the backbone of internal enterprise networks, server-to-resolver communication, and public authoritative zones. Misconfigured port 53 firewall rules remain one of the most common causes of phantom network outages.
Must network and host firewalls allow both UDP and TCP on port 53?
Yes. A persistent legacy myth claims that UDP port 53 handles all DNS lookups while TCP port 53 is only needed for authoritative zone transfers (AXFR). In reality, anywhere plaintext DNS queries are permitted, both UDP/53 and TCP/53 must be open in matching directions, as required by RFC 9210.
What breaks if TCP port 53 is blocked while UDP port 53 is open?
Blocking TCP port 53 causes deceptive, intermittent resolution failures rather than a clean outage. Routine A and AAAA queries with compact replies continue to work over UDP, leading administrators to assume DNS is healthy. Meanwhile, queries returning large payloads—such as DNSSEC-signed government or banking domains, CDN record sets, or large TXT/SPF/DKIM lookups performed by mail gateways—receive TC=1 over UDP, attempt to retry on TCP port 53, hit the firewall block, and hang until the application times out.
How should inbound and outbound port 53 rules be scoped by system role?
- Workstations and Application Servers (Stub Clients): Permit outbound
UDP/53andTCP/53exclusively to approved internal DNS resolvers, and block direct outbound port 53 to the internet to prevent malware DNS tunneling and enforce split-horizon policies. Deny all inbound port 53. - Internal Recursive Resolvers: Permit inbound
UDP/53andTCP/53from internal client subnets. Permit outboundUDP/53andTCP/53to0.0.0.0/0and::/0(if performing root/iterative resolution) or strictly to designated upstream forwarders. - Public Authoritative Name Servers: Permit inbound
UDP/53andTCP/53from the entire internet (0.0.0.0/0and::/0) so external resolvers can complete truncated retries. Never block TCP 53 at the perimeter firewall to protect zone data; instead, lock downAXFR/IXFRinside the DNS server configuration using strict secondary IP access control lists (ACLs) and cryptographic TSIG keys.
Treating UDP 53 and TCP 53 as an inseparable pair in firewall policy—while delegating zone-transfer access control to TSIG and daemon ACLs—prevents hard-to-diagnose lookup timeouts.
How to Test DNS Over TCP vs. UDP from the Command Line
After applying firewall rules or deploying a DNS server, verify both transports independently from the command line. Note that dig automatically retries truncated UDP replies over TCP unless explicitly instructed otherwise with +ignore.
# --- dig (Linux / macOS / BIND Utilities) ---
# Explicitly force a DNS query over TCP (+tcp or +vc)
dig @<DNS_SERVER_IP> <DOMAIN> TXT +tcp
# Explicitly test UDP only and suppress automatic TCP retry on truncation
dig @<DNS_SERVER_IP> <DOMAIN> TXT +notcp +ignore
# Force a small EDNS0 buffer (512 bytes) over UDP to verify TC=1 flag behavior
dig @<DNS_SERVER_IP> <DOMAIN> DNSKEY +bufsize=512 +notcp +ignore
:: --- nslookup (Windows / Linux / macOS) ---
:: Force TCP (virtual circuit) for a single lookup
nslookup -vc -type=TXT <DOMAIN> <DNS_SERVER_IP>
:: Explicitly query over UDP (no virtual circuit)
nslookup -novc -type=A <DOMAIN> <DNS_SERVER_IP>
# --- PowerShell (Windows) ---
# Force DNS resolution strictly over TCP
Resolve-DnsName -Name <DOMAIN> -Server <DNS_SERVER_IP> -Type TXT -TcpOnly
# Default lookup (attempts UDP first; falls back to TCP automatically on TC=1)
Resolve-DnsName -Name <DOMAIN> -Server <DNS_SERVER_IP> -Type A
When inspecting dig output, confirm the active transport in the SERVER footer line ((TCP) vs. (UDP)) and check the flags: line in the header for tc when testing UDP truncation limits.
Best Load Balancers for Mixed TCP and UDP Port 53 Traffic
Once both protocols are verified, production DNS deployments must distribute traffic across redundant backend servers. Standard HTTP/Layer-7 application load balancers cannot handle plaintext DNS, and many basic Layer-4 proxies struggle to bind both UDP/53 and TCP/53 to the same virtual IP (VIP). The following load balancers are purpose-built or proven for dual-protocol port 53 workloads:
PowerDNS
dnsdist
A purpose-built, DNS-aware Layer-7 load balancer engineered specifically to handle concurrent UDP and TCP port 53 traffic alongside DoT, DoH, and DoQ.dnsdistparses DNS headers at wire speed, enforces per-client rate limiting andTC=1slip policies, caches responses in memory, and routes queries dynamically by domain name or query type.NGINX (
ngx_stream_core_module)
Supports simultaneous Layer-4 TCP and UDP load balancing on a shared IP by pairinglisten 53;andlisten 53 udp;directives pointing to upstream server pools. It is a strong fit for infrastructure teams already standardized on NGINX that need reliable active health checks and least-connections balancing without deep DNS packet scripting.AWS Network Load Balancer (NLB)
Provides a nativeTCP_UDPlistener protocol built specifically for cloud DNS architectures. A single static IP per Availability Zone accepts both UDP and TCP port 53 queries simultaneously and forwards them to a unified target group with ultra-low latency and client source IP preservation.Linux IPVS / Keepalived (LVS)
Operates directly inside the Linux kernel to load-balance bothUDP/53andTCP/53on a shared Anycast or local VIP. Supporting Direct Server Return (DSR), IPVS allows large DNSSEC or TCP responses from backend resolvers to return directly to clients without bottlenecking the load balancer node.Envoy Proxy
Combines concurrent UDP listener pipelines, TCP proxy listeners, and an extensible Layer-7 DNS filter. Envoy suits cloud-native and Kubernetes environments that want unified Prometheus telemetry and dynamic service-discovery integration across mixed DNS transports.
Choosing a load balancer capable of sharing a single VIP across both UDP and TCP listeners ensures TCP retries land seamlessly on the exact same service endpoint as initial UDP queries.
Conclusion
DNS is neither exclusively a UDP protocol nor exclusively a TCP protocol—it is a dual-transport system designed to extract the best traits from each. UDP handles the vast majority of routine lookups on port 53 in a single stateless round-trip, while TCP steps in seamlessly whenever responses outgrow safe 1,232-byte unfragmented UDP buffers, zone transfers demand lossless replication, or RRL defenses challenge suspected IP spoofers. Meanwhile, modern encrypted protocols like DoQ and HTTP/3 DoH are bringing those worlds together by layering reliable, encrypted streaming over UDP via QUIC. Whether you are writing firewall policies, debugging TC=1 retries with dig +tcp, or deploying port 53 load balancers, treating UDP and TCP as equal, mandatory halves of DNS is essential for fast and resilient name resolution.












Comments