How to Edit the Hosts File in Windows 11?

How to Edit the Hosts File in Windows 11

How to Edit the Hosts File in Windows 11

A Hosts file is a simple text file that is used to map or resolve hostnames to a specific IP address. It is more often the first step in the Domain Name Resolution process. Along the same lines, some people also modify the Hosts file in Windows 11 to block access to the desired websites (via the localhost address).

Many users prefer this since it doesn’t call for the involvement of any third-party apps. All in all, there could be a plethora of reasons why one would carry out certain modifications to this file. So keeping all those plausible reasons in mind, this guide will outline the steps to modify the Hosts file in Windows 11. But before that, let’s try and understand the contents of this file.

What Information Does Hosts File Contain?

A Host file consists of the following three values (separated by spaces):

127.0.0.1 www.example.com #test
  • The first entry is the IP Address where a request will be redirected to.
  • Then the next value is the website address that you will want to redirect to.
  • The third and final value is the comment, which (always) starts with a hash and is optional.

These three values should be separated by spaces or tabs (the latter is preferred for uniform spacing).

Along the same lines, the Hosts file also contains a loopback address, which will be the same for all the users. When you open the Hosts file and scroll to the end, you shall see the following loopback address.

127.0.0.1 localhost loopback
::1 localhost

These values are included in every host file. Furthermore, the above is a perfect example of an IP address having multiple hostnames (i.e. localhost and loopback)

So with this, you would have got a decent idea about what exactly is a Host file and what all information does it beholds. Let’s now check out the steps to modify the Hosts file in Windows 11.

Steps to Edit the Hosts File in Windows 11 PC

  1. To begin with, use the Windows+E shortcut keys to launch File Explorer on your PC.
  2. Then copy-paste the below location in its address bar:
    C:\Windows\System32\drivers\etc
  3. You should see the Hosts file inside that ‘etc.’ folder. It is recommended that you take a backup of this file before proceeding ahead with the modifications.
  4. So copy this file and paste it to any preferred location of your choice. This will now act as a backup to the original file.
  5. Once the backup is complete, go back to the ‘etc.’ folder and now double-click on the Hosts file. Windows will now ask you the app using which you want to open this file.
  6. Select Notepad or any advanced text editor app of your choice. Once the selection has been made, click OK.
  7. The Hosts file will now open, and you may carry out the desired modifications.
  8. For example, if you wish to block a website, then scroll to the end of the file and add the following line:
    127.0.0.1 websitename.com
  9. Ensure to replace the websitename.com in the above command accordingly, but the localhost address should be the same for all the sites.
  10. For example, if you want to block Facebook, add the following line to the end of the file:
    127.0.0.1 www.facebook.com

  11. Now, if anyone tries to access Facebook, he or she will be redirected back to the localhost rather than the actual website, all thanks to the tweak that we have just made to the Hosts file.
  12. Anyways, once you have made the desired modifications, use the Ctrl+S shortcut keys to save all these changes.

Conclusion

That’s it. These were the steps to modify the Hosts file in Windows 11. If any tweaks made to this file end up causing any issues, then just replace the modified Hosts file via the backup one that you had earlier created. Apart from that, if you have any other queries, do let us know in the comments section below.