How to edit hosts file on windows 11

Published: July 13, 2024 (Updated: Jul 13, 2024)

Enjoying this content? Subscribe to the Channel!

Mastering the Windows 11 Hosts File: Your Essential Guide to Local DNS Overrides

Hello tech enthusiasts, and welcome back to Darren’s Tech Tutorials!

If you’re a developer, a system administrator, or just someone who needs total control over how your computer connects to websites, then the Windows Hosts File is one of the most powerful, yet often overlooked, tools in your arsenal. It allows you to completely bypass external Domain Name System (DNS) servers and tell your local machine exactly where to find a specific website.

This is absolutely crucial for testing new websites, blocking malicious domains, or redirecting local traffic. In this comprehensive guide, we’re going to walk through the exact steps you need to take to locate, edit, and save changes to the Hosts File on Windows 11, focusing on that one critical step that trips everyone up: Administrator access!


Why Editing Your Hosts File is Essential

The Hosts File acts as a local address book for your computer. When you type a domain name (like www.google.com) into your browser, your system checks the Hosts File first before reaching out to the public internet DNS servers.

This simple priority check gives you immense power, especially for:

  1. Website Testing: Need to preview a new version of a website (say, on a new server with a different IP address) before the DNS changes propagate worldwide? You can map the live domain name to the new server’s IP locally.
  2. Blocking Domains: You can map unwanted domains (like known ad servers or trackers) to the local machine address (127.0.0.1), effectively blocking your computer from ever resolving those sites.
  3. Local Development: Directing test domain names (mytestsite.local) straight to your local development environment (WAMP, XAMPP, Docker, etc.).

The Critical Hosts File Location on Windows 11

The Hosts File is not hidden, but it is deeply nested within system directories. You will need to navigate to this exact path:

c:\Windows\System32\Drivers\etc\hosts

Quick Tip: The file itself has no extension (it is not hosts.txt), which is often why people struggle to find it when using standard text editors!


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

Because the Hosts File is considered a critical system resource, Windows 11 requires elevated privileges (Administrator rights) to modify and save changes. This is the single most important part of the process!

Follow these steps exactly to ensure you can save your changes successfully:

Step 1: Open Your Text Editor as Administrator

You cannot just double-click the Hosts File or open Notepad normally. You must launch the application with elevated rights.

  1. Click the Start Menu or the Search icon on your Taskbar.
  2. Type Notepad (or your preferred text editor, like VS Code or Notepad++).
  3. Crucially: Right-click on the Notepad app result and select Run as administrator.
  4. Confirm the User Account Control (UAC) prompt if it appears.

Step 2: Navigate and Open the Hosts File

Since Notepad is now running as an Administrator, you can open protected system files.

  1. In Notepad, go to File > Open (or press Ctrl + O).
  2. In the File Explorer window that appears, navigate to the path: c:\Windows\System32\Drivers\etc\
  3. IMPORTANT: By default, Notepad only shows .txt files. In the bottom right corner of the Open dialog box, click the dropdown menu and change the file filter from “Text Documents (.txt)” to **“All Files (.*)”**.
  4. You should now see the hosts file. Select it and click Open.

Step 3: Make Your DNS Override Entries

The Hosts File uses a very simple syntax: the IP address first, followed by one or more spaces, and then the hostname.

Scroll to the bottom of the existing file (do not delete the original comments starting with #). To add a new entry, simply type:

[IP Address] [Tab or Space] [Domain Name]

Example for Local Testing: If your new server’s IP is 192.168.1.50, and you are testing the domain newsite.com:

192.168.1.50    newsite.com

Example for Blocking a Site:

127.0.0.1       badadsite.com

Step 4: Save the Changes

  1. After making your additions, go to File > Save (or press Ctrl + S).
  2. Because you opened Notepad as an Administrator, the file will save immediately without needing to move it or change permissions.

Step 5: Test and Clear DNS Cache (If Necessary)

Open your web browser and test the domain name you just modified. If the changes don’t appear immediately, you may need to clear your local machine’s DNS cache:

  1. Open the Command Prompt as an Administrator.
  2. Type the command: ipconfig /flushdns
  3. Press Enter. You should see a success message.

Conclusion: Take Control of Your Local Network!

And there you have it! You are now a master of local DNS manipulation on Windows 11. By using the simple yet powerful Hosts File, you gain immediate control over where your computer looks for specific websites—a game-changer for development, network security, and site testing.

If this tutorial helped you unlock the power of your local machine, please hit that Like button! Let us know in the comments below what you are using the Hosts File for—are you a developer testing a new environment, or are you blocking out distractions?

Don’t forget to Subscribe to Darren’s Tech Tutorials for more clear, actionable guides to mastering your technology! Happy editing!