What Is the Hosts File, and How Do You Edit It in Windows? (2024)

Host files are text files that are used to map domain names to IP addresses, precisely what the DNS servers do. You can use them to streamline connecting to websites, and as such, sometimes you'll need to edit one.

As such, this guide will explain what host files are on Windows, how you can edit it, and what to do if you're not able to do so.

What Is a Hosts File on Windows?

What Is the Hosts File, and How Do You Edit It in Windows? (1)

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

Let’s say you want to look up our site, MakeUseOf, in your web browser. For the search to be successful, your PC needs an IP address, so it looks in the host file.

If you have previously specified MakeUseOf's URL and matching IP in the file, your PC uses that information to connect. Otherwise, the PC will attempt to find the IP address in the DNS cache or connect to a DNS server as normal.

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

  • Windows 10 - "C:\Windows\System32\drivers\etc\hosts"
  • Mac OS X - "/private/etc/hosts"
  • Linux - "/etc/hosts"

Why Should You Edit the Hosts File?

The hosts file is edited for several reasons, but you typically want to do so for one of two uses.

First, the hosts file is handy if your DNS server is not working efficiently. If your DNS server is working slowly, you can insert the IP address and domain name in the hosts file to speed up the searching 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 the first port of call for a PC, you can enter an invalid address for the targeted site to stop your PC from accessing it.

How to Edit the Hosts File in Windows 10 and 11

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

1. Create a Backup

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

Follow these steps to proceed:

  1. Launch File Explorer and navigate to the location mentioned below:
    C:\Windows\system32\drivers\etc 
  2. Look for the hosts file and right-click on it.
  3. Choose Copy and paste the file into another safe location on your PC.
    What Is the Hosts File, and How Do You Edit It in Windows? (2)

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

2. Use Notepad to Edit the Hosts File

In this method, we will be launching the hosts file using the Notepad app and editing it in there directly.

Here is all that you need to do:

  1. Open the Notepad by pressing Win + S, typing "Notepad" in Windows search, and clicking on Run as administrator.
  2. In the following window, navigate to File > Open.
  3. Type the following location in the text field for File name and click Open. You can also manually navigate to the file.
    C:\Windows\System32\drivers\etc\hosts 
  4. Once the file is opened, scroll down to the end and enter the IP address followed by the domain name of the site you want to block. Let’s say we want to add Google’s IP address to the file. Using this example, our file will look as follows.
    127.0.0.1 <ahref="http://www.google.com">www.google.com</a> 
    What Is the Hosts File, and How Do You Edit It in Windows? (3)
  5. If you want to block a site, simply enter incorrect IP addresses like 0.0.0.0. Using the example above, we will be entering the following text if we want to block Google.
    0.0.0.0 <ahref="http://www.google.com">www.google.com</a> 
    What Is the Hosts File, and How Do You Edit It in Windows? (4)
  6. To save time, click on File > Save As.
  7. Expand the dropdown for Save as type and choose All Files.
  8. Name the file as hosts2 and save it to your desktop.

Now that you have a hosts file ready to go, all you need to do is put it in the right location.

  1. Head over to the desktop, right-click on the file you just created, and choose Rename.
    What Is the Hosts File, and How Do You Edit It in Windows? (5)
  2. Remove the 2 (or any other number/letter you added) so that the file is only named as Hosts.
  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 on Replace the file in this destination if an overwrite prompt appears.

Your edited 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 can be several reasons as to why this is happening. You might not be able to open the file because the format is unsupported, or you don't have enough permission to access it.

If you are facing issues with the file, here are a few troubleshooting methods you can try:

1. Flush the DNS and NetBIOS Cache

Since such issues commonly arise due to corrupt or faulty cache files, the first solution we recommend trying is clearing the cache.

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

Once you have cleared the DNS cache, follow these steps to clear the NetBIOS cache:

  1. Type Command Prompt in Windows search and click on Run as administrator.
  2. In the following window, execute the following command:
    nbtstat -R 
    What Is the Hosts File, and How Do You Edit It in Windows? (7)

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

2. Reset the Hosts file

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

  1. Launch File Explorer and navigate to the location below:
    %systemroot% \system32\drivers\etc 
  2. Rename the hosts file to hosts.bak.
  3. Next, navigate to the following location:
    %WinDir%\system32\drivers\etc 
  4. Double-click on the hosts file and replace the text present in it with the following:
    # Copyright (c) 1993-2009 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    # 102.54.94.97rhino.acme.com # sourceserver
    # 38.25.63.10x.acme.com # xclienthost
    # localhost name resolution is handled within DNS itself.
    # 127.0.0.1localhost
    # ::1 localhost
  5. Save the file to make the changes.

Customizing Your Hosts File on Windows

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

  • Windows
  • Windows 10
  • Windows 11

Your changes have been saved

Email Is sent

Please verify your email address.

You’ve reached your account maximum for followed topics.

Manage Your List

Follow

Followed

Follow with Notifications

Follow

Unfollow

Readers like you help support MakeUseOf. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.

What Is the Hosts File, and How Do You Edit It in Windows? (2024)

References

Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6176

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.