How to Edit the Hosts File in Windows 11

Modifying the Windows 11 hosts file allows you to manually override DNS settings by mapping domain names directly to specific IP addresses on your local machine. This process is essential for web developers testing sites locally, setting up custom local domains, or blocking unwanted domains. This guide provides a straightforward, step-by-step walkthrough on how to locate, edit, and save the hosts file using administrator permissions in Windows 11.

Step 1: Open Notepad as Administrator

The hosts file is a protected system file, so you must open a text editor with administrative privileges to make and save changes.

  1. Press the Windows Key or click the Start Menu.
  2. Type Notepad into the search bar.
  3. Right-click on Notepad in the search results and select Run as administrator.
  4. Click Yes when prompted by User Account Control (UAC).

Step 2: Open the Hosts File

  1. In Notepad, click File in the top menu and select Open (or press Ctrl + O).
  2. Navigate to the following directory: C:\Windows\System32\drivers\etc
  3. In the bottom-right corner of the file dialog, change the dropdown menu from **Text Documents (.txt) to All Files (.*)**.
  4. Select the file named hosts and click Open.

Step 3: Add Your Domain Redirections

Scroll to the bottom of the hosts file to add your custom entries. Each entry requires an IP address followed by a space or tab and the domain name you want to redirect.

Step 4: Save the Changes

  1. Click File in the top menu and select Save (or press Ctrl + S).
  2. Close Notepad.

Step 5: Flush the DNS Cache

To ensure Windows 11 immediately recognizes your new host mappings without requiring a system restart:

  1. Press Windows Key + R, type cmd, and press Enter to open the Command Prompt.

  2. Type the following command and press Enter:

    ipconfig /flushdns
  3. You will see a confirmation message stating: “Successfully flushed the DNS Resolver Cache.”

Your redirected local domains are now active and ready to use in any web browser.