Why doesn't my HOSTS file redirect DNS in Windows 7?

16,592

Solution 1

Totally forgot about this open question. As it turns out, if you copy the contents of the file, paste it into a new Notepad, delete the original file, and then save HOSTS again to C:|Windows\System32\Drivers\etc then it works.

Solution 2

For Windows 7,

  1. Open Notepad in Run as Administrator mode.
  2. Now you can see these lines...

    # localhost name resolution is handled within DNS itself.
    #    127.0.0.1           localhost
    #    ::1                 localhost
    
  3. Add new line for your domain.

  4. After the change it will be like this...

    # localhost name resolution is handled within DNS itself.
    #      127.0.0.1             localhost
    #      ::1                   localhost
           10.40.0.9             xxx.com  
           10.40.0.10            yyy.com
    
  5. Now save the hosts file. If it prompts to save it elsewhere then you forgot to open Notepad as administartor.

  6. Go to Windows' command promt and run this command ipconfig /flushdns
  7. Open your browser and try to browse xxx.com and yyy.com etc. Should work fine.

Note to remove '#' sign, because 127.0.0.1 doesn't require the hosts file to resolve and the '#' sign denotes a comment line.

Solution 3

Have you tried running an IPCONFIG /Flushdns?

It may be that Windows 7 caches the lookups in a different way to older versions, leading to slightly different behaviour.

Share:
16,592

Related videos on Youtube

Sootah
Author by

Sootah

Updated on September 17, 2022

Comments

  • Sootah
    Sootah almost 2 years

    I've modified the HOSTS file on my Windows 7 machine in exactly the same manner as I have in the past on my Vista and XP machines; however it has had no effect.

    How do you redirect URLs in Windows 7 or enable the HOSTS file so that it acts as it did in the previous versions of Windows?

    • John T
      John T over 13 years
      Please post your hosts file
    • Stephen Jennings
      Stephen Jennings over 13 years
      Can you give a specific example? What is the configuration, what steps do you take to test it, what do you expect to happen, and what actually happens?
    • Andrew J. Brehm
      Andrew J. Brehm over 13 years
      I second post your hosts file. Also try the hosts file on the XP machine where the other hosts file works.
  • Sootah
    Sootah over 13 years
    Yes, I've tried that amongst many other things. I've currently NO idea why the HOSTS file seems to be completely ignored in W7.
  • 100rabh
    100rabh almost 12 years
    Please, please take a moment to read the formatting/Markdown help and keep it simple instead of unwanted garbage HTML
  • Rob
    Rob almost 12 years
    Upvote because this is the right way to do it.