How to Edit the Hosts File in Windows 11
You can edit the Hosts file in Windows 11 to control website access and test local server configurations.
The Hosts file is a system file located at 📁C:\Windows\System32\drivers\etc\hosts that maps domain names to IP addresses, overriding your normal DNS lookups.
Editing this file allows you to manually block specific websites, redirect traffic to different IP addresses, or test how local servers behave before deploying them. For example, you might use it to block annoying ads or prevent access to a website you are developing.
Open Notepad as administrator, then type notepad.exe C:WindowsSystem32Driversetchosts into the Command Prompt. Edit the file, and save your changes via File > Save.
Why Would You Edit the Hosts File?
You might want to edit the hosts file in Windows 11 to block specific websites, test new websites on your own computer before they go live, or fix network issues by linking a name to a specific IP address.- Block websites: Stop your computer from visiting certain websites by redirecting them.
- Test websites: Web developers use the Hosts file to test websites on their own computer before making them live.
- Fix network issues: Sometimes you want to link a name to a specific IP address for easier local access.
Where is the Hosts File Located?
The Hosts file is stored in this location on your computer:
C:\Windows\System32\Drivers\etc\hostsWhat Does the Hosts File Look Like?
The hosts file in Windows 11 looks like a simple text document where each line connects an IP address to a website name, with lines starting with ‘#’ being ignored.
# 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 #)
Note: The IP address and website name should have at least one space or tab between them.
How to Edit the Hosts File: Step-by-Step
Step 1Open Notepad as Administrator
To edit the hosts file in Windows 11, you must first open Notepad as an administrator because this file controls important network settings and requires special permission.
- Click on the Start button or press the Windows key.
- Type
Command Promptin the search box. - Right-click on Command Prompt in the results and select Run as administrator.

Step 2Open the Hosts File in Notepad
In the Command Prompt window, type the following command and press Enter:
notepad.exe C:\Windows\System32\Drivers\etc\hostsThis will open the Hosts file in Notepad with the permission to edit and save changes.
Step 3Add Your Changes
Scroll to the bottom of the file and add your new entries. For example, to make your computer treat example.com as your own local computer (useful to block or test the site), add this line:
127.0.0.1 example.comStep 4Save Your Changes
Click File > Save in Notepad to save the file.

Your changes will take effect immediately — no restart needed!
Tips and Things to Remember
When you edit the hosts file in Windows 11, always run Notepad as an administrator, make a backup copy first, and use the ‘#’ symbol to add comments or disable lines 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.
Editing the hosts file in Windows 11 lets you control how your computer finds websites, allowing you to block sites or test your own locally, but always remember to run Notepad as an administrator and save a backup first.
Is it safe to edit the hosts file?
Security teams use the hosts file to block malicious domains locally. Even regular users sometimes update the hosts file to restrict access to distracting websites. Because the hosts file is local, any changes you make apply only to that specific computer.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!