How to Edit the Hosts File in Windows

filero etc hosts in windows 1000×600.jpg

Did you know that the file ‘/etc/hosts‘ is also present in the Windows? This file, which many people associate with Linux and Unix and Unix-like operating systems, is actually an old travel companion that lets you map hostnames to IP addresses.

The hosts file or ‘/etc/hosts’ (although this is not the only place it can be found, as it depends on the operating system) was originally called HOSTS.TXT and was at originally made available via file sharing by the Stanford Research Institute for members of the ARPANET, the first computer network created for the United States Department of Defense. Basically what it contained and still contains are hostnames with their IP addresses to resolve domain names.

The network, due to its constant growth, has become too large for manual maintenance. Thus, between 1983 and 1984, the DNS (Domain Name System) appeared to provide a framework for instantaneous and dynamic resolution of host names.

Although DNS has greatly reduced the use of the hosts file, it is still useful for tasks such as redirect local domains to test pages, block internet content and prevent contact with activation servers in certain application hacking processes.

/etc/hosts file on Linux

‘/etc/hosts’ file on Linux

However, the hosts file can be an attack vector for malware. In this case, the malware could modify the hosts file so that it redirects traffic to servers hosting malicious or unwanted content. For example, it is possible that the infected user will end up seeing strange advertisements or mining cryptocurrency through their web browser, these scenarios being apparently more likely than having their computer become inoperable (although this can never be excluded). Malicious actors often prefer their malware to go unnoticed in order to avoid detection.

Despite its drawbacks, the hosts file allows, in addition to what has already been mentioned, to configure a small test environment within a local area network (LAN). This is the scenario we are going to cover in this article to learn how to configure the hosts file in Windows in a basic way.

Where is the ‘/etc/hosts’ file in Windows?

Without further ado, the path to follow with Windows Explorer is as follows: “This computer” > C: > Windows > System32 > drivers > etc > hosts (the last item in the path is the file).

Path to /etc/hosts file on Windows

The path without the file is as follows if you want copy and paste your location in the file explorer (you must first press ‘CTRL+L‘):

C:WindowsSystem32driversetc

And it’s the specific location of ‘/etc/hosts’ file in Windows (remember that the Microsoft system doesn’t care about the address of the slashes ‘/’ and ”):

C:WindowsSystem32driversetchosts

How to Edit the Hosts File in Windows

Successive versions of Windows have introduced limitations to critical system directories to prevent the user from modifying or deleting them (at least with the operating system’s default configuration). If you want to modify any content in System32, you must use the System Administrator account, because the common account, although set as administrator by default, does not have permissions to write to it.

To edit the hosts file on Windows, you must first open notepad as administrator. To do this, open the system start menu, write “Notepad” in the search engine, right-click on the entry of the application that we want to open and select “Run as ‘administrator “. The system will ask the user if they want the app to make any changes to the device, to which they obviously have to say yes.

Run Notepad as Administrator in Windows 10

Confirm that you want to open Notepad as an administrator to edit the hosts file in Windows

Once you open Notepad as an administrator, go to the menu File > Open proceed with the opening, worthy of redundancy, of the Windows host files.

Open hosts file in Windows with Notepad

We recall that the path to find the hosts file in Windows is “This Computer” > C: > Windows > System32 > Drivers > etc.. However, when you get there, you find that the folder is apparently empty because Notepad cannot find any file with a ‘.txt’ extension. This is solved by selecting “All the files” in the drop-down list in the lower right corner of the dialog box.

Show all files in notepad

Select the /etc/hosts file in Windows in System32

Alternatively, once the “Open” dialog is open in Notepad, you can press the “ctrl + L” key combination, then copy and paste the following into the address path. This will result in opening the file directly:

C:WindowsSystem32driversetchosts

Once the file is open hosts on WindowsHere’s what it looks like in the app:

/etc/hosts file in Windows 10

In this case, we have a Windows 10 instance running in a GNOME Boxes virtual machine, so we introduced the Host machine IP next to hostname (asus-silver). All lines preceded by a hash mark (#) are comments and are therefore ignored at the configuration level, but they can be useful for introducing descriptions of what the file does or a specific line.

Entering a local network host in the Windows /etc/hosts file

After making the relevant changes to the file, it is saved as usual, by going to the File menu and clicking Save.

Save changes to /etc/hosts file on Windows with Notepad

With the changes made to the file, we tried to access an HTTP server (nginx) running on the host machine through a Docker container with Podman. Instead of putting the IP, which is a number that can be difficult to remember, we put the name of the equipmentand from what you can see in the following image, the Windows hosts file is doing its job correctly to display the content served by the host machine through the HTTP server.

Hosts file works fine on Windows after modifying it

Location of hosts file in other operating systems

The hosts file essentially performs the same function in all operating systems, so we will mention its location through various examples in which we will mention several operating systems which may or may not be popular. We warn that we have not taken into account if the user has permissions, even indirect, to modify it.

location in android:

/etc/hosts # Que es un enlace simbólico hacia /system/etc/hosts

location in iOS Yes macOS:

/etc/hosts # Que es un enlace simbólico hacia /private/etc/hosts

location in haikus:

/system/settings/network/hosts

location in Linux,UnixUnix and POSIX-like:

/etc/hosts

conclusion

Although its use has declined quite a bit over the decades, the hosts file is still useful for certain contexts, and as we have seen throughout this article, not only for creating a small test environment via a local network, but also for the defensive. purposes or restricted access to certain resources.

Of course, we remind you that it must be handled with great care. As a basic tip, we recommend that you do not enter a public IP address there unless you know very well what you are doing. If you want to tinker, it’s best to just enter the local network IP addresses.