Easy Adware and Malware Blocking on Android

Letter box in brick wall.

Digital ads are a disaster. While ads themselves are a legitimate and often necessary source of income for service providers, the way they’re delivered to users can be downright malicious. On mobile devices, ads have been shown to drain battery life and surreptitiously deliver malware, without the content providers even being aware of it. Until content providers can get their act together, it’s up to users to protect themselves.

In this post, I’ll present a convenient, root-free way of blocking ads on Android devices using free and open source tools.

tl;dr: download Steven Black’s hosts file and the Vpn Hosts app from xfalcon.

How it Works

Vpn Hosts is an app that lets you use a custom hosts file on an Android device. A hosts file is a plain text file containing a list of IP addresses and DNS names. Whenever your computer looks up a domain name, it first checks for the domain in the hosts file and uses the IP address listed next to the domain. For example, if you wanted to open google.com in your browser, your computer would first check the hosts file for “google.com”, and if it was listed, it would return the associated IP address to the browser. This is known as domain name resolution, and it happens for almost every network connection your computer initiates. The nice thing about the hosts file is that it gives you direct control over the resolution process using nothing but a plain text file.

For example, this hosts entry maps DNS requests for localhost and loopback to the address 127.0.0.1:

127.0.0.1 localhost loopback

One interesting thing that the hosts file lets us do is provide invalid IP addressed. If we added a domain next to a bogus IP address – like 0.0.0.0 – any requests to that domain will immediately drop. You can use this to prevent your computer from connecting to a specific domain, such as one that distributes ads. As you might imagine, there are a lot of domains that serve ads, and trying to identify them all yourself would be an endless task.

That’s why Steven Black hosts (no pun intended) his unified hosts file, which contains tens of thousands of domains that either host or have hosted adware, malware, spam, gambling services, fake news, social networks, and other undesirable services. This list is constantly being updated by other developers and Steven Black himself, and since the list itself is a simple text file, you can modify it yourself or just download one of the pre-assembled versions. For this example, we’ll use the base version, which you can download using this link.

Installing the Blocker

Once you’ve downloaded the hosts file onto your phone, install the Vpn Hosts app from the Play Store. Vpn Hosts is an open source app that lets you apply a hosts file to all traffic on your smartphone. Best of all, it does this without requiring super user permissions. However, you do have to give it access to all of your phone’s network traffic. Just be mindful of this whenever you enable it.

Once the app is installed, simply open it and tap Select Hosts File. Select the hosts file that you downloaded, then tap the switch in the center of the app. And that’s it! As long as that switch is active, the hosts file is active and any domains included in the file will be blocked.

For a demonstration, check out this video:

 

Share your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.