Can subdomains (domain names) have underscore _
in them?
相关问题
- Find who is hosting a website using PHP
- On Linux, Java issues reverse DNS lookups when a s
- How to balance webserver bandwith usage?
- Are x86 Assembly Mnemonic standarized?
- How to get full host name in C#?
相关文章
- 如何通过命令行测试dns反向解析
- Is there a standard way to store XY data in python
- How do I enable custom domains for my users?
- What is the longest possible email address? [dupli
- performance for searching through 100 million reco
- Build a DNS Proxy in C
- Universal local network name resolution method wit
- W3C document states
A note on terminology, in furtherance to Bortzmeyer's answer
One should be clear about definitions. As used here:
The hostname is subject to the restrictions of RFC 952 and the slight relaxation of RFC 1123
RFC 2181 makes clear that there is a difference between a domain name and a hostname:
So underscores in hostnames are a no-no, underscores in domain names are a-ok.
In practice, one may well see hostnames with underscores. As the Robustness Principle says: "Be conservative in what you send, liberal in what you accept".
A note on encoding
In the 21st century, it turns out that hostnames as well as domain names may be internationalized! This means resorting to encodings in case of labels that contain characters that are outside the allowed set.
In particular, it allows one to encode the
_
in hostnames (Update 2017-07: This is doubtful, see comments. The_
still cannot be used in hostnames. Indeed, it cannot even be used in internationalized labels.)The first RFC for internationalization was RFC 3490 of March 2003, "Internationalizing Domain Names in Applications (IDNA)". Today, we have:
You may also want to check the Wikipedia Entry
RFC 5890 introduces the term LDH (Letter-Digit-Hypen) label for labels used in hostnames and says:
Going back to simpler times, this Internet draft is an early proposal for hostname internationalization. Hostnames with international characters may be encoded using, for example, 'RACE' encoding.
The author of the 'RACE encoding' proposal notes:
Not if you want it to resolve on the Internet.
You cannot have: http://my_subdomain.example.com is invalid.
You can have: http://my-subdomain.example.com with a hyphen.
Individual TLD's can place their own rules & restrictions on domains names as they see fit, such as to accomodate local languages.
For example, according to the CIRA, Canada's
.ca
domain names are allowed:The maximum length is 63 characters, except each accented character reduces that limit by 4 characters.
(Source)
Incidentally, this allows for around 4 Quadragintillion domain name possibilities (not counting sub-domains) for dot-ca domains.
Clarifying bortzmeyer and David Tonhofer, domain name and subdomain name labels can contain leading underscores, but nowhere else.
As David Tonhofer wrote, labels are the in-between-the-periods parts and should follow the LDH rule except when specifying service labels and port labels to differentiate them from regular labels. Then they must occur at the beginning of the label which should be the "Short Names" from the Service Name and Port Number Registry, the port number with no leading 0s, or the protocol (ie. tcp, udp). These service labels are further limited to 15 characters.
Contrary to David Tonhofer's answer, IDN does not allows for encoding underscore ('_' U+005F LOW LINE) or any other invalid ASCII character.
From RFC5890
Punycode encodes all ASCII codepoints as ASCII directly, including underscore. The resulting R-LDH would not conform the the LDH label rules. For example,
Σ_.com
would be encoded asxn--_-zmb.com
which violates the rules. There may be a homographic codepoint which looks like an underscore that can be coded legally (perhaps '_' U+FF3F fullwidth low line), but these kinds of codepoints would be categorized as DISALLOWED by RFC5892 under 2.3 IgnorableProperties as a Noncharacter_Code_Point.RACE (the other proposed IDN encoding scheme) was not accepted as a standard by IETF and should not be used.
There is one additional thing you may need to know: If the host or subdomain part of the url contain an underscore, IE9 (have not tested other versions) cannot write cookies.
So be careful about that. :-)
I followed the link to RFC1034 and read most of it and was surprised to see this:
The labels must follow the rules for ARPANET host names. They must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen. There are also some restrictions on the length. Labels must be 63 characters or less.
For clarification, a domain names are made up of labels which are separated by dots ".". This spec must be outdated because it doesn't mention the use of underscores. I can understand the confusion if anybody stumbles over this spec without knowing it is obsolete. It is obsolete, isn't it?
I followed the link to RFC2181 and read some of it. Especially where it pertains to the issue of what is an authoritative, or canonical, name and the issue of what makes a valid DNS label.
As posted earlier it states there's only a length restriction then to sum it up it reads:
(about names and valid labels)
These are already adequately specified, however the specifications seem to be sometimes ignored. We seek to reinforce the existing specifications.
Kind of leaves me wondering if "a length only restriction" is "adequate". Are we going to start seeing domain names like @#$%!! soon? Isn't the internet screwed up enough?