# Windows – How to edit hosts file in Windows 8? Defender says malware detected

hosts-filewindows 8windows-defender

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.

• 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

1. Open up Windows Defender.
• Press Win and write Defender and start the program.
2. Go to the Settings tab.
3. Select Excluded files and locations.
4. Press browse
5. Find and select the hosts file.
• Normally located at C:\Windows\System32\Drivers\etc\hosts
6. Press Ok.
8. 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:

• Again, normally in C:\Windows\System32\Drivers\etc\hosts