How To Edit & Modify HOSTS File in Linux

How to edit and modify the IP address hosts file on Linux systems.

When entering a website name, for example, in the address bar, the operating system will search in that file for the IP address to establish the connection.

Therefore all the changes we make in the hosts file will be analyzed first.

To know the web addresses that are currently registered in the hosts file, we go to the etc/hosts path:

sudo nano /etc/hosts

This will be the result:

How To Edit HOSTS File in Linux

We have seen that an editor is required to access the hosts file and know its contents, it is vital that we access it with administrative privileges since otherwise, we can not make any changes to it.

The syntax to use to prevent access to a website is as follows:     (website_url)

For example, if we want to block one of the sites where we spend more time, Facebook, we will use the following line:



But not only can we block websites, but we can also allow the redirection to our own servers by entering just the name of this, for example, in the hosts file we can create the following entry: Server_TheLinuxCode

In this way, in the browser, it will no longer be necessary to enter the IP address but the assigned name, and it will redirect us automatically.

We save the changes using the key combination Ctrl + O, and we left the editor using Ctrl + X.

The results of blocking, for example, a website are immediate:

This process applies to all Linux distros.

With this, we check what a file as simple as the host can do in the behavior of web accessibility

It might be interesting

Canadian University unveils the most powerful microscope of the world

The Canadian Centre for Electron Microscopy at McMaster University in Ontario is the place where the world’s most powerful electron microscope is being installed.

Xiaomi unexpectedly introduced on the international market gaming smartphone Black Shark 4 Pro

Back in March 2021, Xiaomi introduced the Black Shark 4 series of gaming smartphones. The basic model of the series entered the international market last May, and only now the more advanced Black Shark 4 Pro made its debut outside of China.

66 Xiaomi smartphones received the final stable MIUI 13 firmware for Q1 2022

You can download the firmware for each device, and to install it or not, you decide for yourself


Apple iPhone was launched as phone that took the paradigm of mobile technology to a new level. The phone was a cult and took the definition of advancements in phone beyond adding pixels to the camera and increasing RAM for gaming, rather the chic handset carried sophisticated look and clubbed it with a musical and video watching feel.