Skip to content
Windows

How to Edit the Hosts File in Windows 11

Richard
Written by
Richard
Updated 8 min read
How to Edit the Hosts File in Windows 11
How to Edit the Hosts File in Windows 11
Before you start
  • 9 steps
  • Needs administrator rights

To edit the hosts file in Windows 11, open Notepad as an administrator and load the file at C:\Windows\System32\drivers\etc\hosts. The hosts file is a plain text system file that maps website names to IP addresses before your PC asks a DNS server, the service that turns names into addresses.

Windows reads this file first, so an entry there overrides what public DNS would say. You can use it to block unwanted domains, redirect web traffic, or test local servers. The steps are the same on Home and Pro editions of a currently supported Windows 11 version, such as 25H2 or 26H2.

Any edit changes how your PC resolves web addresses, so go slowly and keep a backup copy of the original file.

⚡ Quick Answer

To edit the hosts file in Windows 11, open Command Prompt as administrator, type notepad 📁C:\Windows\System32\drivers\etc\hosts, then press Enter. Notepad opens the file with admin rights so you can save changes. Add entries as IP address, a space, then website name, and keep a backup copy first.

Advertisement

Why Would You Edit the Hosts File?

The hosts file works like a local address book that Windows checks before it asks the internet. Editing it by hand lets you decide where a name points. People usually do it for one of three reasons:

  • Block websitesStop your computer from reaching certain sites by redirecting their names to your own machine or to an address that goes nowhere.
  • Test websitesWeb developers point a domain name at a test server or at their own computer. That lets them check a new site or design before it goes live.
  • Fix network issuesLink a name to a specific IP address for convenient local access. It also works as a stopgap when DNS on your local network is giving you trouble.
📝Good to KnowThe hosts file only affects the PC you edit. Other devices on your network will not see your changes, and a router or DNS setting is the place to go if you need that.
Advertisement

Where is the Hosts File Located?

The hosts file lives in a protected system folder on your main drive. This is why a normal editor session cannot save changes to it. The location is shown below.

💻Code
C:\Windows\System32\Drivers\etc\hosts

What Does the Hosts File Look Like?

The file is plain text. Each line holds an IP address followed by the website name it maps to, and each entry sits on its own line. Any line that starts with a hash symbol (#) is a comment. Windows ignores it, so it works as a note rather than an active rule. The default file is mostly comments like these:

# This is a comment - lines starting with # are ignored by your computer

127.0.0.1 localhost

# 127.0.0.1 example.com (this line is ignored because it starts with #)

When you add an entry, put at least one space or tab between the IP address and the website name. Without that separator, Windows can’t read the line properly. A wrong mapping can stop you from reaching the site you meant to change.

The file has no extension. It is called hosts, not hosts.txt, and you should keep it that way.

How to Edit the Hosts File: Step-by-Step

Step 1Open Notepad as Administrator

Windows 11 protects the system folder that holds the hosts file, so Notepad needs administrator rights to save changes. If you open Notepad normally, you can read the file but you get a permission error when you try to save. The trick is to start from an elevated Command Prompt, which is a Command Prompt window that runs with administrator rights.

  1. Click the Start button or press the Win. The Start menu opens with the search box ready.
  2. Type Command Prompt in the search box. Command Prompt appears in the results.
  3. Right-click Command Prompt in the results and select Run as administrator.
  4. Click Yes if User Account Control asks whether to allow the app to make changes. A Command Prompt window opens with Administrator in its title bar.

That’s it. You should now have an elevated Command Prompt, and anything you start from it runs with administrator rights.

If you don’t see Run as administrator, or you are asked for a password you don’t have, you are signed in with a standard account. Sign in with an administrator account and try again.

Opening Command Prompt as Administrator in Windows 11
windows 11 command prompt administrator

Step 2Open the Hosts File in Notepad

Because you started the Command Prompt as administrator, Notepad launched from it also runs with administrator rights. That is what lets you save changes to the hosts file later.

  1. Type the following command in the Command Prompt window and press Enter.

Opening the Hosts file in Notepad with administrative permissions lets you edit and save changes. This is necessary because the Hosts file needs elevated privileges to prevent unauthorized changes.

Notepad opens with the hosts file loaded, and you should see the default comment lines starting with #. If the window comes up empty or asks to create a new file, the path was mistyped. Close Notepad and run the command again.

That’s it. You now have the hosts file open in an editor that is allowed to save it.

Advertisement

Step 3Add Your Changes

Before you change anything, save a copy of the original file somewhere safe, such as your Desktop. If a new entry causes trouble, you can restore it. The default file is only comments, so a backup also shows you what a clean file looks like.

  1. Scroll to the bottom of the file, below the existing lines that start with #.
  2. Click at the end of the last line and press Enter to start a new line.
  3. Type your new entry. For example, to make your computer treat example.com as your own local computer, which is useful to block or test the site, add this line:
    💻Code
    127.0.0.1    example.com

Keep one entry per line, with a space or tab between the IP address and the name. Add as many entries as you need. To leave yourself a note, start a line with # and write the reminder after it.

Step 4Save Your Changes

  1. Click File in Notepad, then click Save. The title bar stays on hosts and no error appears.

That’s it. You should now have a saved hosts file with your new entry active.

If you get an error saying you don’t have permission, Notepad was not opened as administrator. Close it and start again from the elevated Command Prompt. Some security software also guards the hosts file and may block the save, so check its settings if the error persists.

⚠️WarningAlso avoid Save As here. It can create a file named hosts.txt, which Windows ignores.
Saving hosts file in Notepad
windows 11 hosts file save

Your changes take effect immediately, and you do not need to restart. If a site still behaves the old way, close and reopen your browser. Browsers keep their own cache of address lookups, so they can hold on to the old answer for a while.

To undo a change, open the file as administrator again. Then delete the line you added, or put a # at the start of it to turn it into a comment. Save the file, and the old behavior returns. If things go badly wrong, replace the file with the backup copy you made earlier.

Tips and Things to Remember

Backing up your original hosts file before making any changes prevents accidental lockouts or broken internet connections. Always verify your administrative permissions before saving, and use the hash symbol to disable lines temporarily without deleting them.
  • Always run Notepad as administrator to make sure you can save the changes.
  • Make a backup: Before you edit, copy the original Hosts file somewhere safe. This way, you can restore it if something goes wrong.
  • Use # for comments: If you want to disable a line without deleting it, just put a # at the start of that line.
  • Changes are instant: After saving, your computer immediately uses the new settings.

Summary

  • The Hosts file lets you control how your computer finds websites.
  • You can block websites or test your own sites locally.
  • You must run Notepad as an administrator to edit and save the file.
  • Always save a backup before making changes.
Advertisement

Editing the hosts file in Windows 11 gives you direct control over how your computer resolves website addresses for blocking or testing purposes. Success requires running Notepad as an administrator and saving a backup copy of the original document before making changes.

Frequently asked questions

🪟 Windows 11 hosts file?

The hosts file is a plain text file at 📁C:\Windows\System32\drivers\etc\hosts. Windows reads it before asking a DNS server, so any website name you list there points to the address you choose. People use it to block sites or test local servers. Editing it requires administrator rights.

How to edit and save hosts file in 🪟 Windows 11?

Open Notepad as administrator: right-click Notepad in the Start menu and choose Run as administrator. Then select File, Open, go to 📁C:\Windows\System32\drivers\etc, set the file type to All Files, and open hosts. Make your changes, then select File and Save. Back up the original first, since a wrong entry can cut off websites.

How to access host file in 🪟 Windows 11 to block instagram?

Add a line to the hosts file that points instagram.com to 0.0.0.0. Open Notepad as administrator, load 📁C:\Windows\System32\drivers\etc\hosts, and add 0.0.0.0 instagram.com and 0.0.0.0 www.instagram.com on new lines. Save the file, then restart your browser. The Instagram app may still load through other addresses.

The 🪟 Windows 11 ‘expand folder’ doesn’t work. is there a registry fix or group edit fix?

You usually don't need a registry or Group Policy fix. First, check the Expand to open folder setting in File Explorer's Folder Options, under the View tab. If the setting is locked or still fails, restart Windows Explorer from Task Manager and test again. Back up the registry before any manual change.

How to unzip a file in 🪟 Windows 11?

Right-click the ZIP file, choose Extract All, pick a destination folder, and select Extract. To look inside without extracting, double-click the ZIP file, which opens it like a folder. You can then drag files out to copy them.

How do I open a file in 🪟 Windows 11?

Double-click the file to open it in the app Windows assigns to its file type. To choose a different app, right-click the file, select Open with, and pick an app. You can also open the app first, select File, then Open, and find the file.

Still have a question?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Tags: #Windows 11

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

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