Hosts files are an essential part of the Windows Operating system that allows you to manually map IP addresses to domain names, effectively avoiding the Domain Name System resolution process.
One can edit the Hosts file for various purposes, such as blocking websites, redirecting domains, or testing a website on a different server. In this guide, let us talk through the process of editing Hosts files in Windows 11.
What Is Hosts File in Windows 11?
A Hosts File is a plain-text file on your computer that allows you to connect to websites. It is commonly named “hosts” without any file extension and contains a list of a few entries that map common hostnames to their corresponding IP addresses.
How Does Hosts File Work in Windows 11?
When you try to access a website or a service using a domain name on your computer, it first looks up the same domain name in its local Hosts file. If the domain name is present in the host file, your computer uses the corresponding IP address to connect to the requested website or service. This process is called host file-based DNS resolution.
If the domain name is not found in your local host file, then your PC queries a DNS server on the internet for the IP address of the website or service. As we know, a DNS server is a computer that stores a database of domain names and their corresponding IP addresses, so when it sees a query from your system, it will return the IP address of the website or the service you requested and then your computer will connect you to it.
What Are the Advantages of Editing Hosts File?
The Hosts File on Windows 11 has several important uses in computer networking and system management. Here are some common benefits of editing the Hosts file:
- Local Testing and Development: Developers use the Hosts file to map domain names to local IP addresses. This allows them to test websites and applications on their computers before deploying them to production servers. It is particularly useful for checking that web applications work as expected without affecting the live version.
- Blocking or Redirecting Websites: You can block access to specific websites by redirecting their domain names to non-existent or invalid IP addresses in the Hosts file. This process is often done to prevent access to distracting or potentially harmful websites, and it is also the most basic form of website filtering.
- Network Troubleshooting: The Hosts file can be used for network troubleshooting. By temporarily modifying the Hosts file to redirect domain names to alternative IP addresses, users and IT professionals can diagnose network issues and test connectivity to specific servers.
- Blocking Ads: The Hosts file can also be used to block online ads. You can block ads effectively at the DNS resolution level by mapping the known ad-serving domain names to non-functional IP addresses.
- Enhanced Security: To improve security, you can add known malicious or phishing domain names to your Hosts file, as doing this will prevent your computer from connecting to those potentially harmful websites and will also protect you from fraudulent activity and malware.
- Custom Domain Resolution: Using the Hosts file, you can define custom domain names for internal resources on a network. This makes it easier to access devices like printers, servers, or network-attached storage using user-friendly names rather than remembering IP addresses.
- Hostname Resolution: The Hosts file allows you to override the default DNS resolution for some specific domain names. This can be helpful in situations when you want to point a domain to a specific server or location.
- Prevent Tracking: If you’re a privacy-conscious user, you can modify your Hosts file to block connection to all the servers that collect telemetry data or track user activities.
- Custom Local Development Environments: If you’re into web development, then you can use the Hosts file for creating your local development environments with specific domain names. This thing can be pretty useful when you’re working on multiple web projects simultaneously.
How to Find Hosts File in Windows 11?
Follow these steps to locate the Hosts file in Windows 11:
1. Press Win + E on your keyboard to open the File Explorer app.
2. Head to the driver where the Windows OS is installed.
3. Scroll down and open the Windows folder.
4. Open the System32 folder.
5. In the System32 folder, click on the drivers folder.
6. Go to the etc folder, and there you can find the Hosts file.
How to Edit Hosts File in Windows 11?
In this article, we’re focusing on the three main ways in which you can edit the Hosts file in Windows 11. Before going to the steps, please keep these things in your mind:
- You’ll need admin permissions to edit the Hosts file at its original location.
- Make a backup of the Hosts file. This way, you can restore the original file if you make a mistake.
- Only add entries to the Hosts file that you trust. Do not add entries from untrusted sources.
- Be careful while editing, and do not override existing entries in the Hosts file.
- Restart your computer after editing the Hosts file. This will ensure that the changes are applied.
Now, let us look at how you can edit the Hosts file in Windows 11:
1. Using Notepad
Follow these steps to open the Hosts file using the Notepad app in Windows 11:
1. Press Win + S on your keyboard, type Notepad and select the Run as administrator option.
2. Select Yes in the User Access Control pop-up.
3. In the Notepad app, click the File option and select Open. You can also press Ctrl + O to open a file.
4. On the bottom right, change the file type to All files.
5. Navigate to the folder where the Hosts file is placed or copy this path to the address bar.
6. Select the Hosts file and click the Open button.
7. Now, you can make the changes in the Hosts file. Once you’re done, click the File option and select Save As. You can also press the Ctrl + Shift + S button on the keyboard.
8. On the saving page, select a location like your desktop. Next, change the file type to All files, and lastly, make sure to use only ANSI or UTF-8. After doing all these, click the Save button.
9. After saving the file, copy it, go to the default location of the Hosts file, and replace the old file with the new one.
10. Reboot your computer, and you’re good to go.
2. Using Microsoft PowerToys
The notepad method is long and we get it if you don’t want to follow it. That’s why, here’s an alternative. Microsoft PowerToys is the next tool that you can use for editing Hosts files in Windows 11.
If you’re unfamiliar with the app, Microsoft PowerToys is a suite of free and open-source utilities for Windows. It includes a variety of tools that you can use to improve your customization experience on Windows 11.
The best part about PowerToys is that it allows you to edit the Hosts file in a graphical user interface, which can be a lifesaver for users who are not comfortable using a text editor. Follow these steps to edit the Hosts file on Windows 11 using the Microsoft PowerToys app:
1. Open the Microsoft Store, search for Microsoft PowerToys, and install the app.
2. Open the app. Click on Hosts File Editor, and press the Launch Hosts File Editor button.
3. Click the Accept option.
4. Click the New entry button to add a new IP address and domain. You can also enable or disable any entry using the given toggles.
5. On the top right, the first button allows you to save the updates in the Hosts file. With the second button, you can sort entries or apply filters to them, and clicking the third button will open the Hosts file in the Notepad app.
6. You can tweak the Hosts File Editor’s settings by using the cog icon in the top right.
3. Using Command Line
If you’re someone who loves working with the Command Prompt app, then this method is for you. Let us see how we can edit the Hosts file in Windows 11 using Command Prompt.
1. Press the Win key on your keyboard to open the Start Menu. Type Command Prompt in the search bar and select the Run as an administrator option. You can also do this by first pressing Win + R, typing cmd, and then pressing the Ctrl + Shift + Enter button from the keyboard.
2. Execute the following command in the Command Prompt app.
3. Make the necessary changes to the Hosts file.
4. Save the Hosts file.
5. Close Notepad and reboot your computer.
Is It Safe to Edit the Hosts File?
It is generally safe to edit the Hosts file, but it is important to be careful. The Hosts file is a system file, so if you make a mistake, it could cause problems with your computer.
Do I Need to Restart After Editing Hosts File?
Generally, you do not need to restart your computer after editing the Hosts file. However, there are some cases where you may need to restart your computer. If you are not sure whether or not you need to restart your computer, it is best to do so.
Can I Create a Hosts File?
Yes, you can create a new Hosts file by opening a text editor, such as Notepad, and saving the file as Hosts in the above directory. Once you have created the Hosts file, you can add entries to it by specifying the hostname and the IP address, separated by a space.
Can I Reset My Hosts File?
Yes, you can reset your Hosts file. After resetting your Hosts file, you may need to restart your computer for the changes to take effect.
Have Complete Control Over Websites by Editing Hosts Files
Editing the Hosts file in Windows 11 can be a useful technique for various purposes, but it should be done with caution. Always back up the original Hosts file before making any changes, and be mindful of the potential consequences of your edits.
When used correctly, the Hosts file can be a valuable tool for managing network and domain name resolution on your Windows 11 system. Lastly, if you’re facing issues with the Hosts file after editing, our guide on fix hosts file not working in Windows 11 might help.