Protect your computer from malware and phishing attacks by blocking malicious websites with the hosts file. Our guide explains how to edit the hosts file on Windows, MacOS, and Linux to prevent access to known malicious domains. Learn how to use third-party tools to update the hosts file automatically and enhance your online security. Prevent cyber threats and safeguard your personal information with this simple yet effective technique.
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 ?
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.
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: