What is the hosts file on a computer and what is it for

Many users wonder what the host file of a computer is and what it is for . We have to know that the hosts file is a very useful text file that stores host names with their corresponding IP addresses. You could say that it is like a DNS server, but internally on the computer where the hosts file is.

Thanks to the hosts file, we can indicate which hosts name corresponds to a specific IP address, so that web browsers or other programs resolve that IP instead of what the DNS server that we have configured provides. We should know that the hosts file is found in all operating systems of Windows, Linux, MacOS and mobile devices. This file can only be modified by the system administrators of each computer.

So that you understand the importance of this file, every time you want to access a web page or computer on the network, the team first checks the hosts file to see if there is any data in that file about the web address (domain) or computer What are we searching for. If it is not there, it is when you already consult the DNS servers that we have configured.

What is the hosts file?

Although there are people who claim that it is an antiquity to use the host file, the reality is that today it is still used a lot especially at the internal level of companies, to specify names of specific computers with their IP address. Reviewing the history of the hosts file, it was created when the Internet took its first steps, the hosts file served at the time as a DNS server currently serves, that is, it related the domain names to their respective IP addresses.

For your understanding, the hosts file stored that the IP address of the website www.redeszone.net was 185.103.37.62. That is why formerly host files had a long list of names and IP addresses. Of course, with the passage of time and the increasing increase of websites and changes of IP addresses of the storage servers of those websites, the hosts file remained insufficient and that is why the DNS servers were created. If today we open the host file of our computer, we will see that, or few data appear, or it is directly empty. You can see an example in the image below, which is our own hosts file.

As we have indicated before, today these functions are performed by DNS servers and it is only useful to modify the hosts file for specific topics of our own local network, our professional local work network, and even to root different websites.

The hosts file inside

The first thing to know is that the hosts file is a plain text file that in Windows is opened and modified with the Notepad.exe program or with any other text editor. When we open a hosts file, as you can see in the image above, the first thing it shows us is a brief description of how it works and what that file is for. In this case it indicates the following:

“This is a sample HOSTS file used by Microsoft TCP / IP for Windows. This file contains the assignments of IP addresses to host names. Each entry must be maintained on an individual line. The IP address should be placed in the first column followed by the corresponding host name. The IP address and host name must be separated by at least one space. ”

Next, it indicates that if we want to leave comments in the host file, we must use the “#” character in front of what we write.

Finally, it shows examples of how to edit the hosts file correctly:

Example:

102.54.94.97 rhino.acme.com # source server

38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost

:: 1 localhost

As we can see, we must first enter the IP address, followed by at least one space and the DNS name, and, if we want to write a comment, we must leave at least one space and enter the “#” character in front of the comment. As we can see it is very easy to edit the hosts file, but very useful and powerful at the same time.

An advantage offered by the hosts file is that it allows us to assign a specific name to each computer. Another advantage is that we can block access to a specific website by redirecting it to a fake IP. For example, when someone tries to open the web page that we have redirected to a false IP, an error message will be found indicating that the host is not found, and we can even redirect it directly to 127.0.0.1 which is our own computer (localhost).

How to edit a Hosts file

Microsoft Windows

We are going to explain how you can edit the hosts file in the Windows XP, 7, 8 and 10 operating systems. The first thing we have to do is run the Notepad in administrator mode. Once executed in administrator mode we must go to the file menu, open and go to the following path: ” C: / Windows / System32 / drivers / etc / “.

Once in that directory we must select the file called «hosts».

With this, we can edit the hosts file. If we don’t open it as an administrator, it won’t let us save the changes in the folder where the file is.

MacOS

We are going to explain how you can edit the hosts file in OSX operating systems. In the top bar we must select the option “Go to the folder” and write the following path: / private / etc / hosts and click on “Open”. Then we will open the folder with the hosts file, and double-clicking on the file will open the text editor.

If our user does not have write permission, we must perform the following steps. First we open a terminal and type the following command:

Sudo nano / etc / hosts” and press the enter key.

It will ask for the user password, and then we can edit the hosts file.

Linux

We are going to explain how you can edit the hosts file in Linux operating systems. Depending on which Linux operating system we are using, and the desktop we use, we must open a terminal and enter the following command:

sudo nano / etc / hosts and press the enter key.

Then the hosts file will open so we can modify it.

Hosts File Risks

The great risk that we can find with the Hosts file is that an evil program modifies us without knowing the file, and redirects the traffic from the computer to malicious websites. To avoid this, it is important that we have a good firewall and a good antivirus. This will prevent any malicious program from entering. Also, if you have doubts, we advise you to see your hosts file if it has any strange entries. Above you can see a Windows 10 hosts file, as it comes by default.

It has become clear to us that the hosts file is like a DNS server, but local. Thanks to him we have seen that we can customize team names, which by entering that name redirects to a specific IP, blocking websites, or any action we want to do. Nowadays, it is true that for home users it is not used, but at the company level it is widely used to specify specific IPs to specific equipment.

If you want to personalize the access to a computer on your network using a specific name, editing the hosts file is an efficient and simple solution. If you have any questions, leave it to us in the comments.