How To Block A Website In Ubuntu

How To Block A Website In Ubuntu

block websites

Dear ubuntu geeks,

In this tutorial I will teach you how to block unwanted websites in Ubuntu Linux by editing the /etc/hosts file which is used to handle DNS and internet on Linux based systems.

I like very much this method because I don’t need to rely on third party applications and it is extremely easy to use. All you need to do is to make a simple change in the /etc/hosts file.

Make sure to have superuser access on the machine you are using this method, because the /etc/hosts file is owned by the root user and so it cannot not be edited by everyone.

What do you need to edit the /etc/hosts file?

root permissions and a text editor.

For this tutorial I will use my favourite text editor, vim. Ok guys, open a new terminal (CTRL+ALT+T) and run the following command to open the /etc/hosts file for editing.

vim /etc/hosts

Then add the following line.

Replace the with the website you want to block and after you have finished the editing process, save the file and quit.

Now it is time to test if the method has worked or not. Try to access the website you blocked.

My cousin is addicted to the facebook social network so every time he find my laptop, he opens it and goes to to chat with his friends.

What should I do?

I edit the /etc/hosts file and act like the website he is trying to reach is down.

You can also use this method to protect kids from adult content on the internet such as porn and horror movies.

  • Earl Turner

    I’m a dedicated Linux (Debian) user, but it is a good idea to mention that this works just as well on a Windows machine, as this is not Linux-specific. The only difference is the location og the hosts file, and that you would reverse the domain name and IP address of the local host.
    For example:
    Actually I thought that would be the correct way on Linux as well.
    This is TCP/IP and not OS based.
    Your machine will follow a certan pattern to resolve a domain name to an IP address.
    First it’ll check if it is itself, then check the hosts file, then DNS.
    On a windows machine it will then check WINS, then broadcat the request on the local net, and as a last restort check the LM-hosts file (Lan Manager file).
    I’ve been teaching networking and TCP/IP for a number of years and I alwas told the students to remember this by learning (by heart) the sentence:
    Let’s Have Dinner When Billy Leaves.
    Meaning Localhost, Hosts-file, WINS, Broadcast, LM-hosts.
    OK this is Windows… ;-)

    I believe Linux will do the same, with an exeption for WINS and LM-hosts.
    If I’m mistaken I’d like very much a correction. :-)