Hosts file changes are not recognized in Windows 8
As I write this, it is August 2019. I am new to this problem (failure of "hosts" file commands to work or be active). I use Windows 8.1 on a powerful but older Dell desktop (XPS Gen5). My browser is Firefox (48; outdated, I know), and have Windows Explorer (11) available also. The root directory on my PC is C:.
I wanted to easily and effectively block online popup images from objectionable, unsolicited advertisers (originating from an otherwise innocuous webpage), but was unable to get the hosts file commands (intended to associate "evil" host names to the 127.0.0.1 local host IP address) to perform.
I tried MANY remedies (from various online forum sites) and was about to give up when it finally started working. Great feeling. The problem is, there may be multiple reasons why the hosts file commands do not work and you may have to identify and solve them all. Here are some (not all) things to check and try (please excuse those that are too basic for your level of expertise):
Be sure your hosts file is located in the
C:\Windows\System32\drivers\etc
(or equivalent) sub-directory/folder.-
Be sure your Registry has an entry here:
\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath
that points to the right hosts location; for example:
%SystemRoot%\System32\drivers\etc
(w/o quotes)"C:\Windows\System32\drivers\etc\hosts" also works when the location of Windows is "C:\Windows."
Be sure to edit and save the hosts file only with a reliable text file editor (e.g., Windows Notepad) that does not introduce any kind of hidden characters or add a file-name suffix (like ".txt") when you save the modified "hosts" file.
For convenience and simplicity as you are working, rename (e.g., to
hosts.sav
) or move and save somewhere safe the original hosts file and create (e.g., using Windows Notepad) and use a brand new, ANSI-type, temporary, test hosts file with just one command--something like: "127.0.0.1google.com" (w/o quotes)--followed by one completely blank/empty line (without a line return). (You can use any website. I choose the mighty Google.) (If necessary, insert a first line127.0.0.1<tab>localhost
also, for a total of three lines.) Use this test hosts file to easily, quickly, and definitively know whether the hosts file and its commands are "on" and active. If Google is not blocked on your browser, then hosts is not working or is being bypassed for some reason. But if Google.com (or your choice of test site) is blocked, hosts is working and you have a successful command wording pattern that can be repeated for other, real commands. You can then put a "#" in front of the Google line to disable it, or just delete that line, But that command is handy to continuously check the status of the hosts file (is it working?) as you edit the hosts file (and potentially introduce errors that then cause hosts not to work).-
Use the DOS command
ipconfig /flushdns
(w/o quotes) within the Windows "Command Prompt" function in between changes to the hosts file as needed. Much easier than rebooting. I found that rebooting is not necessary.
If you have the hosts file open in a text editor, make changes, and save hosts (w/o closing the editor) Firefox reacts to the changes (i.e., after hitting refresh or reload page buttons) without having to stop and restart Firefox. In contrast, Microsoft Internet Explorer (IE) requires that you stop and then restart IE in order for changes (e.g., access to a particular blocked website) to take effect.
Within the hosts file itself:
I (a) start the command line language (numeric IP address) at the far left without any leading spaces and consistently use a single tab to separate the numeric address from the alphabetic host name. I'm told a single space should also work, or maybe multiple spaces between address and host.) Regardless, it may be important to be consistent.
Make sure every line either starts with a "#" (for documentation) or is a command line, until you reach the last line. Then end with a completely blank line.
To reiterate, start every line with some kind of character, no blank spaces, until you reach the end of the file. Then,...
The last line should be blank (with NO characters, hidden or otherwise).
-
To block Google, for example, you can use either command:
127.0.0.1<tab>www.google.com
or
0.0.0.0<tab>www.google.com
With
127.0.0.1
you get the error message (in Firefox)Unable to connect.
With
0.0.0.0
you get the (Firefox) error messageServer not found.
The last thing I needed to do (that was preventing my finicky hosts' commands from working) was to eliminate "http://" or "https://" from the alphabetic hosts name. I was copying entire web addresses and placing them into the hosts file command line. Dumb rookie error by me. You do not appear to have that problem, but others might. The "www." from a web address (if present) does not appear to be a problem for hosts commands and in fact may be necessary. Experiment.