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

or

sudo -E gedit /etc/hosts

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

Also Read:  Armagetron Advanced 3D Tron Lightcycle Game

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.

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.

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on Twitter and Facebook.



This Post Has 2 Comments

  1. Spas Spasov

    Please change the command line to: `sudo -H gedit`

Leave a Reply to Spas Spasov Cancel reply