9

When i make changes to the hosts file in windows 8, it doesn't work. Although my changes stay in the hosts file.

What I'm trying to, is to redirect the domain name riddergarn.dev to 127.0.0.1 with this line:

127.0.0.1 riddergarn.dev

I use avast! and Windows Defender is disabled, so that's not causing the problem. I have tried ipconfig /flushdns in CMD, but it doesn't solve it either.

I have tried searching for the answer on various sites, but with no luck so far. Maybe someone could help me out.

EDIT: Disabling avast! did not not solve the problem.

My hosts file (example.com doesn't resolve to 127.0.0.1 either):

# localhost name resolution is handled within DNS itself.
127.0.0.1       localhost
#   ::1             localhost
127.0.0.1       riddergarn.dev
127.0.0.1       example.com

My %SYSTEMROOT% is C:\Windows

I don't use IIS, but Apache instead.

When I try to ping the domain I get the following:

C:\Users\Andreas>ping riddergarn.dev
Ping request could not find host riddergarn.dev. Please check the name and try a
gain.
2

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 line 127.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 message

    Server 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.

| improve this answer | |
-1

Are you using Internet Explorer? In my experience you need to restart the IE for hosts changes to be recognised (other browsers will pick up changes straight away).

| improve this answer | |
  • I have tried that with both IE and Chrome, thanks anyway. – alysdal Feb 6 '13 at 16:27
-1

Windows 8 (specifically windows defender) blocks edits to the hosts file.

There's an option in defender to exclude files from this protection.

See this link for specifics: http://www.howtogeek.com/122404/how-to-block-websites-in-windows-8s-hosts-file/

| improve this answer | |
  • That would just revert any changes, it wouldn't make any program ignore them. – Mario Nov 4 '14 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.