How to Edit Hosts File Windows 11

Editing the Hosts File in Windows 11

Editing the hosts file in Windows 11 allows you to override DNS settings for specific domains, essentially telling your computer to look at a different IP address than what the domain would normally resolve to. This can be handy for web development, blocking websites, or redirecting traffic. To do this, you’ll need to use administrative privileges and a text editor like Notepad. Let’s dive in!

Step by Step Tutorial: How to Edit Hosts File Windows 11

In the following steps, you’ll learn how to navigate to the hosts file and make necessary changes. By the end, you’ll be able to control how your computer interacts with specific domains.

Step 1: Open Notepad as Administrator

Click Start, type Notepad, then right-click Notepad in the results and select Run as administrator. Click Yes on the User Account Control prompt.

When running Notepad as an administrator, you gain the necessary permissions to edit system files. Without this step, you’ll likely encounter issues when trying to save your changes. If you are not sure where to find the app, see how to open Notepad in Windows 11.

Step 2: Open the Hosts File

In Notepad, go to File > Open and navigate to C:\Windows\System32\drivers\etc (or paste that path into the address bar of the Open dialog). Select the hosts file to open it.

The hosts file is located in a directory that requires administrative access. Make sure to change the file type to "All Files" in the open dialogue to see the hosts file.

Step 3: Make Your Changes

Add your desired IP address and domain names at the bottom of the file. Format should be: XXX.XXX.XXX.XXX domain.com.

Each entry in the hosts file should be on its own line, with the IP address first, followed by the domain name. Ensure there’s at least one space between the IP address and the domain name.

Step 4: Save the File

After making your changes, go to File > Save in Notepad.

This step requires administrative rights, which you granted by opening Notepad as an administrator. If you encounter any issues saving, double-check you followed Step 1 correctly.

Step 5: Flush DNS Cache

Open Command Prompt as an administrator and type ipconfig /flushdns, then press Enter.

Flushing the DNS cache ensures that Windows starts using your new hosts file settings immediately, without waiting for the old DNS records to expire.

After completing these steps, your computer will use the new IP addresses specified in the hosts file for the domains you added. This change is immediate upon flushing the DNS cache and does not require a system restart.

Hosts File Entry Examples

Each line is an IP address, at least one space or tab, and then a host name. Lines starting with # are ignored. Some common uses:

  • Test a website on a new server before DNS changes: 203.0.113.10 www.example.com sends requests for www.example.com to that server only on your PC.
  • Point a local development name to your own computer: 127.0.0.1 myproject.test.
  • Block a site: 0.0.0.0 www.example.com. Add a separate line for each variation, such as example.com and www.example.com, because the hosts file does not support wildcards.
  • Temporarily disable an entry: put # at the start of the line, for example # 0.0.0.0 www.example.com.

Alternative: Use PowerToys Hosts File Editor

If you edit the hosts file often, the free Hosts File Editor in Microsoft PowerToys gives you a simple table of entries that you can add, turn on or off, and filter without typing into a text file. Install PowerToys from the Microsoft Store, open Hosts File Editor, and launch it as administrator when prompted. It also warns you about duplicate entries.

Tips for Editing Hosts File Windows 11

  • Always create a backup of your hosts file before making changes.
  • Use Notepad++ or another advanced text editor for better syntax highlighting.
  • Be cautious when redirecting domains to avoid disrupting essential services.
  • Use comments (lines starting with #) to annotate why certain entries were added.
  • Validate your changes by pinging the domains and checking they resolve to the new IP addresses.

Troubleshooting

"Access is denied" or Save As appears when saving

Notepad is not running as administrator. Close it and reopen it with Run as administrator. Also check that the file is not marked read-only: right-click hosts in File Explorer, choose Properties, and clear Read-only.

The changes do not work

Run ipconfig /flushdns again and restart your browser, which keeps its own DNS cache. Make sure the file is still named hosts with no extension; Notepad may have saved it as hosts.txt. Also check for typos and that there is no # at the start of your line.

Microsoft Defender removed my entries

Defender can flag hosts file changes that block or redirect Microsoft services and may restore the original entries. If you need such an entry for a legitimate reason, review the alert in Windows Security > Virus & threat protection > Protection history before allowing it.

A program keeps changing my hosts file

Some software and malware add entries. Check for unfamiliar lines, remove anything you did not add, and run a full scan in Windows Security.

Frequently Asked Questions

What is the hosts file used for?

The hosts file is used to map domain names to IP addresses before the DNS server is queried.

Do I need to restart my computer after editing the hosts file?

No, but you should flush the DNS cache to apply changes immediately.

Can editing the hosts file harm my computer?

Only if you make incorrect entries. Always double-check your changes.

Where is the hosts file in Windows 11?

It is in C:\Windows\System32\drivers\etc. The file is simply named hosts and has no file extension.

How do I revert changes to the hosts file?

Open the hosts file again and remove or comment out the changes you made, then save the file and flush the DNS cache. If you made a backup copy before editing, you can also copy it back into the etc folder.

Why can’t I save the hosts file?

You need to run Notepad as an administrator to have the necessary permissions to save changes.

Get Our Free Newsletter

How-to guides and tech deals

You may opt out at any time.
Read our Privacy Policy