How to restrict some websites in Ubuntu 14.04

The easiest way, which works system-wide, is to set up entries in /etc/hosts

For example, add the following lines to the end of /etc/hosts, one for each site you want to block:

127.0.0.1 example.com
127.0.0.1 www.example.com
127.0.0.1 example.net
127.0.0.1 www.example.net

This tells the system's DNS resolver "please override the name to IP resolution for these host names" and since it overrides it to 127.0.0.1, those sites won't work.

Note that it is possible for users to circumvent this by using an HTTP proxy in the browser or if they were somehow to use an alternative DNS resolver, or if the site accept connections based on IP address only, and so on.


Open a terminal, and type sudo vi /etc/hosts.

Type Shift+G, then Shift+A, then I.

You should now see --INSERT-- at the bottom of the screen. Then, cut and paste this code:

127.0.0.1 siteyouwanttoblock.com

To save, press : and type wq and click enter.

It's as simple as that!

Note: I have NOT come up with this answer. I just made it more simple for the newbies. All credits go to you, @neon_overload.