The hosts file, a legacy from the early days of the internet, is still a useful tool for mapping IP addresses to hostnames. This guide will walk you through different methods to edit this file in Windows 11.
Quick Editing with Microsoft PowerToys Hosts File Editor
- Download and install PowerToys from Microsoft Store.
- Click Search on the taskbar and type ‘PowerToys’. Open the application.
- Inside PowerToys, select Hosts File Editor from the left panel.
- Click ‘Launch Hosts File Editor’. This tool requires admin privileges to edit the Hosts file.
- Accept the warning dialog.
- You will see all entries from your Hosts file. Add, delete, or reorder as needed.
Locating Hosts File in Windows 11
On modern versions of Windows, including Windows 11, the hosts file is located at %SystemRoot%\System32\drivers\etc\hosts
.
Understanding the Hosts File
The hosts file contains lines of text with two columns – an IP address and a corresponding computer hostname. The columns can be separated by a space or a tab. The hosts file can be used to override DNS servers or provide hostname lookup in the absence of a DNS server.
Viewing and Editing the Hosts File
By default, the hosts file in Windows 11 doesn’t contain any valid entries. All entries are commented out using the ‘#’ symbol. To edit the hosts file:
- Click Start on the taskbar and type ‘notepad’. Press ENTER.
- Press the Windows key (WIN) + E to open File Explorer.
- Paste the path
%SystemRoot%\System32\drivers\etc\
in the ‘Quick access’ box and press ENTER. - Drag the hosts file from File Explorer into the Notepad window.
NOTE: Only administrators can edit the hosts file in Windows, as it’s located in a protected system directory.
There are two ways to edit the hosts file. The first method involves making a copy of the original file, editing it, and then replacing it. The second method uses the command line to append a line to the hosts file.
Method 1: Edit Hosts File using the GUI and Notepad
- Copy the hosts file and paste it to the desktop.
- Drag the hosts file from the desktop into a Notepad window.
- Add your entries at the bottom of the file.
- Save the file and close Notepad.
- Drag the hosts file from the desktop back to its original location, replacing the old file.
Method 2: Edit Hosts File using the Command Line
- Open the Start menu and type ‘command’. Make sure Command Prompt is highlighted on the left, then click ‘Run as administrator’.
- Give consent or provide an administrator username and password as prompted.
- Use the
echo
command to add a new entry to the hosts file. For example,echo 192.168.1.10 BOBPC >> %SystemRoot%\System32\drivers\etc\hosts
.
Using either method, you’ll be able to successfully edit the hosts file in Windows 11.