Hosts – change and manage the /etc/hosts file

Hosts - change and manage the /etc/hosts file

A little-known feature called “the hosts file” can be used to modify your system depending on your needs. Whether you need to create abbreviations to block websites or something else, all of this can be done using the hosts file.
But how can I make changes to it? Here we will tell you how, and provide some examples, so you can start using the file right now.

What is the hosts file?
If we talk in plain language, the hosts file is a simple text file that can be used on any operating system for translating host names into IP addresses. When you type a host name – for example, or – your system will check the hosts file to get the IP address, which is required for connecting to the appropriate server. But if you open this file on your computer, you will quickly find that there is not stored a directory of all websites on the Internet. There may be just a few lines and nothing more. Your system is always first checks the hosts file, and everything not specified in it, will be found on the DNS servers configured in your network settings (usually a server of your Internet provider).

But it also means that you can use the Hosts file to add addresses that cannot be provided DNS servers (for example, it may be aliases of different locations on your home network that otherwise would be available only if the local network is installed and configured your own DNS server), or to bypass the IP addresses provided by your DNS servers by default.

For example, if you ask your browser to open the DNS server will return the IP address of Facebook on your PC. But if you suddenly want to block Facebook on your computer, you can add to hosts file entry that points to your computer that all requests for need to redirect to some other IP address that is different from the real IP address of Facebook. To block this social network, you can simply register a transfer of requests the IP address, which will always return to your system. You can do a lot with this file, and this is just a very simple example – it all depends on your desires and needs.

Warning: keep in mind, hosts this is a system file, edit it only if you know what you’re doing it!

How to edit hosts file
In Linux Mint you can find hosts file in /etc/hosts. Since this is a plain text file, you can just use a plain text editor (whether terminal or graphical). Unfortunately, there is only one graphic tool that provides partial control of the hosts file is the application Domain Blocker for Linux Mint.

Hosts - change and manage the /etc/hosts file

This program works by adding entries to your hosts file which redirects your specified domains to – that is on your computer. Anyway, that’s all you can do with Domain Blocker – all other use of the hosts file require you to manually edit the file with a text editor.

As hosts it is a system file, you’ll need administrative rights to save changes to the file. However, you can edit it using terminal commands such as

sudo nano /etc/hosts[/simterm]


sudo gedit /etc/hosts[/simterm]

You can also replace the nano or gedit on the command to start your favorite text editor. When you’re finished editing the file in nano, you can press Ctrl+X and then y to confirm the overwriting of changes.

How to understand the format of the contents of the hosts file?
In the hosts file each record is on its own line. For the purposes of our article you can use a very simple syntax – you type the IP address to which you want to redirect the host name (domain), then the tab character (TAB) and the actual domain. For example, to block Facebook, you can enter where is the Tab key on your keyboard. To make sure it is entered correctly, you can also look at the screenshot and compare it with what is in your file.

Hosts - change and manage the /etc/hosts fileHosts – change and manage the /etc/hosts file

Here is another example of use of this opportunity. For example, if your home network is the computer (for example, its IP address is running a simple website that makes something useful for you. You can enter the following in the hosts file: Now, if you open your browser and just type in the address bar http://myhomeserver it will automatically show you the contents of the host It is much easier than to enter the IP address every time.

Potential problems
The only problem that I came across, related to the work of the Chrome browser. Chrome tends to ignore the hosts file, if you don’t do at least one of two possible things:
– to enter http:// in front of each address. For example, if you blocked Facebook via hosts file, Chrome will bypass the lock if you simply enter in the address bar. If you enter in the address bar, Chrome “listen” hosts file and block the website of this social network.
– disable the option “Use a web service to help resolve navigation errors” in the Chrome settings, and then you don’t have to type http:// before the address each time

Try it!
Hosts is a small magic file, which offers several useful features. Even if you don’t need any features that it provides (although, perhaps, you think), to see how it works will be very helpful. If you ever get into a situation where you could use the hosts file, you are familiar with them and know how to configure.

What is in your hosts file? Are there any unique cases of such use? Tell us in the comments!

Good Luck!!!

Share to friends
Rate author
( No ratings yet )
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
2022 years ago

Thanks for the info.
I am trying a huge Hosts file – there are thousands of entries and an adaway list (also thousands) for
What I am trying to do is NOT use an ad-blocker but still block the ads. The entries are first. My Android ROM developer suggests it to counter ads on the phone – I figured it should work for Linux Mint. The Adaway list I found elsewhere and figured it couldn't hurt.

Are there any impacts for having such a large Hosts file? It's 8.6 MB in size.

Reply to  MarkMcD
2 years ago

hi Mark The computer searches the hosts file every time you connect to a new website during a session. Once the browser knows the IP address of the site, it won’t do the lookup again, so any delay only happens the first time you access a particular domain. New pages on the same site don’t get delayed. Let’s estimate how long that delay is. When you start the browser the hole file gets read in from disk, and the time taken depends on your hard drive. You will not notice that delay in the time it takes the browser to… Read more »