Whether the DNS uses the TCP or UDP protocol

Source: Internet
Author: User

DNS occupies port 53 and uses both TCP and UDP protocols. Under what circumstances does DNS use these two protocols?

DNS uses TCP protocol for regional transmission and UDP protocol for other purposes.

The TCP protocol is used for DNS region transmission:

1. The secondary Domain Name Server regularly queries the Primary Domain Name Server (generally three hours) to check whether the data has changed. If there is any change, a regional transfer will be executed for data synchronization. Area transfer uses TCP instead of UDP, because the amount of data synchronously transmitted is much larger than the amount of data responded to a request.

2. TCP is a reliable connection that ensures data accuracy.

Use UDP protocol for domain name resolution:

The client queries the domain name from the DNS server. Generally, the returned content is no more than 512 bytes. Use UDP for transmission. Without three handshakes, the DNS server has lower load and faster response. Theoretically, the client can also specify TCP when querying the DNS server, but in fact, many DNS servers only support udp Query Packets When configuring.

 

Why does DNS use TCP and UDP?

DNS uses both UDP and TCP port 53 at the same time. This single application protocol uses two transmission protocols at the same time, which is an alternative in the TCP/IP stack. However, few people know under what circumstances DNS uses the two Protocols.

First, we will briefly introduce TCP and UDP.
TCP is a connection-oriented protocol that provides reliable data transmission. This protocol is used when the service quality requirements are high. UDP-User Datagram Protocol (UDP) is a connectionless transport layer protocol that provides a simple and unreliable information transmission service for transactions.

Difference Between TCP and UDP:
The main difference between UDP and TCP is that they differ in how to implement reliable information transmission. The TCP protocol includes a special transmission guarantee mechanism. When the data receiver receives the message from the sender, it will automatically send a confirmation message to the sender; the sender continues to transmit other information only after receiving the confirmation message. Otherwise, the sender waits until the confirmation message is received. Unlike TCP, UDP does not provide a data transmission guarantee mechanism. If a data packet is lost during transmission from the sender to the receiver, the Protocol itself cannot detect or prompt. Therefore, UDP is often called an unreliable transmission protocol. Compared with the TCP protocol, another difference between the UDP protocol is how to receive burst data packets. Unlike TCP, UDP does not guarantee the order in which data is sent and received. In fact, this out-of-order nature of UDP is rarely seen. Generally, it can only happen when the network is very crowded.
Since UDP is an unreliable network protocol, what is its value or necessity? In fact, in some cases, UDP may become very useful. Because UDP has a speed advantage beyond the reach of TCP. Although various security protection functions are embedded in the TCP protocol, a large amount of system overhead will be occupied during actual execution, and the speed will undoubtedly be seriously affected. In contrast, UDP eliminates the information reliable transfer mechanism and transfers security and sorting functions to upper-layer applications, greatly reducing the execution time and ensuring the speed.

DNS uses the TCP protocol for regional transmission, and UDP protocol for other purposes;
The DNS specification specifies two types of DNS servers, one is the primary DNS server and the other is the secondary DNS server. In a zone, the primary DNS server reads the DNS data from the local data file, while the secondary DNS server reads the DNS data from the primary DNS server. When a secondary DNS server is started, it needs to communicate with the primary DNS server and load data information, which is called zone transfer ).

Why both TCP and UDP are used?
First, let's take a look at the limits on the length of TCP and UDP transmission Bytes:
The maximum length of a UDP packet is 512 bytes, while that of a TCP packet exceeds 512 bytes. When the DNS query exceeds 512 bytes, the TC mark of the Protocol is deleted, and then sent over TCP. Generally, traditional UDP packets do not contain more than 512 bytes.

TCP is used for regional transmission. There are two main considerations:
1. The secondary Domain Name Server regularly queries the Primary Domain Name Server (generally 3 hours) to check whether the data has changed. If there is any change, a regional transfer will be executed for data synchronization. Area transfer uses TCP instead of UDP, because the amount of data synchronously transmitted is much larger than the amount of data in a request and response.
2. TCP is a reliable connection that ensures data accuracy.

Use UDP protocol for domain name resolution:
The client queries the domain name from the DNS server. Generally, the returned content is no more than 512 bytes. Use UDP for transmission. The DNS server has lower load and faster response because it does not have to undergo TCP three-way handshake. Although theoretically, the client can also specify to use TCP when querying the DNS server, in fact, many DNS servers only support udp Query Packets When configuring.

UDP 
The main difference between UDP and TCP is that UDP does not necessarily provide reliable data transmission. In fact, this Protocol cannot ensure that the data is accurate to the destination. UDP is very effective in many ways. When a program aims to transmit as much information as possible as soon as possible (where any given data is of relatively low importance), UDP can be used. ICQ short messages use UDP to send messages.
Many programs will use separate TCP connections and separate UDP connections. Important Status information is sent along with reliable TCP connections, while the main data stream is sent over UDP.

TCP
TCP aims to provide reliable data transmission and maintain a virtual connection between devices or services that communicate with each other. TCP is responsible for data recovery when data packets are unordered, lost, or damaged during delivery. It completes the recovery by providing a sequence number for each packet it sends. Remember, each packet is considered as an independent unit at the lower network layer. Therefore, data packets can be sent along completely different paths, even if they are components of the same message. This route is similar to the way the network layer processes segments and reassembles data packets. It is only at a higher level.
To ensure that data is correctly received, TCP requires a confirmation (ACK) when the target computer successfully receives the data ). If the corresponding Ack is not received within a certain time limit, the data packet will be re-transmitted. If the network is congested, this re-transmission will lead to repeated data packets. However, the receiving computer can use the serial number of the data packet to determine whether it is a duplicate data packet and discard it if necessary.

TCPAnd UDP Selection

If we compare the structure of UDP packets and TCP packets, it is obvious that UDP packets do not have the complex reliability and Control Mechanism of TCP packets. Similar to TCP, UDP supports multiple applications on one host as well as the number of source ports and destination ports. A 16-bit UDP packet contains a Byte Length header and Data Length. The verification code field enables it to perform overall verification. (Many applications only support udp, such as multimedia data streams, and do not generate any additional data. Even if you know the damaged packets, do not resend them .)
Obviously, when the performance of data transmission must be in the integrity, controllability, and reliability of data transmission, TCP is certainly the choice. UDP is the best choice for audio and multimedia applications that emphasize transmission performance rather than transmission integrity. When the data transmission time is so short that the previous connection process becomes the whole traffic subject, UDP is also a good choice, such as DNS switching. The reason for establishing SNMP on UDP is that the designer believes that when the network is blocked, the low overhead of UDP gives it a better chance to transmit and manage data. The rich functions of TCP sometimes lead to unpredictable low performance, but we believe that in the near future, reliable point-to-point connections of TCP will be used in most network applications.

TCP (transmission control protocol,Transmission Control ProtocolIs a connection-based protocol, that is, before formally sending and receiving data, you must establish a reliable connection with the other party. A TCP connection can be established only after three "conversations. A simple process of three conversations: host a sends a connection request packet to host B: "Can I send you data ?", This is the first conversation; host B sends a packet to host a that agrees to the connection and requires synchronization (synchronization means that two hosts are sending, receiving, and coordinating): "Yes, when will you send it? ", This is the second conversation. host a sends another packet to confirm that host B's request is synchronized: "I will send it now, let's proceed !", This is the third dialogue. The purpose of the three "dialogs" is to synchronize the transmission and receipt of data packets. After the three "dialogs", host a formally sends data to host B.

UDP (user data protocol,User Datagram ProtocolIs the Protocol corresponding to TCP. It is a non-connection-oriented protocol. Instead of establishing a connection with the other Party, it directly sends data packets!
UDP is applicable to applications that transmit only a small amount of data at a time and do not require high reliability. For example, we often use the "ping" command to test whether the TCP/IP communication between two hosts is normal. In fact, the principle of the "ping" command is to send UDP packets to the other host, then, the host of the other party confirms that the packet is received. If the message indicating whether the packet arrives is returned in time, the network is connected. For example, by default, four data packets (2) are sent during a ping operation ). As you can see, the number of data packets sent is 4 packets, and the number of packets received is also 4 (because the recipient's host will send back a packet to confirm receipt ). This fully demonstrates that UDP is a non-connection-oriented protocol and does not establish a connection. Because the UDP protocol does not have a connection process, its communication performance is high; but also because of this, its reliability is not as high as that of the TCP protocol. Qq uses UDP to send messages, so sometimes messages cannot be received. HTTP is transmitted over TCP.

 

TCPDifferences between the Protocol and UDP protocol

TCP is based on connection-oriented protocol, which ensures reliable data transmission and slow transmission speed. It is suitable for scenarios with high data transmission and reliability requirements.

The UDP Protocol is applicable to non-connection protocols, which make data transmission unreliable and fast. It is suitable for applications that transmit only a small amount of data at a time and have low reliability requirements.

Connection-oriented TCP

"Connection-orientedBefore the formal communication, you must establish a connection with the other party. For example, if you call someone else, you must wait until the line is connected and the other party picks up the microphone to talk to each other.

The TCP protocol can provide reliable communication connections for applications, so that the byte stream sent by a computer is sent to other computers on the network without error. for data communication systems with high reliability requirements, the TCP protocol is often used to transmit data.

 

Non-connection-oriented UDP protocol

"Non-connection oriented"Means you do not need to establish a connection with the other party before the formal communication, regardless of the other Party's status, directly send. This is very similar to the popular mobile phone text message: when you send a text message, you only need to enter the phone number of the other party and then OK.

UDP is applicable to applications that transmit only a small amount of data at a time and do not require high reliability.

UDP protocol is a non-connection-oriented protocol and does not establish a connection. Because the UDP protocol does not have a connection process, its communication performance is high; but also because of this, its reliability is not as high as that of the TCP protocol. Qq uses UDP to send messages, so sometimes messages cannot be received.

TCPApplication Protocols Supported by the Protocol and UDP protocol

TCP supports the following application protocols:Telnet, FTP, SMTPAnd so on;

UDP supports the following application-layer protocols:NFS(Network File System ),SNMP(Simple Network Management Protocol ),DNS(Primary Domain Name System ),TFTP(Common File Transfer Protocol.

 

Both TCP and UDP are in the OSI model.Transport Layer.

TCP advantages: connection-oriented, real-time, just like making a call, the two must establish a connection.
It ensures that what you transmit is accurate, and the recipient wants to give you a reply that you have received or not received. Therefore, it is secure ..
UDP advantages: Non-connection oriented, just like sending a mail to someone, the recipient does not need to wait for your mail at the post office.
Therefore, it is not guaranteed and cannot ensure that you will receive a message. Unlike TCP, It is faster than TCP because it does not need to be received by both parties, there is a confirmation process for the sender.

Whether the DNS uses the TCP or UDP protocol

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.