How to remove ads in Android

Posted on March 11, 2014 by Dan Keder

This is a very simple yet effective way to get rid of advertisements in Android apps – without rooting the device. In principle it is the same method that the Android AdBlock app uses: resolve all DNS queries for various ad servers to But AdBlock app requires a rooted device, which not everyone is able or wants to do.

So instead of mocking DNS queries on the phone or tablet we do it on the “next hop” device - i.e. home or company router. That will affect all devices connected to that network - all phones, tablets and computers. But this method also has a drawback - you need a capable router, ideally with root SSH access to it. What I use (and recommend) is a Raspberry PI with Raspbian.

Just put the following simple script into /etc/hosts.d/, make it executable and run it. You may have to create the directory /etc/hosts.d first. You can also run the script in cron so everything updates regularly.


curl '' > /etc/hosts.d/01hosts
curl ''> /etc/hosts.d/02hosts
curl '\ad_servers.txt'> /etc/hosts.d/03hosts
curl '' > /etc/hosts.d/04hosts

Raspbian uses dnsmasq to handle DNS queries so we need to tell it to consult the files in /etc/hosts.d before contacting the real DNS servers. To do it add the following lines into /etc/dnsmasq.conf:

# Disable ads in android apps

And restart the dnsmasq service:

/etc/init.d/dnsmasq restart

And that’s it, now you shouldn’t see any of the annoying ads anymore.