4

I have some serious problems with the hosts file on my Lion 10.7.2. My hosts file is like following;

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost

27.0.0.1 first.localhost
::1 first.localhost
27.0.0.1 second.localhost
::1 second.localhost

I have more than 2 local sites but I just cut is short.

I can't manage http://first.localhost/ to work. http://second.localhost/ works fine but http://first.localhost/ doesn't work. If I delete the last two lines (which corresponds to second) than http://first.localhost/ works.

How can I add more than one local site in my hosts file? I'm using Lion 10.7.2 which I upgraded today and all those problems arose after that upgrade.

Note: There is nothing wrong with Apache config files or any other file with the local web server, I know that it's the /etc/hosts file that causes the problem.

Thanks.

1
  • I'm still confused as to what exactly the problem was. TextMate was appending? As opposed to what? What did nano do that TextMate wasn't? Commented Oct 16, 2011 at 5:32

2 Answers 2

5

All additional entries to the HOSTS file must be above the:

fe80::1%lo0

Make sure there is at least one line break after the last entry. Like so:

127.0.0.1 LLL.localhost
127.0.0.1 LLL.localhost
#

Although you probably can't tell, there is another line following the # symbol. One more thing to mention, using Space instead of Tab between 127.0.0.1 and localhost might help too.

11
  • pastebin.com/uuDzA9pT this is how my hosts file looks like but test.example.com not working. I read some articles that advise the same you say but nothing's working. Commented Oct 13, 2011 at 3:54
  • I'll take a look, just one sec.
    – l'L'l
    Commented Oct 13, 2011 at 3:57
  • Try this one: pastebin.com/d01ahHss ( just replace the XYZ.localhost with yours )
    – l'L'l
    Commented Oct 13, 2011 at 4:02
  • Not working :( This works; pastebin.com/g8b6AnZ9 but can't add a second vhost. If there is only one site, than the one that I wrote works, but if I try to add more sites it doesn't work. This is the weirdest OSX bug I've ever seen :) Commented Oct 13, 2011 at 4:11
  • Everything MUST be above the line: fe80::1%lo0
    – l'L'l
    Commented Oct 13, 2011 at 4:12
1

You'll need to follow ioi's answer to the T to get this to work correctly. I think the real trick might be the extra line at the end of the file.

2
  • Yes but it was my fault that I edited hosts file with Textmate and I didn't realize that TM was appending the file. Using nano solved the problem, thanks to @ioi. Commented Oct 13, 2011 at 5:54
  • @c-apolzon — I agree. It definitely doesn't hurt to ensure EOF.
    – l'L'l
    Commented Oct 13, 2011 at 6:26

You must log in to answer this question.

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