What Is the Hosts File, and How Do You Edit It in Windows?
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?
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:
- Launch File Explorer and navigate to the location mentioned below:
- Look for the hosts file and right-click on it.
- Choose Copy and paste the file into another safe location on your PC.
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:
- Open the Notepad by pressing Win + S, typing “Notepad” in Windows search, and clicking on Run as administrator.
- In the following window, navigate to File > Open.
- Type the following location in the text field for File name and click Open. You can also manually navigate to the file.
- 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 a href="http://www.google.com">www.google.coma>
- 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 a href="http://www.google.com">www.google.coma>
- To save time, click on File > Save As.
- Expand the dropdown for Save as type and choose All Files.
- 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.
- Head over to the desktop, right-click on the file you just created, and choose Rename.
- Remove the 2 (or any other number/letter you added) so that the file is only named as Hosts.
- Copy this file.
- Launch File Explorer and navigate to the original location of the host.
- 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:
- Type Command Prompt in Windows search and click on Run as administrator.
- In the following window, execute the following command:
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.
- Launch File Explorer and navigate to the location below:
- Rename the hosts file to hosts.bak.
- Next, navigate to the following location:
- Double-click on the hosts file and replace the text present in it with the following:
# 126.96.36.199 rhino.acme.com # source server
# 188.8.131.52 x.acme.com # x client host
# 127.0.0.1 localhost
- 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.