6

Mac seems to be ignoring new changes to my hosts file. Older changes work without a problem. I've spent the past 4 hours trying to figure this one out. Help!

I have folders for each site that I develop in my /Sites folder. For example, several folders are named:

wp.dev
daf.dev
test.dev

I run MAMP, set the Apache Port to 80 and the MySQL Port to 3306 (so that I don't have to add the port to the address bar in a browser).

I have edited my /private/etc/hosts file as follows:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 


127.0.0.1   wp.dev
127.0.0.1   daf.dev
127.0.0.1   test.dev
fe80::1%lo0 localhost

Here's the kicker: wp.dev and daf.dev have been around for over a month. They resolve without a problem in my browser. I added test.dev this morning. When I type it into a browser it simply searches "test.dev" as opposed to resolving a domain.

I can ping any of the above domains and they go to 127.0.0.1, including test.dev.

For what it's worth, I've tried virtualhostsx with the same problem. I also run dscacheutil --flushcache and restart MAMP when making changes.

I need to kick off development on a new site, and this is driving me crazy.

chris_mac
  • 921
  • 3
  • 10
  • 21
  • restarting the mac didn't help? – outsmartin Jan 15 '12 at 18:44
  • 1
    Have you tried with `http://test.dev/` rather than `test.dev`, or testing with another browser than Chrome? (I assume you're using Chrome, because it's the only browser I know on Mac OS that will launch a search if the user doesn't type an actual URL) – zneak Jan 15 '12 at 18:44
  • Wrong site. Please ask this again at [AskDifferent](http://apple.stackexchange.com/). – DarkDust Jan 15 '12 at 18:44
  • @chris_mac, consider writing @[username] to answer to comments, it makes it easier to know who you're answering to. – zneak Jan 15 '12 at 18:46
  • Thanks, @zneak - I'm still figuring my way around stackoverflow. Chrome and Firefox give the same prob, even with an http:// preceding. – chris_mac Jan 15 '12 at 18:51
  • I've seen a situation where two spaces (' ') between the IP and the Hostname caused Mac to totally ignore that entry in the hosts file. Food for thought. – Jeff Welling Apr 27 '16 at 01:53
  • I was stuck on this for days, then i found a file ```/etc/hosts~orig``` which i used to restore the hosts file, added my new entries, and now everything is working. – niltoid Dec 09 '20 at 15:49

1 Answers1

19

Try putting all your entries at the top of the file.

Not really logical, but worth a try.

ChristopheD
  • 100,699
  • 26
  • 154
  • 173
  • Strange, but it worked. Hope this helps someone else as well, and thanks! – chris_mac Jan 15 '12 at 18:59
  • 1
    This totally worked. Thank you! – AlienWebguy Mar 20 '13 at 23:31
  • @AlienWebguy: you're welcome! – ChristopheD Apr 08 '13 at 22:50
  • omg thank you so much. that was driving me nuts. i did notice when i deleted the last entry, though, that there was a bunch of extra space in the line beneath it. that shouldn't make a difference but maybe the spaces was throwing the last entry off? at any rate, you saved me hours of headache. – kristina childs Apr 16 '13 at 18:37
  • 6
    That answer is incorrect. The file was probably saved in a non ASCII format. When you edit it and add them to the top and re-save it, you were saving back to a ASCII format. Hence simply opening it and saving it over would have had the same affect. – Steffan Perry May 09 '13 at 21:24
  • @SteffanPerry: good catch. That makes sense! – ChristopheD May 13 '13 at 17:35
  • i think @SteffanPerry is right. Moving to first line didn't help me, but then I found a file ```/etc/hosts~orig``` which i used to restore the hosts file, added my new entries, and now everything is working. – niltoid Dec 09 '20 at 15:51