Hosts File Location in Windows 11: How to Find and Modify It
Have you ever wondered how Windows knows which website or computer to connect to when you enter an address? Most of the time, Windows uses the Domain Name System (DNS) to translate website names into IP addresses. However, there’s another file that can influence this process: the hosts file.
The hosts file is a plain-text file that lets you manually map a hostname, such as a website or computer name, to an IP address. You can use it to test website configurations, troubleshoot certain network issues, or redirect a hostname to a different address on your own computer.
The tricky part is that Windows doesn’t display this file like a regular document in File Explorer, and you usually need administrator permission to edit it.
In this guide, you’ll learn the hosts file location in Windows 11, how to open it, and how to modify its entries.
Hosts File Location in Windows 11

The default location of the hosts file in Windows 11 is:
C:\Windows\System32\drivers\etc\hosts
The file is named hosts and has no file extension. It’s stored inside the etc folder, which is part of the Windows system directory.
You can open the folder using File Explorer, Notepad, or the Run dialog box.
However, if you want to save changes to the original file, you’ll generally need to open your text editor with administrator privileges.
Modify the Hosts File in Windows 11
To modify the hosts file in Windows 11, open Notepad as an administrator, select File > Open, navigate to C:\Windows\System32\drivers\etc, change the file filter to All files, and open the file named hosts. Edit the entries carefully, save the file, and test the result.
Before making changes, create a backup of the original file. An incorrect entry can prevent a hostname from resolving as expected, so it’s important to know how to undo your changes.
Step 1: Open the Hosts File Location in File Explorer
The easiest way to find the hosts file is through File Explorer.
Press Windows + E to open File Explorer. Click the address bar at the top of the window, enter the following path, and press Enter:
C:\Windows\System32\drivers\etc
Windows will open the etc folder. Depending on your system settings, you may see several files, including hosts, networks, protocol, and services.
Look for the file named hosts. Remember that it doesn’t have a .txt extension, even though it contains plain text.
If you don’t see the file, make sure you entered the complete path correctly. You can also use the address bar to navigate directly to the folder instead of opening each folder one at a time.
At this stage, you can locate the file, but opening it for editing and saving changes may require administrator access.
Step 2: Open the Hosts File Using Notepad
You can use Notepad to read and edit the hosts file because it contains ordinary text.
Open the Start menu, type Notepad, and locate the Notepad application. Right-click it and select Run as administrator. If Windows asks for permission through User Account Control, select Yes.
Once Notepad opens, select File > Open.
Navigate to:
C:\Windows\System32\drivers\etc
Notepad may initially show only text files. This happens because the hosts file has no file extension, so it may not appear under the default file filter.
Look at the file type dropdown near the bottom of the Open dialog box. Change it from Text Documents (*.txt) to All files (.).
You should now see the file named hosts. Select it and click Open.
The file will appear in Notepad, allowing you to review its existing contents and make changes if needed.
Step 3: Create a Backup Before Editing
Before modifying a system configuration file, it’s a good idea to save a backup. This gives you a way to restore the original configuration if something goes wrong.
Open File Explorer and navigate to the hosts file location:
C:\Windows\System32\drivers\etc
Right-click the file named hosts and select Copy. Navigate to a folder where you can easily find the backup, such as Documents, and paste the copy there.
Rename the copied file to something recognizable, such as hosts-backup. You can keep this backup outside the protected Windows system folder to avoid permission issues.
Make sure the backup remains separate from the original file. Don’t replace the original unless you need to restore it.
If you make a mistake later, you can compare the edited file with your backup and restore the original entries.
Step 4: Understand the Hosts File Format
Before adding anything, it’s important to understand how entries in the hosts file work.
A typical entry contains an IP address, followed by one or more hostnames. For example:
127.0.0.1 localhost
The IP address appears first, followed by the hostname it represents. You can also add comments by placing a number sign (#) at the beginning of a line.
Lines beginning with # are comments. Windows ignores them when processing hostname mappings.
For example, you might see comments explaining the file’s purpose, followed by sample entries. These comments are normal, and you don’t need to delete them.
When adding a new entry, put it on a separate line and follow the same format. Avoid inserting random characters, removing unfamiliar entries, or changing unrelated lines.
If you aren’t sure what an existing entry does, leave it untouched until you’ve confirmed its purpose.
Step 5: Add a Custom Hosts File Entry
Now that you understand the format, you can add an entry for a hostname you control or one you’re troubleshooting.
For example, to map a test hostname to your own computer, you could add:
127.0.0.1 example.test
This entry tells Windows to resolve example.test to the loopback address, which points back to your local computer. It does not create a website or web server on its own.
If you have a legitimate reason to map a hostname to another IP address, use the correct IP address followed by the hostname. Make sure the mapping matches your intended test environment.
After entering the line, press Enter to keep it separate from other entries.
Be careful when using this feature with real websites. Mapping a hostname to an incorrect address may prevent you from reaching the expected website or service. Only add entries you understand and can safely reverse.
Step 6: Save the Modified Hosts File
After editing the file, save your changes by pressing Ctrl + S or selecting File > Save in Notepad.
Because you opened Notepad as an administrator and edited the original file, Windows should allow the changes to be saved.
If Windows displays an access-denied message, you may have opened Notepad without administrator privileges or may be editing a copy of the file rather than the original.
Don’t save the file as hosts.txt. In the Save As dialog box, choose All files if needed and ensure the filename is exactly hosts. Saving the file with a .txt extension creates a separate text document that Windows won’t use as its hosts file.
Once saved, close Notepad. Your changes should take effect without requiring a restart, although you may need to clear the DNS cache or restart the application you’re testing.
Step 7: Flush the DNS Cache
Windows may temporarily retain previously resolved hostname information in its DNS cache. If your new hosts entry doesn’t appear to work, flushing that cache is a useful troubleshooting step.
Open the Start menu and type cmd. Right-click Command Prompt and select Run as administrator.
Enter the following command and press Enter:
ipconfig /flushdns
Windows should display a message confirming that the DNS Resolver Cache was successfully flushed.
This command clears the cached DNS information. It doesn’t modify the hosts file or repair an incorrect entry, so double-check your changes if the hostname still resolves incorrectly.
Close Command Prompt and test the hostname again in the relevant application.
Step 8: Test the Hosts File Entry
After saving the file and flushing the DNS cache, verify that Windows is using the expected mapping.
Open Command Prompt and run the following command, replacing example.test with the hostname you added:
ping example.test
Check the IP address displayed in the command output. If the hostname resolves to the IP address in your hosts entry, Windows is recognizing the mapping.
Keep in mind that a successful name resolution doesn’t guarantee that the destination is reachable. For example, a hostname mapped to 127.0.0.1 may resolve correctly even if no application is listening on the required network port.
Some applications also use their own DNS-over-HTTPS settings or networking behavior, so their results may differ from basic Windows name-resolution tests.
If the mapping doesn’t work, verify the filename, entry format, spelling, and location before trying more advanced troubleshooting.
Step 9: Restore the Hosts File if Something Goes Wrong
If a change causes unexpected network behavior, you can remove the entry you added or restore your backup.
Open Notepad as an administrator and reopen the original hosts file. Find the line you added and delete it, or place a # at the beginning of the line to disable it.
Save the file and run ipconfig /flushdns in Command Prompt.
If you need to restore your backup, compare it with the current file and restore the original contents carefully. Avoid replacing the file with an unfamiliar hosts file downloaded from the internet.
If you suspect that malware or another program modified the hosts file without your permission, review the entries and run a scan with Windows Security.
FAQs
1. Where is the hosts file located in Windows 11?
The hosts file is located at C:\Windows\System32\drivers\etc\hosts. You can navigate to the folder using File Explorer or open the file through an elevated text editor.
2. Why can’t I save changes to the hosts file?
Windows protects the hosts file because it affects hostname resolution. Open Notepad using Run as administrator and make sure you’re editing the original file rather than a separate copy.
3. Does the hosts file have a file extension?
No. The standard Windows hosts file has no extension. If you save it as hosts.txt, Windows won’t treat that separate file as the hosts file.
4. Do I need to restart Windows after modifying the hosts file?
Usually, no. Changes generally take effect without restarting Windows. If they don’t appear to work, flush the DNS cache and restart the application you’re testing.
5. Is it safe to edit the hosts file?
Yes, if you understand the entries you’re changing and keep a backup. Incorrect mappings can prevent websites or other network services from resolving as expected, so avoid modifying unfamiliar entries.
Summary
The hosts file location in Windows 11 is C:\Windows\System32\drivers\etc\hosts. You can find it through File Explorer and open it with Notepad running as an administrator.
Before making changes, back up the file and learn how its IP address and hostname entries work. After editing, save the original file, flush the DNS cache if necessary, and test the result.
If something stops working, remove the entry you added or restore your backup.
