Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Edit the Hosts File in Windows 10 and 11

Edit the Windows hosts file safely with Notepad or a copy-and-replace method, preserve the extensionless filename, flush DNS, test mappings, and fix save errors.

Table of Contents

The Windows hosts file maps a hostname to an IP address before the system uses normal DNS resolution. Editing it is useful for testing a site on a new server, naming a device on a private network, or temporarily redirecting a domain on one PC.

On Windows 10 and Windows 11, the file is:

C:WindowsSystem32driversetchosts

You need administrator permission to save changes. Back up the file first, change only the required lines, and remember that the mapping affects this computer only.

Hosts file syntax

Each active entry contains an IP address followed by one or more hostnames, separated by spaces or tabs:

192.0.2.25    example.test
192.0.2.25    www.example.test

A line beginning with # is a comment. Do not remove comment markers from example lines unless you intend to activate them. Hostnames with and without www are different and need separate entries when both should resolve.

How to edit the hosts file on Windows 10 Picture 1
The hosts file is a plain-text list of local hostname mappings.

Method 1: Edit a copy, then replace the original

This method preserves an easy backup and avoids losing work if the editor cannot save in the protected folder.

  1. Open File Explorer and paste C:WindowsSystem32driversetc into the address bar.
  2. Copy the file named hosts to the Desktop or Documents folder.
  3. Create a second copy named hosts.backup.
  4. Open the working copy in Notepad. If Windows asks which app to use, choose a plain-text editor.
  5. Add or remove the required entries, then save. Keep the filename exactly hosts with no extension.
  6. Copy the edited file back to C:WindowsSystem32driversetc.
  7. Approve the administrator prompt and replace the existing file.
How to edit the hosts file on Windows 10 Picture 2
Copy the hosts file to a writable folder before editing.
How to edit the hosts file on Windows 10 Picture 3
Edit the copied file as plain text.
How to edit the hosts file on Windows 10 Picture 4
Copy the accepted version back to the protected etc folder.

Notepad may silently add .txt if Text Documents is selected in the Save dialog. Choose All files and verify in File Explorer that the file is named hosts, not hosts.txt.

Method 2: Run Notepad as administrator

  1. Open Start and search for Notepad.
  2. Right-click it and choose Run as administrator.
  3. Approve User Account Control.
  4. In Notepad, select File > Open.
  5. Paste C:WindowsSystem32driversetchosts in the File name box, or browse to the folder.
  6. If the folder appears empty, change the file filter from Text Documents (*.txt) to All files (*.*).
  7. Open hosts, make the change, and save.
How to edit the hosts file on Windows 10 Picture 5
Start Notepad with administrator privileges.
How to edit the hosts file on Windows 10 Picture 6
Use File > Open from the elevated Notepad window.
How to edit the hosts file on Windows 10 Picture 7
Browse to the Windows hosts file.
How to edit the hosts file on Windows 10 Picture 8
Select All files if the extensionless hosts file is hidden.
How to edit the hosts file on Windows 10 Picture 9
Add the mapping with the IP address first and the hostname second.

Example: test a website on another server

Suppose a staging server uses the address 192.0.2.25, and you want this PC to open www.example.com there:

192.0.2.25    example.com
192.0.2.25    www.example.com

Remove those lines when testing is complete. Leaving a production domain pinned to an old address can make a later server migration look broken on that PC.

Blocking a hostname

You can map an unwanted hostname to a non-routable local address, for example:

0.0.0.0    ads.example.invalid
0.0.0.0    www.ads.example.invalid

The hosts file is not a complete parental-control or security system. Applications can use their own DNS or direct IP connections, users with administrator access can undo the change, and large blocklists are difficult to maintain. Use operating-system family controls, a managed DNS filter, browser policy, or a firewall when enforcement matters.

Apply and test the change

Most changes take effect without restarting Windows, but an application or DNS client may cache an earlier result. Close and reopen the browser first. If necessary, open Command Prompt as administrator and run:

ipconfig /flushdns
How to edit the hosts file on Windows 10 Picture 10
Flush the Windows DNS resolver cache if an old address remains cached.

Test with:

ping example.test

The address shown by ping should match the hosts entry even if the server does not answer ICMP requests. nslookup queries DNS directly and is not a reliable way to confirm a hosts-file mapping.

If Windows will not save the hosts file

How to edit the hosts file on Windows 10 Picture 11
A permission error usually means the editor is not elevated.
SymptomFix
Access denied or no permissionRun the editor as administrator or use the copy-and-replace method
File saves as hosts.txtChoose All files and remove the .txt extension
File is read-onlyOpen Properties and clear Read-only only if organizational policy permits it
Security software restores the fileDo not disable protection blindly; review the alert and allow the exact intended edit through approved controls
Change has no effectCheck spelling, comments, duplicate lines, cache, and the application’s DNS behavior
No administrator prompt appearsConfirm the account can elevate and that the editor was launched with Run as administrator
How to edit the hosts file on Windows 10 Picture 12
The hosts file has no extension and must remain plain text.
How to edit the hosts file on Windows 10 Picture 13
Use the Security tab only to diagnose permissions, not to grant broad access unnecessarily.

Restore the default hosts file

The safest restoration is to copy back the backup made before editing. If no backup exists, remove only the custom entries you added and preserve the standard comments. Save the file, flush the DNS cache, and reopen affected applications.

Security checks

  • Do not paste a hosts file from an unknown website; malicious mappings can redirect banking, update, or login domains.
  • Do not change file or folder permissions to give all users write access.
  • Record why each custom entry exists and remove it when no longer needed.
  • If unexpected entries return after removal, run a trusted malware scan and check device-management policy.
  • Use reserved documentation addresses such as 192.0.2.0/24 in examples, not a real third-party server.

The reliable workflow is simple: back up hosts, edit it with administrator permission, keep the extensionless filename, flush cached DNS if needed, and test the resolved address. Avoid third-party hosts editors unless you have verified their publisher, maintenance, and security.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.