为什么 QNAME 字段的内容不是 DNS 消息中的原始域?

Why is the content of QNAME field NOT the original domain in a DNS message?

为什么 QNAME 字段的内容不是 DNS 消息中的原始域?

比如我想获取域www.mydomain.com的IP,我会向网络发送一个DNS查询包,包的问题部分包含域

但实际上QNAME包中的内容是3www8mydomain3com0而不是www.mydomain.com.

3www8mydomain3com0表示每个标签都以该部分的长度开始,然后是内容,以长度0结束。

那么,为什么我们使用长度+数据模式来描述域而不是原始域?

看看这部分4.1.2. Question section format描述了我们如何在RFC1035上定义域记录(请搜索以查看这部分)。

1) DNS 不知道 URLs。 DNS 比 URL.

的概念更早

2) 因为这就是 DNS 的有线格式的工作原理。您看到的是域名 www.mydomain.com,以 DNS 二进制格式编码。 Length+data是一般情况下很常见的字符串存储方式

(域名更改为让 Stack Overflow 关闭无法命名的域。)

For example, if I want to get the IP of domain www.qqqqsovr.com, I will send a DNS lookup package to the network, and the package's question section contains this url.

那不是 URL,它是一个域名。域名是 URL 的 部分 ,但 URL 类似于 http://www.qqqqsovr.com/homepage.html.

But actually the content of QNAME in the package is 3www8qqqqsovr3com0 instead of www.qqqqsovr.com.

www.qqqqsovr.com。正如 Calle Dybedahl 所说,这是因为名称的编码形式有些复杂。 RFC 1035 的第 3.1 节“名称 space 定义”说:

Domain names in messages are expressed in terms of a sequence of labels. Each label is represented as a one octet length field followed by that number of octets. Since every domain name ends with the null label of the root, a domain name is terminated by a length byte of zero. The high order two bits of every length octet must be zero, and the remaining six bits of the length field limit the label to 63 octets or less.

并且名称的那些单独位可以由其他名称指向,因此,例如,如果您在 DNS 消息中同时具有 www.qqqqsovr.comwww.abcdefgh.com,则第二个域名可以指向第一个域名的.com;这在 RFC 1035 的第 4.1.4 节“消息压缩”中有所描述。

简单地将域字符串作为文本字符串放入消息中是不允许压缩的;您需要 一些 方式来表达指针。您可能不得不问 Paul Mockapetris 为什么他(和 Jon Postel)选择使用那种 特定的 编码。

即使在那里,字符串长度也必须以某种方式 指示,可以通过计数或 null-termination。 1987 年,虽然 UNIX 计算机在 Internet 上很常见,但据我所知,它们并不 如此 常见,因此 null-termination 是一个“显而易见的”选择。