Wikipedia states that underscores are used by both Android and Microsoft Windows Systems in hostnames. My question is, what are these host names? Do you have examples of these strange hostnames names and what they are used for?
-
2Just wanted to let you know that, no, _ is not a valid character in a hostname, even though it is perfectly legal in a DNS record. As an example on why you should not accept it, Java, .Net, Zend PHP, Ruby and many more will throw when trying to parse (eg when making a request) a url containing a hostname with a _ in it. – Sean Kinsey Jul 03 '12 at 05:01
4 Answers
What are host names?
Analogous to a school class room where each student has a roll number/id so that he/she is identified, in the class room of Internet (or for that matter any computer network) each device that are in the network needs to be uniquely identified. This is done via a Host Name. Thus hostnames are names that helps in identifying devices in a network.
Hostnames with underscore(_) character.
During the period when the standards were being laid for the valid and invalid hostnames
, the common terminal interface was the keyboard of the Teletype (TTY) ASR-33. Now this keyborad never had a underscore(_) key in it (check this pic http://www.pdp8.net/asr33/pics/kbd_top.shtml?large) and hence it was not possible to have a hostname
with an underscore(_) in it. Check this link for more details: http://www.quora.com/Domain-Name-System-DNS/Why-are-underscores-not-allowed-in-DNS-host-names
Underscore(_) character can be used in the domain names. As this post states Can (domain name) subdomains have an underscore "_" in it? it is completely valid to have an underscore. Some examples(as shown in the post) are _jabber._tcp.gmail.com
or _sip._udp.apnic.net
. Another example of usage of an underscore is seen here http://ideaharbor.org/notes/technical/enabling-chat-outside-google-apps. Though its valid to use underscores it not a recommended practice.
The wikipedia link in your post states that Microsoft Windows and Android smartphones does not enforce the rule against using an underscore in hostnames. Non enforcement of this rule may result in problems because many systems reject such kind of hostnames.
Hope you get something out of this explanation.
EDIT
On further investigation on the issue, I came upon this wonderful post which I suppose clarifies the usage of underscore in hostnames:
http://networkadminkb.com/KB/a156/windows-2003-dns-and-the-underscore.aspx

- 1
- 1

- 18,352
- 4
- 28
- 28
-
Do you know of any windows specific usages of the `_` in host names? I feel like some M$ magic might also use this feature. – rook Jun 27 '12 at 01:29
-
re: that link - there's some question as to whether RFC 2181 actually does apply to hostnames. I know one of the authors and am awaiting his response. – Alnitak Jun 29 '12 at 20:14
-
This is actually not correct - it is allowed to have _ in DNS records, but not in hostnames - that some DNS records represent hostnames (A, CNAME) does not mean that all do (_jabber, _tcp). Most major frameworks will not allow _ in hostnames, including .Net, Java, Ruby, Zend PHP and more. – Sean Kinsey Jul 03 '12 at 04:47
-
1The networkadminkb link is broken. This wayback machine link does work as an alternative: https://web.archive.org/web/20130504144642/http://networkadminkb.com/KB/a156/windows-2003-dns-and-the-underscore.aspx – Kristof Neirynck Sep 28 '21 at 12:18
-
I got an error when trying to use `_` in a database hostname for `postgres` in `docker`. – FreeSoftwareServers Aug 28 '22 at 03:47
Hostnames (including the domain component(s)) are only allowed to contain alphabetic characters, numeric characters, hyphen and period. This was originally specified in RFC 952 and updated in RFC 1123. The wikipedia article linked in the question says that Android and Windows allow the use of hostnames which violate this syntax.
Such names are definitely invalid hostnames but they are explicitly valid DNS records, even if they are address records which typically contain hostnames. I don't know of an example of a hostname in the wild which uses underscores. Why is this allowed? As explained in the "Name Syntax" section of RFC 2181, DNS intended to be a generic naming service so it doesn't try to enforce all the different name syntaxes that might apply to individual record types.
So even though underscores are disallowed in hostnames, the question of whether a program should allow them is more subtle. In the context of DNS, underscores MUST be allowed. If you are setting the hostname of a particular machine, they should definitely be disallowed because they are invalid. If you are using a hostname, say to access a URL, I guess you could argue that you should allow it if it resolves, in an effort to "be liberal in what you accept".

- 8,717
- 1
- 31
- 35
-
I realize that many of these points were made in other answers, but I didn't see any that synthesize these or that focus clearly enough on the distinction between a valid domain name in DNS and a valid hostname. – John Watts Jul 01 '12 at 18:03
Your reading of the Wikipedia page is incorrect. It does not say that those systems use underscores, it says that they support underscores.
If the administrator of such a system was to use an underscore when configuring it then it's his own fault when it fails to interoperate with the rest of the world.
hostnames are the {fully qualified} names used in (usually DNS) name resolution. The underscore whilst apparently allowed does not conform to the appropriate rfc regarding allowable characters and could raise incompatibility issues if used outside the local environment.
Perhaps Windows has this as a Netbios/Netbeui hangover from the 90's.

- 696
- 3
- 7
- 15