[笔记]Why is UDP used for DNS instead of TCP?

Why is UDP used for DNS instead of TCP?

Isn't TCP supposed to be more reliable (lossless)? Reliability would appear to be of utmost importance in DNS, no?


TCP is used if the size of the packet goes over 512 bytes. Practically this is only used for zone transfers.

It's also faster... Assuming everything works, it's one round trip time for the query and response for UDP, as opposed to 2 for the TCP case because you have to set up the connection first.

Being connectionless means that the server can be much more efficient, because it never has to keep track of any connections or state.

And, as others have pointed out, you just retransmit if you don't get an answer. TCP isn't really lossless, it just guarantees that you know when you've lost something which is an important distinction. And with DNS, that's pretty easy -- you didn't get your answer. TCP would take a while to figure this out, with UDP you can pick your timeout.

所以,一般情况下DNS使用UDP通讯

但是有两种情况例外:

1. 当客户端发出DNS查询请求。从服务器收到的响应报文中的TC(删减标志)比特被置为1时,

此时意味着服务器响应长度超过512 bytes字节,但是udp只能返回512字节。

此时,客户端就需要使用TCP重发原来的DNS查询请求。

2. DNS的主辅名字服务器在同步时使用TCP协议,辅名字服务器一般每小时向主名字服务器发起查询,

看主服务器是否有新的记录变动,如果有,

将执行一次区域传送,区域传送就是使用TCP协议。

原文地址:https://www.cnblogs.com/hoanfir/p/9073728.html