Hosts File Location in Windows 11 and How to Edit It Safely

The hosts file location in Windows 11 is C:\Windows\System32\drivers\etc\hosts. It is a plain text file that maps domain names to IP addresses before DNS is asked. This guide shows how to open and edit it with administrator rights, block or redirect sites, fix “access denied” errors, and restore the default.

Where the Hosts File Is in Windows 11

The full path is C:\Windows\System32\drivers\etc\hosts. If Windows is installed on another drive, use %SystemRoot%\System32\drivers\etc\hosts, which always points to the right place.

Why you cannot see it in some folders

The file has no extension. In the Notepad Open dialog, change the file type filter from Text Documents (*.txt) to All Files (*.*), otherwise it stays hidden.

What the hosts file does

Windows checks this file before asking a DNS server. A line such as 192.168.1.20 nas.home makes that name resolve to that address on this PC only. Developers use it to test sites, and some people use it to block domains.

How to Edit the Hosts File in Windows 11

Open Notepad as administrator

  1. Click Start, type Notepad, right-click it and choose Run as administrator.
  2. Choose File > Open, paste C:\Windows\System32\drivers\etc\hosts into the file name box and press Enter.
  3. Add your lines at the bottom, then press Ctrl + S.

Line format

Each entry is an IP address, a space or tab, then the host name. Lines starting with # are comments. One host name per line is easiest to manage, and example.com and www.example.com need separate lines.

Using PowerToys Hosts File Editor

Microsoft PowerToys includes a Hosts File Editor with a table view, enable/disable switches for each entry and duplicate detection. It is a good choice if you edit the file often.

Block or Redirect a Website

Block a domain

Point it to an address that goes nowhere: 0.0.0.0 example.com and 0.0.0.0 www.example.com. 0.0.0.0 usually fails faster than 127.0.0.1.

Redirect a domain for testing

To preview a site on a new server before changing DNS, map the domain to the new server’s IP, for example 203.0.113.10 example.com. Remove the line when testing ends.

Apply the change

Save the file, then flush the DNS cache with ipconfig /flushdns and restart your browser. Browsers keep their own cache too; our guide on how to flush DNS covers both.

Fixing Common Hosts File Problems

“Access denied” or “You don’t have permission to save”

Notepad was not running as administrator. Close it and reopen it with Run as administrator. If it still fails, right-click the hosts file, choose Properties and untick Read-only.

Microsoft Defender flags or resets the file

Defender can detect hosts entries that redirect or block Microsoft domains, and may report them as a settings modifier threat. That is intentional protection against malware that hijacks the file. Blocking Windows Update or activation servers this way can also break updates, so avoid copying large blocklists for telemetry into the file.

Changes have no effect

Check for typos, make sure the line is not commented out, flush DNS, and check whether a VPN, proxy or browser DNS over HTTPS setting bypasses system name resolution.

Restore the Default Windows 11 Hosts File

The default file contains only comment lines explaining the format; localhost resolution is handled by DNS itself. To reset, open the file as administrator, delete every non-comment line you added, save, and flush DNS. Keeping a copy named hosts.bak in the same folder before editing makes this even easier.

Frequently Asked Questions

Is the hosts file location the same in Windows 10 and 11?

Yes. Windows 7, 8.1, 10 and 11 all use C:\Windows\System32\drivers\etc\hosts.

Can I use a tool instead of Notepad?

Yes. PowerToys has a hosts editor, and some tweak utilities include one; hellzerg’s Optimizer utility has a HOSTS editor tab. Each edits the same file.

Conclusion

The Windows 11 hosts file lives in System32\drivers\etc, edits need administrator rights, and every change should be followed by a DNS flush. For network-wide changes rather than one PC, changing your DNS server is usually the better tool.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top