I have some serious problems with the hosts file on my Lion 10.7.2. My hosts file is like following; localhost broadcasthost
::1 localhost
fe80::1%lo0 localhost first.localhost
::1 first.localhost 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.


  • 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? Oct 16, 2011 at 5:32

2 Answers 2


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


Make sure there is at least one line break after the last entry. Like so: LLL.localhost 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 and localhost might help too.

  • 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. Oct 13, 2011 at 3:54
  • I'll take a look, just one sec.
    – l'L'l
    Oct 13, 2011 at 3:57
  • Try this one: pastebin.com/d01ahHss ( just replace the XYZ.localhost with yours )
    – l'L'l
    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 :) Oct 13, 2011 at 4:11
  • Everything MUST be above the line: fe80::1%lo0
    – l'L'l
    Oct 13, 2011 at 4:12

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.

  • 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. Oct 13, 2011 at 5:54
  • @c-apolzon — I agree. It definitely doesn't hurt to ensure EOF.
    – l'L'l
    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 .