In this guide I will be showing you how to quickly and easily block advertisements on your desktops using your systems /etc/hosts file. You may be asking why block ads using this method when there are plenty of ad-blocking plug-ins available? The answer is simple, those don’t block advertisements for your entire system and outside of your browser.
This method will reroute any traffic that would of gone to the ad servers directly back to yourself (127.0.0.1) which also means things may speed up a bit if you have a slow connection or older model computer.
Setup host.conf File
So lets get started by making sure our hosts file isn’t being ignored. More than likely you can skip this step although it won’t hurt anything. What we are doing is making sure that your system checks your hosts file before sending a DNS request. To do this you can simply run the following command.
sudo echo 'order hosts,bind' >> /etc/host.conf
Setup /etc/hosts File
First if you don’t already have curl installed then you will need to install it with one of the following commands based on which distribution you are using.
sudo apt-get install curl -y # Ubuntu / Debian / Linux Mint sudo yum install curl -y # Fedora / CentOS
Next we will use curl to grab a massive list of ad servers and insert them directly into the hosts file, this will add thousands of entries which will redirect any ad server requests back to your computer. Since your computer doesn’t serve ads, the ads will never appear.
sudo curl -s http://winhelp2002.mvps.org/hosts.txt >> /etc/hosts
Congratulations, you are done. You should now be able to browse the web and use your favorite applications without the annoying advertisements. Please note that currently Chrome and Chrome based browsers ignore the hosts file, for those browsers you will need to use an ad blocker instead.
I hope you enjoyed this quick and easy guide, please don’t forget to like, comment, and share for more guides. Thanks!