Why DNS uses UDP as the transport layer protocol?

18,149

Solution 1

  • UDP is much faster. TCP is slow as it requires 3 way handshake. The load on DNS servers is also an important factor. DNS servers (since they use UDP) don’t have to keep connections.
  • DNS requests are generally very small and fit well within UDP segments.
  • UDP is not reliable, but reliability can be added on application layer. An application can use UDP and can be reliable by using timeout and resend at application layer.

You can read it here: https://www.geeksforgeeks.org/why-does-dns-use-udp-and-not-tcp/

Solution 2

UDP is cheap. UDP itself is not reliable, but higher level protocols — as DNS — may maintain reliability, e.g. by repeating the UDP datagram in the case of no response.

But the last is not the case for DNS. DNS itself uses sometimes besides UDP (as its primary protocol) the reliable Transmission Control Protocol (TCP), too.

The last is used when the response data size exceeds 512 bytes, and for tasks which require the reliable delivery (e.g. zone transfers).

Moreover, there are some resolver implementations that use TCP for all queries.

Share:
18,149

Related videos on Youtube

Ada S
Author by

Ada S

Updated on June 15, 2022

Comments

  • Ada S
    Ada S about 2 years

    Why DNS uses UDP as the transport layer protocol?

    • Ry-
      Ry- over 7 years
      Most queries fit into one message. You can re-send the message if you don’t get an answer. Less overhead than TCP.
  • MarianD
    MarianD almost 7 years
    3 notes to your answer: 1) DNS uses not only UDP - sometimes it uses TCP, too. 2) The slowness of TCP lies mainly not in the connection establishment (which in turn is not only the 3-way handshake). 3) Reliability can be added on higher layers but it is not the case of DNS.
  • Aman Gupta
    Aman Gupta over 5 years
    how dns can use tcp. please explain @MarianD ??? As the response time will increase
  • MarianD
    MarianD over 5 years
    @AmanGupta, see the last two paragraphs in my answer, please.
  • Tom Burrows
    Tom Burrows over 3 years
    This answer has been plagiarised, typos included, here: geeksforgeeks.org/why-does-dns-use-udp-and-not-tcp
  • Matthias Hamann
    Matthias Hamann over 3 years
    Yes I got it from another source, whether it was I don't remember. I could have named it.