The hosts file on windows computers is used to bind certain name strings to specific ip addresses to override other name-resolution methods

Sometimes one decides to change the hosts file and discovers that the changes refuse to take effect or that even old entries in the hosts file are ignored thereafter There are a number of mistakes that can cause this and it can be frustrating to figure which one to blame

What's the best troubleshooting procedure for windows ignoring a hosts file?

This question has duplicates on SO, such as HOSTS file being ignored

These tend to deal with a specific case but once any mistake made by the op is discovered the discussion is over If you have not made the same error this discussion isn't very useful So I thought it would be more helpful to have a general protocol for resolving all hosts-related issues that would cover all cases.

Best Answer

Based on my own experience and what i encountered when googling here are some things i should try

1. Did you check that it works correctly?

The changes to hosts should take effect immediately but windows caches name resolution data so that they may be used for some time Open a command line (Windows+R, cmd , Enter) and type.

ipconfig /flushdns

To remove the old data To check if it works, use (assuming you have an ipv4 entry in your hosts for , or an ipv6 entry in your hosts for

ping -n 1
ping -6 -n 1

So you'll see if it uses the correct ip If yes, your hosts file is fine and the problem is elsewhere.

Also, you can reset the netbios cache with (open the console as an admin or it will fail).

nbtstat -R

You can check the data in the current dns cache

ipconfig /displaydns | more

NB: nslookup does not look at the hosts file. See NSLOOKUP and NBLOOKUP give one IP address; PING finds another

2. Basics

  • Should my host file be named correctly? It should be hosts and not host , etc.
  • Is this extension correct? It should have no extension ( hosts not hosts.txt ) - be careful if you have configured windows to hide known extensions, check the properties to be sure: The correct hosts file's type will show up as just "File".
  • Did you follow the correct syntax ? Did you accidentally prefix lines with a hash ( # ) which indicates comments?
  • Did you take care of all variants ( and - safest to just add both)?

3. Whitespace

The format for each line is IP address , then a horizontal tab (escape code \t , ASCII HT , hex 0x09 ) or a single space (hex 0x20 ), then the host name, ie. , then finally a carriage return followed by a line feed, (escape codes \r\n , ASCII CRLF , hex 0x0d 0x0a ).

Examples of entries using unicode control pictures to indicate control characters (Don't copy and paste these into your hosts file!)␉␍␊

The individual bytes may be viewed in Notepad++ with the hex editor plugin . Notepad++ will also show special characters (view -> show symbol) so you can easily inspect the number and kind of whitespace characters.

If you copy and pasted host entries from somewhere you may end up with multiple spaces In theory hosts supports multiple spaces separating the two columns, but it's another thing to try if nothing else works.

To be on the safe side, make sure all lines in your hosts file either use tabs or spaces, not both.

End the file with a blank line

4. Registry Key

There's a registry key specifying the location of the hosts file Windows doesn't support the option to set hosts in other files but you might want to check The key is


The entry should be.


5. Permissions

Sometimes there are issues with permissions on the file, the file attributes, and similar things. To recreate the file with default permissions.

  1. Create a new text file on your desktop
  2. Copy and paste the contents of your current hosts file into this file in notepad
  3. Save the new text file and rename it to hosts .
  4. Copy ( do not move ) the file to your %SystemRoot%\System32\drivers\etc directory, and overwrite the old file.

Last point is important: copying works, moving doesn't.

The local Users account must be able to read the hosts file . To make sure (in windows 7).

  1. Navigate to %SystemRoot%\System32\drivers\etc in Windows Explorer.
  2. If you can't see the hosts file, ensure you can see hidden and system files .
  3. Right-click on the hosts file and select Properties from the context menu.
  4. In the hosts Properties window, click on the Security tab.
  5. Examine the list of names in the Group or user names: box. If %COMPUTERNAME%\Users is present, click on it to view permissions.
  6. If Users is not present, or is present but does not have Read permission, click Edit... .
  7. If Users is not present, click Add... , type Users , click Check Names , and click OK or press Enter.
  8. Select Users , and ensure Read & execute is checked in the Allow column. Click ok. If a Windows Security alert box pops up, choose Yes to continue.
  9. Click OK to close the hosts Properties window.
  10. Go to section 1 of this answer and follow the instructions to check if it's working

6. Encoding

The hosts file should be encoded without bom in ansi or utf-8 You can do this by selecting file - save as

7. Proxies

If you have a proxy configured it might bypass the hosts file The solution is to not use the proxy or configure it to not do this

To check, go to your internet explorer -> internet options -> connections -> lan settings. If everything is blank and "automatically detect settings" is checked, you aren't using a proxy.

If you rely on a proxy to access the web and you don't want to disable it you can add exceptions to internet explorer - internet options - connections - lan settings - proxy server advanced Then add your exceptions to the text box exceptions e.g. localhost;;*.dev

8. DNS address

(This may also resolve proxy issues.)

Go to your network connections properties, then TCP/IP settings, and change the first DNS server to (localhost). The second should probably be your actual ip address in your dns system

This is not necessary for the hosts file to work , but it may help in your case if something is configured strangely.

9. .local addresses

If you are using a .local domain entry in the form of myhost.local and it gets ignored please try the following.

x.x.x.x myhost.local www.myhost.local

even if the www.myhost.local does not exist. Windows does not append its workgroup or localdomain

10. Line / count limits

(added to this answer to make it visible as it's been mentioned a few times)

A windows host file appears to have a line or limit If you have more than 150 characters on a line or more than 8 hosts entries for an IP create a new line

e.g. instead of.

Try this.