How to edit hosts file in Windows 8? Defender says malware detected
I've tried editing it in the same way as in Windows 7. E.g. opening Notepad/Notepad++ as Administrator and then opening the file and save it.
Right after saving it Windows Defender will say Malware Detected. Closing the hosts file and opening it again will give me the default hosts file, with my changes removed.
How can I modify the hosts file and have my changes kept?
There are several reasons to edit the hosts file. To block web sites, but mainly my reason for modifying it is when developing web services. Mocking a server and have the program believe it's talking to the real server makes testing much easier.
Solution 1:
Windows Defender is treating these changes as malware. This is because changing the hosts file is something malware does. It's an effective way to trick people, since they think they are visiting the real website, for instance facebook.com, but are in fact really talking to a malicious (phishing) server.
What we need to do is disable Windows Defender's protection of the file. Note that this may open you up for the attack mentioned above, so it shouldn't be done unless needed.
Exclude the hosts file from Windows Defender
- Open up Windows Defender.
- Press Win and write Defender and start the program.
- Go to the Settings tab.
- Select Excluded files and locations.
- Press browse
- Find and select the hosts file.
- Normally located at
C:\Windows\System32\Drivers\etc\hosts
- Normally located at
- Press Ok.
- Press Add.
- Press Save changes.
Now the hosts file is not protected anymore, so we can finally:
Edit the hosts file
You need Administrator privileges to edit the hosts file, so open up your text editor as admin. How to do it with Notepad:
- Search for Notepad in your apps.
- Right click it and select Run as administrator.
- Press Yes if UAC appears.
- Press File -> Open and navigate to the hosts file.
- Again, normally in
C:\Windows\System32\Drivers\etc\hosts
- You may have to select All files instead of Text Documents in the lower right corner.
- Again, normally in
- Edit the file to your liking and save it.