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


sudo -E gedit /etc/hosts

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

Also Read:  Automatically Download and Change Wallpapers with WallpaperDownloader App

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

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.

You may also like...

2 Responses

  1. Spas Spasov says:

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

  1. July 26, 2019

    […] If you want to edit your hosts file in ubuntu, please click the below link. How to edit the hosts file on ubuntu […]

Leave a Reply

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