Thousands of malicious websites proliferate on the Internet. They can infect your PC with malware that can steal and destroy your personal data.
Today, we will see how to block malicious sites using the hosts file.
Using hosts file, you will be able to prohibit the maximum number of malicious websites from communicating with your computer !
how to know the addresses of malicious websites ?
There are users who are responsible for making lists containing the addresses of all the malicious websites they have spotted. You just have to copy one of these lists (there are several) and put it in your system. To be more precise, it will have to be copied into the hosts file of the operating system. The hosts file allows, among other things, to block access to websites that it is indicated.
How it works ?
To block a website with the hosts file, just note the domain name of the site (ex: site-web-mechant.net) and the invalid IP address (ex: 127.0.0.1)!
So, when a malicious site forces you to connect to another site that hosts exploits or malware, with the hosts file, your PC will connect not to the site’s real IP address, but to the invalid IP address you entered for example (0.0.0.0) : there will be no connection between the malicious site and your PC !
How to block a website with hosts file
Suppose you want to block the network connection between Facebook and your computer.
We will edit the hosts file located in the C:\System32\Drivers\etc\directory (on Windows) and block the domain name of Facebook. Or rather domain names ! because Facebook has several domain names all linked together.
Here are the addresses that we will have to block :
www.facebook.com facebook.com static.ak.fbcdn.net www.static.ak.fbcdn.net login.facebook.com www.login.facebook.com fbcdn.net www.fbcdn.net fbcdn.com www.fbcdn.com static.ak.connect.facebook.com www.static.ak.connect.facebook.com fr-fr.facebook.com
Let’s go (example on Windows):
- Open the hosts file as administrator :
- Open the Run command.
- Enter the following command:
- Press CTRL + SHIFT + Enter.
- To block a website, create a new line at the bottom of the file using the following format:
127.0.0.1 [space] nom-de-domaine-du-site-web-a-bloquer.net
In our example with Facebook, we will add the following lines to block all domain names linked to Facebook :
127.0.0.1 www.facebook.com 127.0.0.1 facebook.com 127.0.0.1 static.ak.fbcdn.net 127.0.0.1 www.static.ak.fbcdn.net 127.0.0.1 login.facebook.com 127.0.0.1 www.login.facebook.com 127.0.0.1 fbcdn.net 127.0.0.1 www.fbcdn.net 127.0.0.1 fbcdn.com 127.0.0.1 www.fbcdn.com 127.0.0.1 static.ak.connect.facebook.com 127.0.0.1 www.static.ak.connect.facebook.com 127.0.0.1 en-fr.facebook.com
- Save the file: Ctrl + S.
Now try to connect to Facebook by typing facebook.com.
Access to Facebook is now blocked.
You see that it is quite easy to block access to a website ! You can also use this hosts file as a parental filter to protect your children from certain inappropriate websites. Like Facebook !
See below how to get pre-filled list of thousand malicious links of porn sites and offensive content.
Block X sites and offensive content
If you are a parent or a school and want to protect your children or students from inappropriate sites such as pornographic sites, follow this tutorial: