Windows Hosts File / What It Does, Where It Is, and How to Edit It
The Windows hosts file is a local text file that maps hostnames to IP addresses you specify. On Windows 10 or 11, run Notepad as administrator, back up the original, and edit the extensionless file at %SystemRoot%\System32\drivers\etc\hosts.
What the hosts file does
The Windows resolver turns hostnames into IP addresses. When it has loaded a matching hosts entry into the client cache, Windows can use that address before consulting a DNS (Domain Name System) server. The change applies to this PC. See Microsoft’s guide to Windows name resolution troubleshooting.
Put the IP address first, followed by whitespace and the hostname. A line starting with # is a comment. app.test and www.app.test are separate names. Enter the hostname without https://, a port, or a path.
Find, back up, and edit the file
%SystemRoot%\System32\drivers\etc\hosts
%SystemRoot% denotes the Windows installation directory, typically C:\Windows. The final component is the file name hosts, which has no extension.
- Enter
%SystemRoot%\System32\drivers\etcin File Explorer’s address bar. Copy the existinghostsfile to Documents or another separate location and give the copy a clear backup name. - Search for Notepad in Start. Right-click the result and choose Run as administrator. Review and approve the User Account Control prompt if it appears.
- In Notepad, select File → Open. Open the
etcfolder, choose All files as the file type, and openhosts. - Edit just the lines you need and press Ctrl+S to save. If Notepad opens Save As, first verify that you launched it as administrator and opened the original. Reopen
hostsat the same path to verify your line.
Map app.test to this PC and verify
Add the line below at the end of the file and save. .test is reserved for testing, and 127.0.0.1 is the IPv4 loopback address for this PC. See RFC 2606 for the reservation.
127.0.0.1 app.test
Run the following in Command Prompt or PowerShell. -4 uses IPv4, and -n 1 sends one request.
ping -4 -n 1 app.test
If you see [127.0.0.1] on the first line, the name resolved as expected. A browser also needs a local web server listening on the address and port you use. The DNS check needs only the mapping.
When the mapping does not take effect
- The file is missing or will not save. Check that Notepad is running as administrator and that the Open dialog shows All files. If you see
hosts.txt, turn on file extensions in File Explorer and locate the realhostsfile. - You get a different address. Check the spelling, look for a leading
#, and check for duplicate entries.nslookupqueries a DNS server directly. Use thepingcommand above to check the hosts mapping.
If the entry is correct and Windows still returns an old address, clear the Windows DNS cache in an administrator terminal, then run ping again.
ipconfig /flushdns
If ping shows the expected IP and one app still behaves differently, fully restart that app and check its proxy or name resolution settings.
Undo the change
Remove only the added line or comment it out with a leading #, then save. If you changed several lines, open your backup, restore the previous contents to hosts, and repeat the check. If you have no backup and need the default file, see Microsoft’s guide to restoring the default Windows Hosts file. Check with your administrator before resetting a work or school PC that may have required mappings.




