54

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.

14
  • 3
    As a kind of proof by example, they do exist: 7dayshop.com
    – Holloway
    Oct 20, 2014 at 11:11
  • 3
    How about a digit-only hostname? 88888888.cn
    – 小太郎
    Oct 20, 2014 at 11:48
  • 8
    4chan.com is a valid (and well known) host name that starts with a number.
    – IQAndreas
    Oct 20, 2014 at 17:49
  • 3
    How can you forget 9gag.com? :D
    – ADTC
    Oct 21, 2014 at 2:33
  • 9
    @IQAndreas, 4chan.org is a good enough reason to make it invalid. (Just kidding anonymous, don't hurt me.)
    – Paul Ruane
    Oct 21, 2014 at 8:34

3 Answers 3

39

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.

4
  • 8
    Keep in mind that implementations which couldn't handle digits in names dated back to the 1980s; RFC 1178 was published in 1990. Anything that can't handle it now is simply buggy. Oct 20, 2014 at 12:17
  • 1
    @MichaelHampton You would be surprised of how many implementations still don't honor these RFCs. Starting from your linux hosts file handling. Oct 20, 2014 at 12:33
  • 12
    Haha, no I wouldn't. Hardly a day goes by that I don't have cause to beat some developer over the head with an RFC. Oct 20, 2014 at 12:34
  • 2
    @Michael Hampton: You wouldn't believe the shit I see from devs at times. Couple of weeks ago I had one who had made a network-config webpage in a ip-camera so that the user could enter the hostname for the camera. He didn't do ANY validation on the free-format user-input. Beta-test user entered "Room 1.10" and the camera happily send that as DHCP client identifier. I can assure you Microsoft DHCP and DNS servers don't like that. Good thing I noticed before that got into the production build. I can only shudder at the thought what sometimes does get through to the customer...
    – Tonny
    Oct 20, 2014 at 18:56
15

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");

2
  • Should a full domain name really need to be passed to the isValid method? After all InternetDomainName.isValid("server"); returns true.
    – Mark
    Oct 20, 2014 at 14:43
  • @Mark OK, I updated the answer accordingly Oct 20, 2014 at 14:49
9

Yes. RFC 1123 clearly allows it and here's an example:

http://9292.nl/

It's the route planner for Dutch public transportation.

1
  • 3
    There are plenty more: 9gag.com, 4chan.org, etc.
    – user232701
    Oct 21, 2014 at 12:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .