Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 am trying to redirect to my local machine for fun and learning with this /etc/hosts file on my Mac.

However, still maps to the Google home page when I visit it in Chrome on my Mac. Why?

Basically, this is all I did:

  1. Type sudo vim /etc/hosts in terminal.
  2. Inputted into the hosts file.
  3. Saved and quit vim.
share|improve this question
up vote 8 down vote accepted

The hosts file doesn't work this way. You can only use it to map an hostnames to IP addresses, not to localhost.

For your case you'd use, i.e. map to

If you want to map more hostnames to a singe IP, you just add those hostnames in the same line, e.g.

share|improve this answer
Thank you. I just changed the /etc/hosts file on my Mac to However, still leads to the Google home page. Do I need to refresh anything? Should I restart my computer? – David Faux Jun 3 '12 at 3:30
You shouldn't need to. Try adding (without the www) after this line and check whether it works. – Renan Jun 3 '12 at 3:31 isn't working either. I'm not sure what's going on ... I know that /etc/hosts is a soft link to /private/etc/hosts on a Mac, but I don't think that helps at all. – David Faux Jun 3 '12 at 3:53
A technicality: hosts maps hostnames to IP addresses, not vice versa. – Dennis Jun 3 '12 at 4:43
@Dennis, that’s what I was going to say, but then again, it really does work both ways when you think about it, because it creates an association between two items. – Synetech Jun 3 '12 at 4:46

A web browser isn't the best way to check if your hosts syntax is correct. Try executing


and verify that it pings

The reason why Chrome appears to ignore your hosts file is caching:

If Chrome has already queried the IP lately (the definition of lately most likely depends on the time to live (TTL) returned by the DNS server), it will bypass the hosts file, since it already knows the correct IP. This is done to speed up web browsing.

To make Chrome respect the new entry, do the follwing:

  1. Edit /etc/hosts as @Renan described.

  2. Go to chrome://chrome/settings/clearBrowserData.

  3. Choose since the beginning of time.

  4. Check Empty the cache, but uncheck everything else.

  5. Click Clear browsing data and wait for it to finish.

  6. Restart Chrome.

Chrome should respect your hosts file now.

share|improve this answer
I learned this a long time ago with IE6. If I made a change to the HOSTS file while IE was still open, I would have to specifically close it and run it again for it to pick up the changes. This goes for most programs. Some programs however (like versions of Chrome from the past year or two) will actually re-read the HOSTS file periodically, so if you make a change, just wait a minute or two, then refresh (no need to clear the cache). (This re-reading policy is handy sometimes like this, but usually pretty bad in reality since it is wasteful, and particularly bad if the HOSTS file is large.) – Synetech Jun 3 '12 at 4:48
@Synetech: Chrome picks up changes in hosts instantly, as long as the entry isn't a hostname that's already cached. I assume that it checks hosts only if the TTL has past. With big web sites, that can take a while. – Dennis Jun 3 '12 at 5:09
I don’t know the specifics about how different versions go about re-reading the HOSTS file, but you can use Filemon/ProcMon to see it in action; chrome.exe will occasionally read the entire file. – Synetech Jun 3 '12 at 6:26
There is a less brutal way of flushing chrome's DNS cache… – hakunin Mar 14 '13 at 11:50
@hakunin: Neat. On Chromium 25.0.1364.160 Ubuntu 12.04, this isn't even necessary anymore. I checked in net-internals/#dns, and the host cache gets cleared automatically when /etc/hosts is altered. – Dennis Mar 14 '13 at 12:05

You must log in to answer this question.

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