Based on my own experience and what I encountered while Googling, here are some things to try:
1. Did you check that it works correctly?
Changes to hosts should take effect immediately, but Windows caches name resolution data so for some time the old records may be used. Open a command line (Windows+R,
cmd, Enter) and type:
To drop the old data. To check if it works, use (assuming you have an ipv4 entry in your hosts for www.example.com, or an ipv6 entry in your hosts for ipv6.example.com):
ping -4 www.example.com -n 1
ping -6 www.example.com -n 1
And 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):
You can check the current data in the DNS cache with:
ipconfig /displaydns | more
nslookup does not look at the hosts file. See NSLOOKUP and NBLOOKUP give one IP address; PING finds another
- Is your hosts file named correctly? It should be
hosts and not
- Is the extension correct? It should have no extension (
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 (
example.com - safest to just add both)?
The format for each line is
IP address, then a horizontal tab (escape code
0x09) or a single space (hex
0x20), then the host name, ie.
www.example.com, then finally a carriage return followed by a line feed, (escape codes
Sample 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 copied and pasted hosts 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.
Lastly, terminate the file with a blank line.
4. Registry Key
There is a registry key specifying the location of the hosts file. Supposedly, Windows doesn't actually support putting the hosts file in other locations, but you might want to check. The key is:
The entry should be:
Or, in a Command Prompt window, type:
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters -v DataBasePath
which should display something similar to:
DataBasePath REG_EXPAND_SZ %SystemRoot%\System32\drivers\etc
Sometimes there are issues with permissions on the file, the file attributes, and similar things. To recreate the file with default permissions:
- Create a new text file on your desktop.
- Copy and paste the contents of your current hosts file into this file in Notepad.
- Save the new text file and rename it to
- 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.
Users account must be able to read the hosts file. To make sure (in Windows 7):
- Navigate to
%SystemRoot%\System32\drivers\etc in Windows Explorer.
- If you can't see the
hosts file, ensure you can see hidden and system files.
- Right-click on the
hosts file and select
Properties from the context menu.
- In the
hosts Properties window, click on the
- Examine the list of names in the
Group or user names: box. If
%COMPUTERNAME%\Users is present, click on it to view permissions.
Users is not present, or is present but does not have
Read permission, click
Users is not present, click
Check Names, and click OK or press Enter.
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.
- Click OK to close the
hosts Properties window.
- Go up to section 1 of this answer and follow the directions to check if it's working now.
Or, in a Command Prompt window, type:
which should display something like:
C:\WINDOWS\System32\drivers\etc\hosts NT AUTHORITY\SYSTEM:(F)
APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(I)(RX)
APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES:(I)(RX)
You should see an
The hosts file should encoded in ANSI or UTF-8 without BOM. You can do this with File -> Save As.
If you have a proxy configured, it may 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 therefore don't want to disable it, you can add exceptions by going to Internet Explorer -> Internet Options -> Connections -> LAN settings -> Proxy Server / Advanced. Then add your exceptions to the Exceptions text box. e.g.
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
127.0.0.1 (localhost). The second should probably be your actual DNS's IP.
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 somehow 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)
Windows hosts file seems to have a line or host 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:
18.104.22.168 host1.com host2.com host3.com host4.com host5.com host6.com host7.com host8.com host9.com
22.214.171.124 host1.com host2.com host3.com host4.com host5.com
126.96.36.199 host6.com host7.com host8.com host9.com
chrome://flags/->Secure DNS lookups -> disable.
chrome://net-internals/#sockets-> Flush Socket Pools worked for me. (But I need to repeat it, or else restart Chrome, every time I change the hosts file.)