53

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.

Mark
  • 1,331
  • 1
  • 11
  • 16
  • I was going to say 'no', but that RFC clearly says it's ok. I don't think it matters regarding domain name. However I'd still be wary of doing it, because it _used_ to be invalid, and a lot of people may still be under the same misconception as I was :) – Sobrique Oct 20 '14 at 09:37
  • An interesting question, +1 from me, but I note that the example you quote above is a domain name, not a hostname (which would be, eg, `8server.example.com`). Could you clarify what the question's about, as the answers may differ? – MadHatter Oct 20 '14 at 09:39
  • @MadHatter I've edited the question to clarify why I have asked this. – Mark Oct 20 '14 at 10:23
  • Thank you! I only wish I were enough of a programmer to know what that call does, so I could answer the question myself! – MadHatter Oct 20 '14 at 10:27
  • Concerning the call to isValid(), did you try `InternetDomainName.isValid("8server.com");`, as isValid() is expecting a domain name? – Céline Aussourd Oct 20 '14 at 10:44
  • 2
    As a kind of proof by example, they do exist: http://www.7dayshop.com/ – Holloway Oct 20 '14 at 11:11
  • 3
    How about a digit-only hostname? http://www.88888888.cn/ – 小太郎 Oct 20 '14 at 11:48
  • @CélineAussourd 8server.com is accepted as a valid domain name. The Guava code specifically checks for a name with a single part starting with a number to reject it. I have posted a question on their Google Group as well. However, I also wanted to ask here to get a general answer for reference. – Mark Oct 20 '14 at 11:54
  • 7
    `4chan.com` is a valid (and well known) host name that starts with a number. – IQAndreas Oct 20 '14 at 17:49
  • I'm aware of .com addresses etc starting with a digit. As I mentioned in my question it wasn't clear whether a hostname without a . and starting with a digit was valid e.g. "8server" – Mark Oct 20 '14 at 19:07
  • @Mark You seem to think that there's a rule stating that a tld name must not start with a digit. That's not true and that's exactly what RFC 1123 deprecates. It should even be technically possible to use fully numeric TLDs in DNS with some restrictions (e.g. forbid 4 digits TLD names as it will be resolved as an IP address by most implementations and resolved as such, bypassing DNS query) in the future. For instance I remember the [42 registry project](https://twitter.com/42registry) that served the TLD `.42`. – Xavier Lucas Oct 20 '14 at 22:08
  • @XavierLucas I think the problem is that the rules are spread over any number of RFCs and aren't completely clear. But I agree with your point. On the Guava Discuss thread it was pointed out that in a `.111` TLD `222.222.222.111` would be an IPv4 address while `999.999.999.111` would be a hostname! – Mark Oct 20 '14 at 22:12
  • 3
    How can you forget [9gag.com](http://9gag.com/)? :D – ADTC Oct 21 '14 at 02: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 '14 at 08:34

3 Answers3

38

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.

Flow
  • 1,008
  • 10
  • 15
Xavier Lucas
  • 13,095
  • 2
  • 44
  • 50
  • 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. – Michael Hampton Oct 20 '14 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. – Xavier Lucas Oct 20 '14 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. – Michael Hampton Oct 20 '14 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 '14 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");

Céline Aussourd
  • 600
  • 1
  • 5
  • 14
9

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

http://9292.nl/

It's the route planner for Dutch public transportation.