Is it valid for a hostname to start with a digit?
Is it valid for a hostname to start with a digit? e.g. 8server
From reading RFC 1123 it would appear that this is a valid hostname. However, I'm not clear on whether a hostname can only start with a digit when there is a suffix e.g. 8server.com
The origin of this question is that InternetDomainName.isValid("8server");
in the Google Guava library (Javadoc) rejects the input. I also posted a specific question on the Guava Discuss group.
RFC 1123 relaxes a constraint of RFC 952 which specifies a legacy of the Hostname Server Protocol (described in RFC 953) replaced by DNS. So a fully numeric hostname would be valid per these RFCs.
RFC 1123 itself discusses consequences when it comes to IP versus hostname parsing :
If a dotted-decimal number can be entered without such identifying delimiters, then a full syntactic check must be made, because a segment of a host domain name is now allowed to begin with a digit and could legally be entirely numeric (see Section 6.1.2.4). However, a valid host name can never have the dotted-decimal form #.#.#.#, since at least the highest-level component label will be alphabetic.
However, it was provided in RFC 1178 guidelines to choose a valid hostname because of implementations issues. A lot of these implementations don't recognize numeric hostnames well and try to parse them as if they were IPs until they contain at least one non-numeric character no matter the location.
Also, you will find that implementations don't always honor other original constraints of RFC 952, allowing for instance the hostname to end with a minus sign or a period.
DNS preserved these original specifications for hostnames and added support for underscores (RFC 2782).
Update As requested in comments, clarification for the sentence : However, a valid host name can never have the dotted-decimal form #.#.#.#, since at least the highest-level component label will be alphabetic. This means the top level domain name must be alphabetic, thus the fully qualified hostname can never be confused with an IPv4 address. This idea has been clarified by RFC 3696 for DNS and changed to not all-numeric. Note the slight difference.
Originally the hostname couldn't start with a digit or underscore (RFC 952) but the new specification RFC 1123, as you mentioned, allows it.
Concerning the call to isValid(), in this case, the full domain name should be passed in parameter: InternetDomainName.isValid("8server.com");
Yes. RFC 1123 clearly allows it and here's an example:
http://9292.nl/
It's the route planner for Dutch public transportation.