Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum length of a DNS name

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.

like image 426
Nicolas Bouvrette Avatar asked Aug 29 '15 20:08

Nicolas Bouvrette


People also ask

What is the DNS message limit in characters?

Most TXT records can have up to 255 characters. For TXT records that include more than 255 characters, DNS adds multiple strings together in a single record. If you're using a 2048-bit DKIM key, you can't enter it as a single text string in a DNS record with a 255-character limit.

What is the maximum size of a FQDN?

Each label must consist of 1 to 63 characters and the total FQDN may not exceed 255 characters in total. Only letters, numbers, or dashes can be used. Each label has to have either a letter or a number at the beginning.

Why does DNS impose a limit on the key length?

label length The 63-byte limit is because in the DNS protocol, labels stored as , length is a single byte, but two high bits of the length field reserved for something else (compression) thus leaving 6 bits for the length itself, 2^6=64 possible values - 0.. 63.

What is the maximum length of a subdomain?

A subdomain is a domain that is part of a larger domain. Each label may contain from 1 to 63 octets. The full domain name may not exceed a total length of 253 ASCII characters in its textual representation.


1 Answers

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.

like image 148
Calle Dybedahl Avatar answered Sep 23 '22 21:09

Calle Dybedahl