How do I block & unblock websites in Ubuntu 14.04?

I'm using Ubuntu 14.04 LTS desktop edition. In that, I need to block the sites like torrents and Facebook, YouTube etc. Can you please help me to block and unblock the sites. If it is possible to do so, please show step by step help.


You can edit the hosts file manually.
Open a terminal and type sudo nano /etc/hosts.

Then at the last line type each website's domain name you want to block like this:

127.0.0.1 www.youtube.com
127.0.0.1 thepiratebay.se
...

You may need to restart your browser/system in order for this to work.

Some general info:

The hosts file was used for mapping IP addresses to domain names in the past, now it's used for "defining" strict routes.

Routes specified in this file are always in priority by the system. It means: "If you want to visit %website%, use the IP I provided".

127.0.0.1 is always mapped to your own machine, so none of the websites listed will load.

Alternative

There may be a more elegant solution by using a firewall, but my knowledge on that is limited.


Mozilla Firefox is the default web browser in Ubuntu 14.04. Firefox does not have a built-in website blocking feature. But you can install an extension (Add-on) with this functionality. BlockSite allows you to block and unblock websites from Options (BlockSite Preferences).

Open Firefox → Add-ons → Get Add-ons → type BlockSite in the search field → click Install

enter image description here

enter image description here

Here you find more information on how to use BlockSite : How to Block Websites on Firefox