Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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
127.0.0.1 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?

share|improve this question
1  
Could it be that it's the browser DNS cache that is not flushed? What IP does ping youtube.com use? –  Leonid Shevtsov Feb 18 at 14:32
add comment

2 Answers

up vote 7 down vote accepted

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.
share|improve this answer
1  
This fixed it. Under Chrome's "Clear Browsing Data", there are checkboxes for types of data. "Empty the cache" is the relevant one. –  Nathan Long Feb 18 at 15:34
add comment

Delete your browsers cache and add 127.0.0.1 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.

share|improve this answer
add comment

Your Answer

 
discard

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.