Last Update: Sep 04, 2024 | Published: Jan 12, 2023
In this article, you will learn how to edit the Windows 11 hosts file. There are several easy ways that you can edit the file, and in this article, I will take you through each method step-by-step.
In the early days of the Internet, there was just one ‘hosts’ file that was used to match computer names to IP addresses. All devices connected to the Internet are represented by an IP address. An IP address might look something like this: 172.217.23.238. As you can see, it would be difficult to remember the IP address of every device connected to the Internet! So, the hosts file contained a phonebook-like directory of IP addresses mapped to computer hostnames.
As the Internet developed and more devices were connected in different geographical locations, it was no longer practical to maintain a single hosts file. The Domain Name System (DNS) was created in 1984 to provide devices connected to the Internet with a way to look up hostnames by querying a set of distributed servers. And that is how the Internet works to this day.
Perhaps the easiest way to view and/or edit the hosts file is to use the new Hosts File Editor in Microsoft PowerToys. But if you want more information about what the Hosts file is and how to edit it manually, skip to the next section.
PowerToys is a free set of tools for sysadmins and developers that you can download for free from GitHub. Before you can use Hosts File Editor, you’ll need to download PowerToys from the Microsoft Store.
Once PowerToys are installed, follow the instructions below to use Hosts File Editor:
You can right click entries to reorder them too.
But the hosts file remains part of most operating systems. It can be used to override results provided by DNS servers and provide hostname lookup on a local area network (LAN) in the absence of a DNS server. Depending on the operating system, the hosts file is found in a different location. For instance, in Unix, you will find the hosts file in /etc/hosts. And on all modern versions of Windows, including Windows 11, the hosts file is in %SystemRoot%System32driversetchosts. The %SystemRoot% environment variable by default points to C:WINDOWS.
The hosts file contains lines of text with two columns. In the first column there is an IP address. And in the second column, there is a computer hostname. The two columns can be separated by a space or tab. So, an example hosts file might look like this:
192.168.0.10 bobpc
192.168.0.11 clairepc
192.168.0.129 printserver
If you add these entries to the host file on a device, then you can ping each host by name and the computer can resolve it to the corresponding IP address. For example, ping printserver would return a reply like this:
You can also use Fully Qualified Domain Names (FQDN) in a hosts file. For example:
172.217.23.238 google.com
The hostnames you add to the hosts file are not case sensitive. They can be in uppercase, lowercase, or a mixture of both. Be aware that the hosts file is sometimes used by hackers to redirect network traffic to malicious sites. That is why only administrators can edit the hosts file in Windows.
By default, the hosts file in Windows 11 doesn’t contain any valid entries. By that, I mean everything is commented out using the hash # symbol. Let start by opening the hosts file in Notepad.
You’ll see that there are two entries at the bottom that are both commented out. The first entry is the IPv4 address for localhost. And the second entry is the IPv6 address for localhost.
# 127.0.0.1 localhost
# ::1 localhost
But if you try to add an entry to the hosts file, you won’t be able to save it. The hosts file can only be edited by administrators because it is in a protected system directory.
There are two ways that you can edit the host file. The first involves making a copy of the original file and then replacing it. The second uses the command line to append a line to the hosts file.
The easiest way to edit the hosts file is to make a copy of it and then replace the original in the ‘etc’ folder.
192.168.1.10 BOBPC
This method uses the command line and is much faster than the method above.
echo 192.168.1.12 TOMPC >> %SystemRoot%System32driversetchosts
type %SystemRoot%System32driversetchosts
The easiest way to remove an entry is to open Notepad from the command line. The command line must be started with administrator privileges as described above.
notepad %SystemRoot%System32driversetchosts
Notepad will open the hosts file. You can add or remove entries and then save the file to disk.
And that’s it!
Related articles