Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
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? – Jason Salaz Oct 16 '11 at 5:32
up vote 5 down vote accepted

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.

share|improve this answer this is how my hosts file looks like but not working. I read some articles that advise the same you say but nothing's working. – Burak Erdem Oct 13 '11 at 3:54
I'll take a look, just one sec. – l'L'l Oct 13 '11 at 3:57
Try this one: ( just replace the XYZ.localhost with yours ) – l'L'l Oct 13 '11 at 4:02
Not working :( This works; 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 :) – Burak Erdem Oct 13 '11 at 4:11
Everything MUST be above the line: fe80::1%lo0 – l'L'l Oct 13 '11 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.

share|improve this answer
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. – Burak Erdem Oct 13 '11 at 5:54
@c-apolzon — I agree. It definitely doesn't hurt to ensure EOF. – l'L'l Oct 13 '11 at 6:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.