Blocking Websites with /etc/hosts

dnshostsinternetnetworking

There's a website, www.example.com, that I tried to block myself from accessing because it wastes too much of my time. So I configured my /etc/hosts file. I added the following lines, to block the website on both IPv4 and IPv6:

127.0.0.1 www.example.com
::1 www.example.com
127.0.0.1 http://www.example.com
::1 http://www.example.com
127.0.0.1 example.com
::1 example.com

I restarted my computer, and I cannot wget www.example.com, and pinging www.example.com works as expected, but the website is not actually blocked in my browser! I can still access it in Firefox 28 and Chromium.

Questions

  • What's going on?
  • How do I block this site using systems-level tools instead of using browser extensions?

Best Answer

Rather then make this block using /etc/hosts I'd suggest using a browser addon/plugin such as this one named: BlockSite for Firefox or StayFocusd for Chrome.

BlockSite

  ss #1

StayFocusd

                    ss #2

But I want to really use /etc/hosts file

If you must do it this way you can try adding your entries like this instead:

0.0.0.0   www.example.com
0.0.0.0   example.com
::0       www.example.com
::0       example.com

You should never add entries to this file other than hostnames. So don't put any entries in there that include prefixes such as http:// etc.

Related Question