Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valid characters of a hostname?

Tags:

networking

What are the valid characters of a hostname? This would be something like a networked computer or a web domain.

To put it in context, I am writing a PC game which connects to a remote server; so I have a field for hostname and a field for port. Obviously the port is a number in the Short range, but I need to know what all the possible hostname characters are (and any other pattern that might be required - does a hostname need to start with a letter?).

Examples of hostname include localhost or google.com.

like image 371
Ricket Avatar asked Aug 19 '10 14:08

Ricket


People also ask

How many characters is a hostname?

Hostnames are composed of a sequence of labels concatenated with dots. For example, "en.wikipedia.org" is a hostname. Each label must be from 1 to 63 characters long. The entire hostname, including the delimiting dots, has a maximum of 253 ASCII characters.

How do I check if a hostname is valid?

The HostName test performs DNS lookup and provides information about how a domain or hostname (www.yourdomain.com) is resolved to an IP address (69.147. 114.210). Common use of the HostName test is to verify that the DNS records are correct and specific domain points to the correct IP address.

What is an example of a hostname?

A host, or website, on the Internet is identified by a host name, such as www.example.com . Host names are sometimes called domain names.

Is _ allowed in hostname?

The underscore is not a legal character for use in hostnames. As defined in RFC 822, the only legal characters are the following: Alphanumeric ( a-z and 0-9 ): Both uppercase and lowercase letters are acceptable, and the hostname is case insensitive.


2 Answers

Checkout this wiki, specifically the section Restrictions on valid host names

Hostnames are composed of series of labels concatenated with dots, as are all domain names. For example, "en.wikipedia.org" is a hostname. Each label must be between 1 and 63 characters long, and the entire hostname (including the delimiting dots but not a trailing dot) has a maximum of 253 ASCII characters.

The Internet standards (Requests for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.

like image 124
Aaron Hathaway Avatar answered Nov 04 '22 08:11

Aaron Hathaway


It depends on whether you process IDNs before or after the IDN toASCII algorithm (that is, do you see the domain name παράδειγμα.δοκιμή in Greek or as xn--hxajbheg2az3al.xn--jxalpdlp?).

In the latter case—where you are handling IDNs through the punycode—the old RFC 1123 rules apply:

U+0041 through U+005A (A-Z), U+0061 through U+007A (a-z) case folded as each other, U+0030 through U+0039 (0-9) and U+002D (-).

and U+002E (.) of course; the rules for labels allow the others, with dots between labels.

If you are seeing it in IDN form, the allowed characters are much varied, see http://unicode.org/reports/tr36/idn-chars.html for a handy chart of all valid characters.

Chances are your network code will deal with the punycode, but your display code (or even just passing strings to and from other layers) with the more human-readable form as nobody running a server on the السعودية. domain wants to see their server listed as being on .xn--mgberp4a5d4ar.

like image 39
Jon Hanna Avatar answered Nov 04 '22 08:11

Jon Hanna