Block ads, social media, trackers and more
Here you going to learn how to block ads, trackers, social media, porn, gambling and any specific web-pages you want using the hosts file in your system weather it's Linux or Windows (and probably MacOS too).
1. Download the hosts file
Go to https://github.com/StevenBlack/hosts and select a hosts file variant that you want. (e.g. Unified hosts + porn + social). Download it by pressing the raw hosts link.
2. Replace your system's hosts file
Be sure to make a backup of your hosts file in case something brakes!
Linux
/etc/hosts
Windows (tested in win10, search online if not found on other versions)
C:\Windows\System32\drivers\etc\hosts
MacOS (Not tested)
/etc/hosts
Done. Try it out
If your new hosts file has social extension, try opening up facebook.com in your browser. If everything was done right it will not load.
You should update your hosts file every now and then (I think once a year is good enough) to make sure new sites get added to the list. The github repository is actively maintained for now, so go there and download new hosts file whenever you feel like you need to.
Extra stuff
You can also add any specific web address to your hosts file to block it from loading on your device
To do that open your hosts file in any text editor (vim, nano, notepad). Go to the end of the file and add the following line
0.0.0.0 domain_name.com
Replacing domain_name.com with a domain name you need. And save the file.
How it works
Whenever something on your system wants to connect to a domain, it first looks into the hosts file to find the IP address and then use it to connect to the server. If there's no needed entery in the file it goes to the DNS server and looks for IP address there.
As mentioned above the IP address we put inside the hosts file is 0.0.0.0 which is basically your computer or "This host on this network" according to IANA. But your host doesn't have this domain name configured, that's why it doesn't load. Weather it's you trying to connect to a social media or porn site or random sites trying to send requests to trackers and ads servers.