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

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

问题描述

我看到几个人提到DNS名称(域名)的最大字符串长度是253个字符。维基百科似乎是指这个旧博客:



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



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


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


根据RFC1035,域名为组成如下:


表示为一系列标签的域名,其中每个标签由长度为八位字节,后跟该数量的八位字节组成。域名以零长度字节终止为根的空标签。注意,该字段可以是奇数个八位字节;没有使用填充。


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


$ b $标签名称( LL ):1字节
  • 标签名称( LN ): 63字节(最大)
    ,因为标签长度最大值只能为00111111(因为
    ,两个第一位被保留用于特殊功能,如指针)

  • Null Label ( NL ):1个字节(代表根域)

  • 格式应该是(不像博客文章):



    LL + LN [ LL + LN



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



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



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



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



    我想念什么,还是应该更新几个维基百科的参考?唯一不确定的部分是关于Null Label是255个字节的一部分。

    解决方案

    域名 abcde 将被认为是五个字符长。怀疑没有多少人会发现这种计数方式有用。这种计数方式也使得最大长度随着标签数量的不同而变化,因此当您有四个标签时,最大长度为250个字符,但如果您有127个标签,则最大长度只有127个字符。



    以这种方式想想:当我们打印一个域名供人类使用时,我们打印长度字节,只是我们打印它们作为周期(都是第一个长度字节)。如果我们没有,我们将无法区分 a.b.c。 abc。之间的区别。因为我们打印它们,所以当我们计算长度时,应该包括它们。通过这种计数方式,最大长度总是253个字符(包括最后一个时间段,而非打印的零字节为255)。



    在其他单词,如果最多有250个ASCII字符(字母,数字,破折号),考虑到标签的最小数量为4,您还需要在它们之间添加3个可打印点,最多可打印253个可打印字符第一个长度字节和空白标签)。



    下面的示例(粗体是可打印的字符,LL被打印为点):


    $ b LL(1)+ LN(63) + LL(1) + LN(63) + (1) + LN(63) + LL(1) + LN(61) + NL(1)= 255



    所以包含点的新计算将成为:



    63 + 1 + 63 + 1 + 63 + 1 + 61 = 25 3 / p>

    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/Hostname http://blogs.msdn.com/b/oldnewthing/archive/2012/04/12/10292868.aspx

    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:

    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.

    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. 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

    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 bytes

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

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

    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.

    解决方案

    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.

    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).

    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).

    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 bytes

    So the new calculation including dots will become:

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

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

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