DNS 名称的最大长度是多少 [英] What is the maximum length of a DNS name

查看:44
本文介绍了DNS 名称的最大长度是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到好几次提到 DNS 名称(域名)的最大字符串长度是 253 个字符.维基百科似乎在引用这篇旧博文:

I saw several mentions that the maximum string length of a DNS name (domain name) is 253 characters. Wikipedia seems to be referring this old blog post:

https://en.wikipedia.org/wiki/Hostnamehttp://blogs.msdn.com/b/oldnewthing/archive/2012/04/12/10292868.aspx

另一方面,如果我理解RFC,这篇文章是错误的.DNS 名称最大字符串长度应为 250 个 ASCII 字符而不是 253 个基于以下字节序列,根据 RFC1035 最大为 255 个字节:

On the other hand, if I understood the RFC, this article is wrong. DNS name maximum string length should be 250 ASCII characters instead of 253 based on the following byte sequence which as per RFC1035 is maxed to 255 bytes:

为了简化实现,域名的总长度(即标签八位字节和标签长度八位字节)限制为 255 个八位字节或少.

To simplify implementations, the total length of a domain name (i.e., label octets and label length octets) is restricted to 255 octets or less.

按照RFC1035,域名的组成如下:

As per RFC1035, the domain names is composed as follows:

表示为标签序列的域名,其中每个标签由一个长度的八位字节和该数量的八位字节组成.域名以根的空标签的零长度八位字节结束.请注意,该字段可能是奇数个八位字节;不使用填充.

a domain name represented as a sequence of labels, where each label consists of a length octet followed by that number of octets. The domain name terminates with the zero length octet for the null label of the root. Note that this field may be an odd number of octets; no padding is used.

这意味着以下字段组成了域名:

Which means that the following fields make up domain names:

  1. 标签长度 (LL):1 字节
  2. 标签名称 (LN):63 字节(最大)因为标签长度最大值只能是 00111111(因为前两个位保留用于特殊功能,如指针)
  3. 空标签 (NL):1 个字节(代表根域)
  1. Label Length (LL): 1 byte
  2. Label Name (LN) : 63 bytes (maximum) because the label length maximum value can only be 00111111 (since the two first bits are reserved for special functionalities like pointers)
  3. Null Label (NL) : 1 byte (representing the root domain)

格式应始终为(与博客文章不同):

The format should always be (unlike the blog post):

LL + LN [ LL + LN ... ] + NL>

LL + LN [ LL + LN ... ] + NL

这意味着最大长度应该是(1 个字节 = 1 个字符 = 1 个八位字节):

Which means the maximum length should be (1 byte = 1 character = 1 octet):

LL (1) + LN (63) + LL (1) + LN (63)+ LL (1) + LN (63) LL (1) + LN (61) + NL (1) = 255 字节

LL (1) + LN (63) + LL (1) + LN (63) + LL (1) + LN (63) LL (1) + LN (61) + NL (1) = 255 bytes

所以如果我们只计算字符串部分(LNs),我们得到:

So if we calculate the string part only (LNs), we get:

63 + 63 + 63 + 61 = 最多 250 个字符.

63 + 63 + 63 + 61 = 250 characters maximum.

我是否遗漏了什么,或者我们应该更新一些维基百科参考资料?我唯一不确定的部分是 Null 标签是 255 个字节的一部分.

Did I miss anything or we should be updating a few Wikipedia references? The only part I'm unsure is about the Null Label being part of the 255 bytes.

推荐答案

按照您的计算方式,域名 a.b.c.d.e. 将被认为是五个字符长.它怀疑没有多少人会发现这种计数方式有用.这种计数方式也使最大长度随着标签的数量而变化,因此当您有四个标签时,最大长度为 250 个字符,但如果您有 127 个标签,则最大长度仅为 127 个字符.

With your way of counting, the domain name a.b.c.d.e. would be considered to be five characters long. It suspect that not many people will find that way of counting useful. That way of counting also makes the maximum length vary with the number of labels, so when you have four labels the maximum length is 250 characters, but if you have 127 labels the maximum length is only 127 characters.

这样想:当我们打印供人类使用的域名时,我们确实打印长度字节,只是我们将它们打印为句点(除了第一个长度字节之外的所有字符)).如果我们不这样做,我们将无法区分 a.b.c.abc. 之间的区别.由于我们打印它们,因此在计算长度时应该包括它们.以这种方式计算,最大长度始终为 253 个字符(包括最后一个句点,根的非打印零八位字节为 255).

Think of it this way: when we print a domain name for human use, we do print the length bytes, it's just that we print them as periods (all of them but the first length byte). If we didn't, we wouldn't be able to tell the difference between a.b.c. and abc.. Since we print them, they should be included when we count the length. And with that way of counting, the maximum length is always 253 characters (including the final period, and the non-printed zero octet for root makes 255).

换句话说,如果您有最多 250 个 ASCII 字符(字母、数字、破折号),考虑到标签的最小数量是 4,您还需要在它们之间添加 3 个可打印的点,总计为 253可打印字符(省略第一个长度字节和空标签).

In other words, if you have a maximum of 250 ASCII characters (letters, numbers, dash), considering that the minimum number of label is 4, you will need to also add 3 printable dots between them which sums up to 253 printable characters (ommited the first length byte and the null label).

示例如下(粗体是可打印的字符,LLs 打印为点):

Example below (bold are printable characters, and LLs are printed as dots):

LL (1) + LN (63) + LL (1) + LN (63) + LL (1)) + LN (63) + LL (1) + LN (61) + NL (1) = 255 个字节

LL (1) + LN (63) + LL (1) + LN (63) + LL (1) + LN (63) + LL (1) + LN (61) + NL (1) = 255 bytes

所以包括点的新计算将变成:

So the new calculation including dots will become:

63 + 1 + 63 + 1 + 63 + 1 + 61 = 最多 253 个字符.

63 + 1 + 63 + 1 + 63 + 1 + 61 = 253 characters maximum.

这篇关于DNS 名称的最大长度是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆