How to edit the hosts file on Ubuntu and block a website

The hosts file is an OS based plain text file that maps hostnames to IP addresses.It contains lines of IP address in the first field and host names in the second field. Each field is separated by tab space. you can also add a comment line by adding a hash (#) in the front.

Edit the hosts file on Ubuntu:

Open your Terminal app searching “terminal” in the unity dash or by press Ctrl+Alt+T key combination. If you want to take a backup of your hosts file , typing the following command in your terminal app.

sudo cp /etc/hosts /etc/hosts.old

Type your ubuntu password and press enter. Then run the below command in terminal.

sudo gedit /etc/hosts

It will open the hosts file in the gedit text editor.

It you you want to block www.google.com, then add below line in your hosts file.

127.0.0.1    www.google.com

Save the file and close it. You can add as many sites as you want.

Suggested Read:  How to install PeaZip on ubuntu

If the blocking is not working correctly in Google chrome browser, then just disable  the “Use a web service to help resolve navigation errors” option in the chrome settings.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

*