How to Edit the Hosts File in Windows

The hosts file is a text-based file that resides in the same place in all modern versions of Windows. Most people never need to get into it, but if you do, you should know how to open and edit the hosts file.

However, some versions of Windows do not allow editing the hosts file directly. You will even get an error if you try to save the changes. Fortunately, there is a simple tip you can use to edit the hosts file in Windows 10, 8, 7, Vista or XP.

What does the Hosts file do?

The purpose of the hosts file was originally to be what: DNS servers do it now – map friendly domain names to unfriendly IP addresses.

It’s much easier to remember a domain name like YouTube.com than an IP address like 172.217.1.238† Instead of having to type the IP address into the address bar every time you want to watch YouTube videos, you can just enter the domain name and the DNS server your device uses will assign the name to the correct address, so you can at the web page a lot easier.

The hosts file, which serves as a kind of DNS server, works the same way. You can enter an IP address to which a domain name should be resolved. In other words, you can instruct your computer to load a different IP address than the DNS server would, essentially doing some nice things.

Why edit the Hosts file?

One reason to edit the hosts file is if you want a super easy way to: block websites from loading on your computer† Enter an invalid or wrong IP address for the site you want to block, and every time you try to open it, the hosts file loads the IP address you chose. Depending on what you have chosen, it can be cblock the website completely†

You can use the same technique to have the hosts file block malicious sites. There are even lists of hosts file entries (like these) you can download and import into your hosts file to block hundreds of malicious sites or ads.

Another use of the hosts file is to speed up web browsing. If the DNS server you are using is down or not running fast enough, by manually entering the IP address and domain name assignments in your hosts file, you can have your computer find these addresses almost instantly instead of relying on the DNS server.

Tip: Learn how to use alternate DNS servers to get faster Internet access.

Windows Hosts File Location

You need to know where to find the hosts file before you can open it for editing. This is the location of the hosts file in Windows 10 through Windows XP:

C:\Windows\system32\drivers\etc

How to edit the hosts file?

The hosts file is a text file, which means you need a text editor to make changes to it. However, since the hosts file is super simple and doesn’t need to work with hyperlinks, images, etc., you can use a simple text editor (ie no need to use a full-fledged editor like Microsoft Word).

Opening the Hosts file

Let’s start with simple opening the hosts file. We’re using Notepad, which is built into Windows 10 through Windows XP.

  • Open the Run dialog box by clicking the . to hold Windows key, then press R once.
  • Type notepad and then press Enter to open the program.
  • Go to File Open
  • Type (or copy and paste) into the file name text box at the bottom of the hosts file location shown above, then press Enter
  • Select the menu to the right of the text box to change Text documents (*.txt) until All files
  • Double click hosts

from the list of files to open the hosts file for editing in Notepad.

Editing the Hosts file

There are a few examples in the hosts file to show you how to format your input. You must put the IP address first, followed by the domain name, and the two must be separated by at least one space (a tab is a good way to format them).

Here are some examples:
127.0.0.1 www.google.com

13.249.79.104 www.bing.com As you can see in the image above and read from the directions in the hosts file, the

symbol is used as a comment, meaning anything that follows it is avoided. This is why the two example lines we provide above are helpful in this hosts file; they are not followed by that symbol.Related

: Edit hosts file to add local DNS lookup If you want to block websites with the hosts file, such as YouTube, Amazon, Google, Reddit.com, etc., you can enter a fake IP address, such as0.0.0.0

Remark

: When entering the URL of the site you want to associate with a specific IP address, make sure to exclude the initial part and type only the subdomain like www or whatever it is for the site you are adding.

Saving the Hosts file

  • Here’s how we save the hosts file to make sure it works no matter what operating system you’re using, what text editor you choose, or how your Windows settings are configured: Go to File Save as
  • change the Save as type option toAll files
  • Rename the file to
  • hosts.backup fileand then save it to your desktop.
    Close Notepad and locate the hosts file you just created on the desktop. You want the . backup file
    part of the name and leave alone
  • hosts
  • (without a period or text after the word).
  • After you’ve done that, click away from the file to something else on the desktop and confirm the name change when prompted. Copy the hosts file. Open the hosts file location you had previously opened (the
  • etc

folder). Paste the hosts file you copied from the desktop and confirm any overwrite prompts if you see them.

Leave a Reply

Your email address will not be published.