A common way to "block" a website (eg, to eliminate it as a distraction) is to edit /etc/hosts and point the domain to the loopback address. Eg:

# Stop goofing off youtube.com

On Mavericks, I find that changes like this are seemingly ignored by the OS; after editing the file (with sudo) and saving, the site that should be blocked still loads.

I've tried resetting my DNS cache as follows:

dscacheutil -flushcache
sudo killall -HUP mDNSResponder

But the site still loads.

How can I get OSX Mavericks to notice a change to /etc/hosts?

  • 1
    Could it be that it's the browser DNS cache that is not flushed? What IP does ping youtube.com use? Commented Feb 18, 2014 at 14:32
  • Side note: if you're using DNS to temporarily block sites, selfcontrolapp.com for OSX works nicely. It modifies the hosts file and seems to flush browser cache automatically. They also mention similar apps for other platforms: github.com/SelfControlApp/selfcontrol/wiki/FAQ Commented Nov 17, 2014 at 14:52

4 Answers 4


According to the the hosts(5) manual page, the /etc/hosts file is used by mDNSResponder. Your attempts are correctly flushing the computer wide cache but you also need to flush the browser's private cache.

After each edit of /etc/hosts reset the mDNSResponder cache using this Apple technical note, OS X: How to reset the DNS cache:

sudo dscacheutil -flushcache

After doing this, reset your browser caches:

  • Safari: use the menu item Safari > Reset Safari.
  • Chrome: use the menu item Chrome > Clear Browsing Data.
  • 1
    This fixed it. Under Chrome's "Clear Browsing Data", there are checkboxes for types of data. "Empty the cache" is the relevant one. Commented Feb 18, 2014 at 15:34

Delete your browsers cache and add www.youtube.com to your host file.

youtube.com resolves to www.youtube.com. Your browser is caching that information and redirects you to the www-page.


In OS X 10.9 Mavericks, there are problems with trying to list multiple hostnames on the same line of /etc/hosts. I tried all of the other DNS-related tips in this post and the related post to no avail, until I stumbled on the "problems" link above.

I used to have something like this: localhost host1 host2 host3 ...

but I found that resolution of those hosts would either take forever or not work at all. Trying to access the sites via browsers would be generally OK (although sometimes very slow to resolve), but trying to ping from the command line would not work.

Changing it to the following format made everything work fine for me, and things now work great with ping, in the browser, and everywhere else: localhost host1 host2 host3

More details.


On top of Graham's answer, try chrome://net-internals/#dns (for Google Chrome) to see what is cached. Then click Clear Host Cache to wipe it all out.

You must log in to answer this question.

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