is DNS using TCP or UDP?

Source: Internet
Author: User

DNS concurrently consumes UDP and TCP port 53 is generally accepted, this single application protocol uses two kinds of transport protocol in the case of the TCP/IP stack is also a kind of alternative. The following describes the conditions under which DNS is used in each of the two protocols.

Introduction to TCP and UDP
TCP is a connection-oriented protocol that provides reliable data transfer, and the general quality of service requirements are relatively high, using this protocol. UDP---User Datagram Protocol, which is a non-connected Transport layer protocol, provides a simple and unreliable information delivery service for transaction.

the difference between TCP and UDP
The main difference between UDP and TCP protocols is that they differ in how to achieve reliable transmission of information. The TCP protocol includes a special delivery guarantee mechanism that automatically sends a confirmation message to the sender when the data receiver receives the message from the sender, and the sender will continue to send additional information only after receiving the acknowledgement, otherwise it waits until the confirmation message is received. Unlike TCP, the UDP protocol does not provide a guarantee mechanism for data transfer. If the datagram is lost during delivery from the sender to the receiver, the protocol itself is not capable of making any detection or prompting. Therefore, the UDP protocol is often referred to as an unreliable transport protocol. In contrast to the TCP protocol, another difference in the UDP protocol is how to receive bursts of multiple datagrams. Unlike TCP,UDP, there is no guarantee of the order in which data is sent and received. In fact, this sort of chaos in the UDP protocol is rarely seen, and is usually only possible if the network is very congested.
Since UDP is an unreliable network protocol, what value or necessity is there? In some cases, the UDP protocol may become very useful. Because UDP has the speed advantage that TCP can not catch. Although a variety of security features are embedded in the TCP protocol, the actual execution of the system consumes a lot of overhead, which undoubtedly makes the speed seriously affected. In view of the elimination of the information reliable transmission mechanism, the security and sequencing functions are transferred to the upper application to complete, greatly reducing the execution time, so that the speed is guaranteed.

DNS uses the TCP protocol while the zone is being transferred, and the UDP protocol is used at other times;
The DNS specification specifies 2 types of DNS servers, one called the primary DNS server, and one called the secondary DNS server. In a zone, the primary DNS server reads the DNS data information for the zone from its own native data file, while the secondary DNS server reads the DNS data information for that zone from the primary DNS server in the zone. When a secondary DNS server is started, it needs to communicate with the primary DNS server and load the data information, which is called zone transfer (zone transfer).

Why use both TCP and UDP?
First look at the length limit for TCP and UDP delivery bytes:
The maximum length of a UDP message is 512 bytes, while TCP allows the message to be longer than 512 bytes.
When the client issues a DNS query request, the TC (deletion flag) bit in the response message received from the server is set to 1 o'clock, which indicates that the total answer length is more than 512 bytes, only the first 512 bytes are returned, and then DNS needs to use TCP to re-send the original query request. Because in a UDP application, its application is limited to 512 bytes or less, so the DNS packets can only have 512 bytes of traffic, and TCP can divide the user's traffic into segments, so TCP can use more than 512 bytes of data stream or any length of data stream.


TCP is used for zone transfer, with the following two points in mind:
1. The secondary name server will periodically (typically 3 hours) query the primary nameservers to see if the data is changed. If there is a change, a zone transfer is performed and the data is synchronized. Zone transfers will use TCP instead of UDP, because the amount of data that is transferred synchronously is much larger than the amount of data requested and answered.
The 2.TCP is a reliable connection that guarantees the accuracy of the data.

The UDP protocol is used for domain name resolution:
The client queries the DNS server for domain names, and generally returns no more than 512 bytes, which can be transmitted with UDP. There is no TCP three handshake, so the DNS server loads less and responds faster. While it is theoretically possible for a client to specify TCP when querying to a DNS server, in fact, many DNS servers are configured to support only UDP query packets.

In layman's terms, TCP is used when transferring between DNS servers, and UDP is used when transferring between the client and the DNS server.

is DNS using TCP or UDP?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.