Block websites on Local.
Using the /etc/hosts
file to block access to malicious sites is an effective strategy for enhancing system security. By redirecting known malicious or phishing sites to a non-routable IP address like 127.0.0.1, you can prevent your system from connecting to these domains. This proactive measure helps shield your computer from potential threats such as malware infections, data breaches, and phishing attacks. Implementing these blocks in the /etc/hosts
file offers a straightforward and local solution for maintaining a safer and more controlled browsing environment.
🎧
To prevent access to specific websites on your local machine, follow these steps:
1. Open the /etc/hosts file:
Edit this file with root privileges.
$ sudo nano /etc/hosts/
2. Add entries to block websites:
To block specific domains, redirect them to 127.0.0.1 (localhost).
This will prevent your browser from accessing those sites.
For instance, to block pornographic sites, you could add those lines like this to your hosts
file:
127.0.0.1 examplepornsite.com
127.0.0.1 www.examplepornsite.com
127.0.0.1 is the IP address used to refer to the local loopback interface on a computer. It’s also commonly known as "localhost".
When you direct traffic to 127.0.0.1, it essentially means that the traffic is being routed back to the same machine, effectively preventing the computer from reaching external servers.
3. Flush DNS Cache (Optional)
Some systems store DNS lookups in a cache.
To apply changes immediately, you may need to clear the DNS cache.
The steps for doing this differ depending on the system.
• On systems with systemd-resolved:
- clear the DNS cache
$ sudo systemd-resolve --flush-caches
or
-restarting the systemd-resolved
service.
$ sudo systemctl restart systemd-resolved
If you’re unsure, you can simply reboot your machine.
Checking Website Access
To check if the websites are blocked, try to access them using a web browser or by pinging them:
$ ping whateveryouwanttoblock.com
You should see that the requests are not reaching the intended website.
Remember, changes to the /etc/hosts
file affect only your local machine and won’t block sites for other devices on the network. This method might not be fully effective, as users could bypass the restrictions. For more reliable blocking, use dedicated parental control software or services.
We hope you found these insights useful!