I'm attempting to block myself from time-wasting websites but changes I make to /etc/hosts. For example:   localhost   ross-laptop   bing.com

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

I can access bing.com in a freshly opened Chrome or Firefox - why is this not working?


You'll find the browsers and the system will cache things for you. In order to get this to apply right off the bat you should make sure to clear caches and restart your browser. In order to test this out, try performing a dns check from a terminal such as

ping bing.com

You should get it replying back from If this works then your hosts file change is good, but it's just cached in your browser.

  • But does the cache really survive restarting the browser? I've run into this also. It would be nice if there's a way to invalidate the cache.
    – loevborg
    Aug 28 '10 at 18:10
  • 1
    Well I'm not 100% sure if the dns cache survives a browser reload. I do know the files cache does. The thing is that with today's ajax/multi request models of web development you don't want to be performing a dns hit on every request while loading a page. Each browser will do it's own tricks to help speed that up and so you'd have to check their dns caching mechanisms on a per browser/browser version basis.
    – Rick
    Aug 30 '10 at 0:17
  • I'd be surprised if the DNS cache doesn't persist through browser restarts, at least in most browsers (probably all the major ones).
    – David Z
    Aug 30 '10 at 2:42

Have you tried putting the entries on the same line? abc bing.com foo

That should work.

  • 3
    This did work, although I think it's to do with browsers caching it and not clearing the cache properly.
    – Ross
    Aug 28 '10 at 18:20

Open Terminal (ALT+F2).

Type sudo -i in the input field. Check the Run in terminal option. Finally click Run button.

Type your password if necessary and press enter. Then enter the following commands.

gedit /etc/hosts

You will get Gedit Text Editor window.

For Example, if we need to block Facebook add the following lines just after localhost. facebook.com www.facebook.com

By doing this, it will block the site in all browsers including Google Chrome, Chromium, Mozilla.

That's it. When you now open www.facebook.com or facebook.com, you cannot access it. To enable back Facebook, remove the lines we added from the file /etc/hosts.

Source - Subin's Blog


Besides CragM's solution, remember you can use all 127.x.x.x address for this purpose, don't repeat the same address.   localhost   ross-laptop   bing.com   foo.com   bar.com
  • 1
    Can you explain why the same address not be repeated?
    – 8128
    Aug 29 '10 at 15:56
  • @fluteflute, I'm not sure but I used to do this and it always worked for me.
    – grokus
    Aug 29 '10 at 18:11

Modifying /etc/hosts looks like a global hack. I'd suggest setting up a local http proxy instead (squid, privoxy etc) and point your browser to use it. This way you would get a more flexible way of managing blacklists at proxy level.

  • 2
    It sounds like that would be a lot of effort compared to adding a couple of lines to /etc/hosts? Could you explain why this is a better solution?
    – 8128
    Aug 29 '10 at 15:56
  • "It sounds" because you are making assumptions without trying it. Issuing apt-get install, editing a config file and/or a blacklist and pointing the browser to the local proxy is not more complicated. It is better because you don't make any global changes to your system, you're only setting up an alternate way of having some sites blocked. If you ever need to undo, you won't have to edit /etc/hosts again, you'll just set the browser to access sites directly, not through the proxy.
    – vh1
    Aug 30 '10 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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