Are you a developer who wants to test changes to their website before making them live? Or do you want to block access to certain websites on your home network?

how to edit hosts file on windows

A simple search on the internet will suggest you edit the hosts file on your computer and make changes to it accordingly to achieve your objective.

But what exactly is a hosts file? And how to edit the hosts file on Windows 10 or Windows 11? Let’s dive in to find out.

What Is a Hosts File?

A hosts file plays an important role in helping your computer find websites on the internet. It’s essentially a text file that holds website records, i.e., their domain names / hostnames and their associated IP addresses, for your system to look up to resolve domain names correctly.

Simply put, when you type a website address (like www.google.com) in a browser, your system needs to know its IP address to establish a connection. To do this, it first looks up the hosts files in the filesystem for a matching record. If it finds one, it connects to the website and displays it in the browser. Otherwise, it switches to DNS or Domain Name System to get the website’s IP address for domain resolution.

Clearly, the hosts file is useful, but it has its own share of problems. Prime of these is the complexity and inconvenience that comes with maintaining and keeping in sync huge records of domain names and IP addresses. As such, many operating systems today rely primarily on DNS to resolve domain names.

All of this, however, isn’t to say the hosts file holds no value today. In fact, it’s far from that idea, as there are many scenarios where the hosts file still plays an important role, which is why you’ll see suggestions to modify the hosts file on your system under different scenarios.

How to Edit Hosts File in Windows 10 and Windows 11?

Hosts is just like any other text file. This means you can edit it using any text editor, be it Notepad, which comes preinstalled on Windows, or your favorite third-party text editor.

But before you edit the file, it’s important to make a backup. Doing so ensures that if something were to go wrong because of your changes to the hosts file, you can effortlessly revert to the previous version and restore things to normal.

Here’s what the whole process looks like:

Step 1: Create a Backup

Whether your computer is running Windows 10 or Windows 11, you can backup the hosts file on your PC using these steps:

  1. Launch File Explorer.
  2. Navigate to this location: C:\Windows\system32\drivers\etc.
  3. Locate the hosts file, right-click on it, and select Copy from the context menu.
  4. Navigate to a location on your system you feel is safe and paste the hosts file here.

Alternatively, you can create a restore point, which will back up everything on your system all at once.

Step 2: Edit the Hosts File in Notepad

Once you’ve backed up the hosts file, editing it is as simple as editing any other text file. We’ve demonstrated the process below using Notepad, but you can use any other text editor.

  1. Click the Start button and search for Notepad.
  2. From the results on the right, click on Run as administrator, and when the User Account Control prompts to confirm full administrative access for the app, hit Yes.
    searching Notepad in Windows Start menu
  3. In the Notepad app, click on File > Open.
    opening a new file in Notepad
  4. When this brings up the File Explorer window, go to the hosts file location: C:\Windows\System32\drivers\etc.
  5. If no files are displayed on the screen, click the select dropdown box next to the File name box and select All Files (*.*).
    choosing the All Files filter to find the hosts file
  6. Locate the hosts file, right-click on it, and select Open with. Choose Notepad from the list of apps and hit Just once.
    using the Open with option to open the hosts file in Notepad
  7. Notepad will now open the hosts file in edit mode. Go ahead and make changes to the existing entries (if there are any) or add new ones as per your requirements. Beware of the syntax while you do this.
    Windows 11 hosts file open in edit mode in Notepad
  8. Once you’ve finished editing, save the hosts file by clicking File > Save. Or use the Ctrl + S keyboard shortcut.

Be Diligent With Your Hosts File Manipulations

Editing the hosts file is easy but demands due diligence at your end. You can’t simply open the file at will and make random changes; you need to be extra cautious when mapping IP addresses to host names since failing to do so can lead to incorrect domain name resolution, which may momentarily disable your access to a website. A good practice when dealing with hosts file is to always take a backup and double-check your changes before saving them.

Was this article helpful?
YesNo