The hosts file on Windows 11 is located at C:\\Windows\\System32\\drivers\\etc\\hosts. This system file maps hostnames to IP addresses, allowing you to override the global Domain Name System (DNS) for specific websites or servers on your local machine.
Administrator Privileges Required for Editing
You cannot save changes to the hosts file using a standard user account because it is a protected system file. If you open the file by simply double-clicking it, Windows opens it in read-only mode, and any attempts to save your edits will result in an "Access Denied" error message.
To modify the file, you must launch your text editor with administrative rights. Search for Notepad in the Start menu, right-click the application icon, and select Run as administrator. Once the program is open with elevated privileges, use the File > Open menu to navigate to the directory. Labels and menu paths may differ slightly depending on your specific system configuration.
A common misconception is that you can simply move the hosts file to your desktop, edit it there, and move it back. While this sometimes works, Windows often prevents the replacement of the file in the etc folder unless the file explorer process itself is running with administrative permissions. The most reliable method is opening the editor as an administrator first.
Navigating to the etc Folder
Finding the file can be difficult because the etc folder does not contain a file extension for the hosts file, and the folder is buried deep within the system directory. To reach it quickly, you can copy the path C:\\Windows\\System32\\drivers\\etc and paste it directly into the address bar of File Explorer.
When you arrive in the etc folder, you will see several files. The hosts file is the one simply named "hosts" without any .txt or .ini extension. If your File Explorer is set to hide extensions for known file types, it may look like a generic file. Ensure you are selecting the file that has no extension to avoid creating a duplicate called hosts.txt, which Windows will ignore.
A useful rule of thumb for navigating system folders is to always verify you are on the C: drive. If you have multiple hard drives or a partitioned system, the Windows directory will always be on the primary boot drive where the operating system is installed.
Formatting Entries in the Hosts File
The hosts file uses a simple two-column format: the IP address followed by the hostname. There must be at least one space or tab between the IP address and the domain name. Each new mapping must start on a new line.
For example, if you want to redirect a website to a local server for testing, you would enter the IP address 127.0.0.1 followed by the domain name, such as 127.0.0.1 example.com. This tells Windows that whenever you type example.com into a browser, it should look at your own machine instead of asking a DNS server on the internet.
Lines starting with the hash symbol (#) are treated as comments and are ignored by the system. You can use these to organize your entries or leave notes for yourself about why a specific redirect was created. For instance, adding # Block Social Media above a list of redirects helps you identify the purpose of those lines months later.
If you need to map multiple domains to the same IP address, you can list them on separate lines or, in some cases, separate them with a space on the same line. However, placing each domain on its own line is the standard practice to ensure compatibility across different network configurations and to make the file easier to read during audits.
Handling Read-Only and Antivirus Blocks
Even with administrator privileges, you may find that the hosts file is locked. Some security software programs protect the hosts file by default because malware often modifies it to redirect users from legitimate banking or email sites to fraudulent clones. If you receive an error saying the file is read-only or being used by another program, check your antivirus settings.
To check if the file is marked as read-only, right-click the hosts file in File Explorer, select Properties, and look at the Attributes section at the bottom. If the Read-only checkbox is checked, uncheck it and click Apply. This is a common hurdle for users who have inherited a system configured by a corporate IT department.
If your antivirus continues to block changes, you may need to temporarily disable the "Host File Protection" or "Real-time Protection" feature within the security software's settings. Once the edit is saved and the editor is closed, re-enable the protection immediately to keep your system secure from unauthorized changes.
Verifying the Changes Took Effect
Changes to the hosts file usually take effect immediately, but your web browser or the Windows DNS cache may hold onto old information. If you have added a redirect but the browser still loads the original website, you need to clear the local DNS cache.
Open the Command Prompt by searching for cmd in the Start menu. Type the command ipconfig /flushdns and press Enter. You should see a message confirming that the DNS Resolver Cache was successfully flushed. This forces Windows to look at the hosts file again for the next request.
You can verify that the mapping is working by using the ping command. In the Command Prompt, type ping followed by the hostname you modified, such as ping example.com. The output will show the IP address that Windows is currently using to reach that host. If the output displays the IP address you entered in the hosts file, the configuration is correct.
If the ping command shows the original public IP address instead of your custom IP, double-check that you did not accidentally save the file as hosts.txt. Windows will only read the file that has no extension. If you see a file named hosts.txt in the etc folder, delete it and rename your edited version to simply hosts.
Managing Large Lists of Redirects
When managing dozens or hundreds of entries, the hosts file can become cluttered. To maintain organization, group your entries by function. Place all local development redirects in one block, all blocked domains in another, and all temporary testing overrides in a third.
Use clear comment headers to separate these sections. For example, use a line of hashes like #################### to create a visual border between different categories of redirects. This prevents you from accidentally deleting a critical mapping while trying to remove an old one.
Be aware that the hosts file is not a replacement for a professional firewall or a dedicated DNS server. While it is effective for single-machine overrides, it does not scale across a network. If you need to change the destination of a website for every computer in an office, you must make those changes at the router or DNS server level rather than editing the hosts file on every individual workstation.
Regularly auditing your hosts file is a good security practice. Over time, you may forget why certain redirects were added. Reviewing the file every few months allows you to remove obsolete entries, which keeps the system clean and ensures that you are not accidentally blocking services that you now need to access.