Alexander's Blog

Sharing knowledge with the global IT community since November 1, 2004

How to Edit Hosts File in Windows 8 or Windows 8.1

/
/
ad-mania

A “host” name is used by TCP/IP to identify a TCP/IP device on the network. What is a TCP/IP device? Well, every device that uses TCP/IP protocol to communicate on a network is considered a TCP/IP host. A computer, printer, tablet, and routers are all examples of TCP/IP devices. The HOSTS file in Windows (and other operating systems) is used to map host names to IP addresses. This allows communication over a TCP/IP network.

In previous versions of Windows, the hosts file was very easy to edit. In fact, it was so easy to edit that the bad guys started to use the file to do bad things to our computers by adding entries without our permission or knowledge. Those of us who are concerned about computer security started to make the HOSTS file read-only but the bad guys found ways to remove the read-only attribute and still were able to mess with the HOSTS file. In this article I won’t focus on how to protect your HOSTS file, instead I want to show you how to edit the file in Windows 8/Windows 8.1 because editing this file is not so easy anymore. Thanks to Microsoft, the HOSTS file is more secure in Windows 8 and requires additional steps.

In Windows 8/8.1 you will get an access denied error when you edit the hosts file, even when you are logged in as an Administrator. You can also try to edit the hosts file by starting the Notepad as an Administrator while logged in as an Administrator. You will still get an access denied error. The only way I know is to save the file to another location and then copy it back to the original location. By default the HOSTS file resides in C:\Windows\System32\drivers\etc folder. The HOSTS file is one of the few files in Windows that don’t have a file extension. When you edit the file make sure you do not save it as a .txt file or else it won’t work. Here’s the step-by-step procedure for editing the HOSTS file in Windows 8/8.1.

Editing the Hosts File

  1. Start Windows File Explorer and go to C:\Windows\System32\drivers\etc folder.
  2. Make a backup copy of hosts file by simply copying the hosts file and then pasting it. It will add a file called hosts_2. You might want to rename it something like hosts.old or hosts.original.
  3. Right-click the hosts file and select Open with.
    HostsFile01
  4. Select Notepad from the choice of programs displayed for you. If you do not see Notepad in the list, scroll down to the bottom of the screen and click the hyperlink Look for another app on this PC.
    HostsFile02
  5. Enter the IP address and the host name for each host you want to add to this file. The graphic below shows an example of what the entry would look like. Do not use the address and server name in the example. It is only used for demonstration purposes.
    HostsFile03
  6. Make sure there is no pound symbol (#) at the beginning of the entry or else it will be considered a comment and will be ignored by the system.
  7. On the menu, click File, Save.
  8. Change the Save as type option to All Files (*.*) so that the file will be saved without an extension. The default option is Text Documents (*.txt) and it will add the .txt extension to the file, which we don’t want.
    HostsFile04
  9. When you click Save you will get a message similar to the one below that you don’t have permission to save the file in this location. Click Yes and then save it to another location, like desktop or Documents folder.

    WARNING! Just before you click Save make sure the Save as type option is set to All Files (*.*). I have noticed that when I click Yes it keeps the Save as type option as All Files (*.*) but it changes the file name to hosts.txt, which I don’t want. Delete the .txt extension so your screen looks like the one in step 7 above and then click Save.

    HostsFile05

  10. Close Notepad.
  11. Navigate to the location where you saved the file. You may notice that even though you told Windows not to use a file extension it ignored your instruction and saved the file with a .txt extension. This is a Windows 8/8.1 (cough) “feature.”
  12. Rename the file to hosts. Do not forget the s at the end. You will see the following prompt that if you change a file name extension, the file might become unstable. Click Yes.
    HostsFile06
  13. Copy the hosts file and then navigate back to C:\Windows\System32\drivers\etc folder.
  14. Paste the file in the etc folder.
  15. When prompted, replace the file with the newer file.

If you would like to learn more about Host and NetBIOS name resolution methods then check out this article: Host & NetBIOS Name Resolution Methods.


Copyright ©2014 Zubair Alexander. All rights reserved.

  • Facebook
  • Twitter
  • Linkedin

7 Comments

  1. Hi, I seem to have a problem with my hosts file. It will not apply the changes I have made, and is saved as a .txt file. Is there anyway to rectify this mistake?

  2. Hi Allie,

    The answer is yes. I have clearly documented exactly what you are experiencing in this article including the fact that your file will be saved as .txt. Please follow all the steps in this article, especially steps 6-15.

  3. I tried exactly what this article teaches. However, when trying to replace the hosts file, the system rejects and states that “you need permission to perform this action.” Any solutions? Thank you.

  4. Mzarrini, when exactly are you getting the permission error? Is it in Step 9 or Step 14? If in Step 14 and you are logged in as Administrator then I would suggest you look at the folder’s permissions. Go to the properties of C:\Windows\System32\drivers\etc folder. On the Security tab click Advanced and verify that the account that you are logged in as has the proper permissions to modify the files. I have tried these steps on multiple Windows 8.1 computers without any problems. The message that I get when I copy the file in Step 14 is “You’ll need to provide administrator permission to copy to this folder.” Because I am logged in as an Administrator, all I have to do is click Continue to overwrite the file.

  5. Worked like a charm, thanks.
    The only thing i would suggest is when you go to the location where you saved the hosts file and it shows hosts -original.txt (or whatever you saved it as) and you rename it to hosts, you need to highlight the whole thing hosts-original.txt, then rename it and it will change the extension to a File. That part was a little confusing.

  6. Did everything as instructed but kept getting a message about the hosts file being already in use when I attempted to copy over it. So used “EMCO Move on boot” to rename the hosts file on the next boot, which it did. Then I had no trouble pasting my new hosts file to that folder. Hope this helps anyone who has same problem.

    Good luck.

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar