What is the Hosts file and how do I edit it in Windows?

Hosts files are text files used to map domain names to IP addresses, precisely what DNS servers do. You can use them to streamline logging into websites, and as such, sometimes you’ll need to change one.

As such, this guide will explain what host files are in Windows, how you can modify them, and what to do if you are unable to do so.


What is a Hosts File in Windows?

When your computer wants to connect to a website, it needs to communicate with a DNS server to convert the URL to an IP address. However, if you already know the IP address of a URL, you can add the details to the hosts file and your PC will use it without consulting a DNS server or the cache.

Suppose you want to search for our site, MakeUseOf, in your web browser. For the search to succeed, your PC needs an IP address, so it looks in the hosts file.

If you previously specified the MakeUseOf URL and corresponding IP address in the file, your PC uses this information to connect. Otherwise, the PC will try to find the IP address in the DNS cache or connect to a DNS server normally.

Hosts files are present in all operating systems, but in different locations. Here are the typical locations:

  • Windows 10 – “C:WindowsSystem32driversetchosts”
  • Mac OS X – “/private/etc/hosts”
  • Linux – “/etc/hosts”

Why should you modify the Hosts file?

The hosts file is modified for several reasons, but generally you want to do it for one of two uses.

First, the hosts file comes in handy if your DNS server isn’t working efficiently. If your DNS server is running slow, you can insert the IP address and domain name into the hosts file to speed up the lookup process (if you know all the details).

Conversely, you can use the hosts tile to block a PC from accessing a website. Since the hosts file is a PC’s first port of call, you can enter an invalid address for the targeted site to prevent your PC from accessing it.


How to Edit the Hosts File in Windows 10 and 11

Editing the hosts file in Windows is quite simple. Follow the steps below.

1. Create a backup

First, we need to create a backup. This will help you roll back to a previous state if something goes wrong.

Follow these steps to continue:

  1. Launch File Explorer and navigate to the location mentioned below:
    C:Windows
    ystem32driversetc
  2. Find the hosts file and right-click on it.
  3. Picking out Copy and paste the file to another safe location on your PC.

To add an extra level of security, you can also create a restore point. This restore point will allow you to revert the operating system to the current state using the System Restore feature.

2. Use Notepad to Edit the Hosts File

In this method, we will launch the hosts file using the Notepad application and edit it directly.

Here is all you need to do:

  1. Open Notepad by tapping Win + Sby typing “Notepad” in Windows search and clicking Execute as administrator.
  2. In the next window, navigate to Case > Open.
  3. Type the following location in the text field for file name and click Open. You can also manually access the file.
    C:WindowsSystem32driversetchosts
  4. Once the file opens, scroll to the end and enter the IP address followed by the domain name of the site you wish to block. Let’s say we want to add Google’s IP address to the file. Using this example, our file will look like this.
    127.0.0.1 a href="http://www.google.com">www.google.coma>
  5. If you want to block a site, just enter incorrect IP addresses like 0.0.0.0. Using the example above, we would enter the following text if we want to block Google.
    0.0.0.0 a href="http://www.google.com">www.google.coma>
  6. To save time, click Case > Save as.
  7. Expand the drop-down menu to save as type and choose All the files.
  8. Name the file as hosts2 and save it to your desktop.


Now that you have a ready-to-use hosts file, all you have to do is put it in the right place.

  1. Go to the desktop, right click on the file you just created and choose Rename.
  2. Remove the 2 (or any other number/letter you added) so that the file is only named as host.
  3. Copy this file.
  4. Launch File Explorer and navigate to the original location of the host.
  5. Paste the new file here and click Replace file in this destination if a replacement prompt appears.

Your modified hosts file is now ready to use.

What to do if the Hosts file is not working

If the hosts file is not working on your system, there could be several reasons why this is happening. You may not be able to open the file because the format is not supported or you do not have sufficient permissions to access it.

If you are having trouble with the file, here are some troubleshooting methods you can try:

1. Flush DNS and NetBIOS Cache

Since such issues usually arise due to corrupted or faulty cache files, the first solution we recommend you try is clearing the cache.

We covered how to do the latter in our guide to what is a DNS server, so check it out for instructions on how to do it.

Once you have flushed the DNS cache, follow these steps to flush the NetBIOS cache:

  1. Type command prompt in Windows search and click Execute as administrator.
  2. In the next window, run the following command:
    nbtstat -R

Once the command is executed, check if the issue is resolved.

2. Reset the Hosts File

You can also try resetting the hosts file to its default version to fix any issues related to it.

  1. Launch File Explorer and navigate to the location below:
    %systemroot% 
    ystem32driversetc
  2. Rename the hosts file to hosts.bak.
  3. Then navigate to the following location:
    %WinDir%
    ystem32driversetc
  4. Double-click the hosts file and replace the text it contains with the following:

    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host
    # 127.0.0.1 localhost
  5. Save the file to make the changes.


Customizing Your Hosts File on Windows

You now know how to modify the hosts file in Windows. You can use this information to perform a bunch of tasks, such as blocking websites, redirecting them, creating shortcuts to websites, and even testing web servers.