Is there a maximum number of hostname aliases per line in a Windows hosts file?

17

3

I have a hosts file on Windows 7 that has an IP address followed by 10 different hostname aliases. I can ping the first nine, but if I try to ping the tenth, I get:

Ping request could not find host tenth. Please check the name and try again.

I've tried switching the ninth and tenth entry in case it was something to do with the specific hostname, in each case it is the tenth listed that I can't contact.

Is there a limit to the number of hostnames that can be listed on a line? If so, is there a way around this restriction?

EDIT: The length of this line of the hosts file is less than 150 characters.

Dan

Posted 2015-06-24T17:09:04.743

Reputation: 795

Upvote for showing on the first page of Google results. June 2018 – SDsolar – 2018-06-07T04:05:29.570

Answers

24

Windows allows up to nine aliases per line. For more, add another line.

Before (h10 and h11 do not resolve):

127.0.0.1  h01 h02 h03 h04 h05 h06 h07 h08 h09 h10 h11

After (h10 and h11 resolve):

127.0.0.1  h01 h02 h03 h04 h05 h06 h07 h08 h09
127.0.0.1  h10 h11

I confirmed this behavior and workaround on Windows 7, Windows 10, and Windows Server 2008 R2.

While I cannot find a Microsoft citation, the following article claims the third-party utility Hosts Optimizer puts "a maximum of nine host names in a single line if they point to the same IP address."

http://www.ghacks.net/2010/05/23/windows-hosts-file-optimizer

Steven

Posted 2015-06-24T17:09:04.743

Reputation: 24 804

1Do you have a citation for this? The TechNet page linked to by CodingPenguins does not appear to support your statement. – a CVn – 2015-06-24T17:23:42.957

The TechNet page doesn't mention the nine alias maximum. I tried a tenth alias and it didn't work, and moving the tenth alias to the second line did work. – Steven – 2015-06-24T17:37:44.567

Well, personal experience is worth something too, particularly when spelled out as such. But did you switch places between the "before" and "after"? – a CVn – 2015-06-24T18:18:20.187

0

Looks like Microsoft has inconsistent handling of the hosts file. While you can't ping past the ninth hosts item, you can still navigate to hosts past the tenth in the browser.

Documentation found related: https://technet.microsoft.com/en-us/library/bb727005.aspx?f=255&MSPPError=-2147217396#EDAA

You can just add additional lines.

127.0.0.1 myreallylonghostname
127.0.0.1 myotherreallylonghostname

CodingPenguins

Posted 2015-06-24T17:09:04.743

Reputation: 369

1While it's not impossible given the question, I find it hard to believe that the OP really has a host name of >255 characters without mentioning that. The linked page does not appear to say anything about maximum line length, and the OP does say already tried switching places of ninth and tenth but still couldn't resolve tenth. – a CVn – 2015-06-24T17:22:39.133