51

Possible Duplicate:
Is it true that a nameserver have to answer queries over TCP?

I know DNS uses UDP for most of its queries, but in what circumstances will it use TCP instead?

1
  • 2
    The Stack Exchange sites are not forums. They are Q&A sites. Please see the FAQs for why that matters. The "closed as exact dupe" question isn't the same Question, but has the same answer, and Alnitak is pretty much a DNS demi-god.
    – Chris S
    Jul 4, 2012 at 22:02

2 Answers 2

49

DNS uses TCP when the size of the request or the response is greater than a single packet such as with responses that have many records or many IPv6 responses or most DNSSEC responses.

The maximum size was originally 512 bytes but there is an extension to the DNS protocol that allows clients to indicate that they can handle UDP responses of up to 4096 bytes.

DNSSEC responses are usually larger than the maximum UDP size.

Transfer requests are usually larger than the maximum UDP size and hence will also be done over TCP.

10
  • 8
    DNSSEC does not do any certificate negotiation! The resource records added for DNSSEC are no different than other resource records. DNSSEC works just fine over UDP and will only resort to TCP when the response is too large (compare dig +dnssec @a.gtld-servers.net com. any and dig +dnssec @a.gtld-servers.net com. dnskey)
    – Cakemox
    Jul 4, 2012 at 21:59
  • Indeed, I stand corrected. That second query certainly did work just fine over UDP. I'll amend my answer.
    – Ladadadada
    Jul 4, 2012 at 22:14
  • 1
    Are requests larger than 512 something that happens in practice, or is it merely a theoretical case? I can't think of a valid DNS request which wouldn't fit in 512 bytes.
    – kasperd
    May 16, 2015 at 21:13
  • @kasperd ANY queries are notorious for producing large packets, which is why they're often used in DNS amplification attacks. With EDNS0, attackers try to send a small query that produces a response size just under the standard 4096 byte limit.
    – Zenexer
    Apr 27, 2016 at 3:19
  • 1
    RFC 2671 See also Wikipedia
    – Ladadadada
    Mar 26, 2017 at 19:57
10

The Transmission Control Protocol (TCP) is used when the response data size exceeds 512 bytes, or for tasks such as zone transfers.

https://en.wikipedia.org/wiki/Domain_Name_System#DNS_transport_protocols

Not the answer you're looking for? Browse other questions tagged or ask your own question.