One of the easiest yet least known ways to drastically improve any PC’s ability to defend itself against malware such as adware or spyware is to simply redirect malicious websites using the hosts file.

What is a hosts file and how does editing it block malware?

Before we begin, let’s first talk about what a host file is. When a PC accesses the internet, it uses a DNS server to resolve domain names to IP addresses. Your PC then follows the IP addresses to the servers that will serve you a webpage or provide you with another service.

For example, when you type in, your PC will ask a DNS server what the IP address of is. The DNS server may then respond with something like which is then where your PC will go to find the webpage you’re looking for.

The hosts file allows your PC to bypass the DNS for the domain names and address that are specified within the file. As you may imagine, if we had a regularly updated list of malicious websites, we can easily redirect those websites to something like thereby preventing you from the possibility of getting infected by those websites. Additionally, if you are infected, a modified hosts file can also help block known adware and spyware as they’re no longer able communicate with the advertising servers they’re expecting to retrieve ads from.

Now that you’ve been convinced that editing the hosts file can significantly improve your online security, here’s how to edit it.


Edit the Hosts File

Step 1

Go to the Start Menu and type in Notepad. Right click on Notepad and click on Run as administrator. This is important! If you don’t do this, you will get permission errors when trying to save the modified hosts file.

Step 2

Once Notepad is open, go to File, then click on Open. Alternatively, you can also hit Ctrl+O.

Step 3

Click on the address bar, type in C:\Windows\System32\drivers\etc and hit enter. This should navigate you to the C:\Windows\System32\drivers\etc directory. You can also do this manually if you’d like.

Step 4

You should see an empty directory. Don’t worry. You haven’t done anything wrong. At the bottom right corner is a drop down menu that allows you to select the file type to show. The file type is Text Documents (*.txt) by default. Switch this to All Files (*.*).

Step 5

At this point, you should see a list of files. Select hosts and click Open.

Step 6

Once the hosts file is open, you can now copy a modified hosts file such as the hosts file from and paste it into your hosts file.

Step 7

Once the file is pasted in, go ahead and click on File then click on Save. Alternatively, you can also hit Ctrl+S.

That’s it! You’re now protected against known malicious websites. For even better protection, be sure to download other excellent anti-malware applications such as Malwarebytes or Bitdefender.