Block ads on your Android phone (2010-04-15)

Search This thread

phaelox

Senior Member
Feb 28, 2009
119
17
AdFree is a fantastic program created by XDA user delta_foxtrot2 (see this thread in the G1 forum) to facilitate using your hosts file to block ad servers. This makes it extremely easy. Of course you will need root access!


Unfortunately I found some ads still weren't blocked and the last update to the AdFree hosts file happened 2010-02-27. So I decided to update the hosts file myself. I merged the hosts files from adfree/mvps/yoyo and added a bunch of mobile ad providers I've found myself. The list is free of duplicates and comments, so as to keep it as small as possible (it still amounts to about 635 kB).

To install this hosts file, you still need root access obviously:

  1. download the zip
  2. unpack it to the directory where adb.exe is located (if you don't know what adb is or how to get it running, please use the search)
  3. open a command prompt
Code:
adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 
adb push hosts.for.mobile.txt /etc/hosts
adb shell mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system

You might need to restart your phone. Also clearing the Android browser cache will apparently help in getting rid of already cached ads (worked for me, ymmv).


As for ethical discussions on blocking ads for free apps, blah. I don't so much have a problem with ads, as I do with the personal data that gets send to the ad providers. I'm talking about location data and whatever else they might want to know about my device and what I'm running ("analytics" is a fancy name for "we want to find out as much about you as we possibly can get away with").

Anyway.. use it, don't use it, up to you.

Last updated

15-4-2010 23:23 (20808 hosts blocked)


.
 

Attachments

  • hosts-file-for-android_2010-04-15.zip
    129.1 KB · Views: 21,743
Last edited:

Neejay

Senior Member
Jul 29, 2009
1,016
148
Atlanta, GA
Thanks for the updated hosts. So should we even bother with the program, especially if it doesn't get updated hardly at all?
 

phaelox

Senior Member
Feb 28, 2009
119
17
You're welcome!

If you push my hosts file, you don't need the AdFree app, but I wanted to acknowledge his work and give people a simpler alternative to using adb.

Best choice right now is my hosts file as it's simply more comprehensive.

Sent from my HTC Hero using the XDA mobile application powered by Tapatalk
 

Neejay

Senior Member
Jul 29, 2009
1,016
148
Atlanta, GA
You're welcome!

If you push my hosts file, you don't need the AdFree app, but I wanted to acknowledge his work and give people a simpler alternative to using adb.

Best choice right now is my hosts file as it's simply more comprehensive.

Sent from my HTC Hero using the XDA mobile application powered by Tapatalk
Understood. Yeah, it was a great start/beginning to blocking ads, but no updates. Thanks again.
 

tmayne

Member
Apr 18, 2010
10
0
Thanks! I've been looking for something like this for awhile. Real quick question: is getting "Data connectivity errors" in browser normal with this? It didn't start till I pushed this on my phone.
 

phaelox

Senior Member
Feb 28, 2009
119
17
Real quick question: is getting "Data connectivity errors" in browser normal with this? It didn't start till I pushed this on my phone.


Short answer: Yes.

Long answer:
You may know this, but I'll explain anyway. The way this works is as follows. The loopback address for any network interface is 127.0.0.1 -- this is the address for the device, but only from the device itself, it loops back on itself. We don't want to waste bandwidth with ads, or have ad providers collect all sorts of data on us, so we don't want to connect to them. Any FQDN -Fully Qualified Domain Name- (for example: analytics.admob.com) needs to be converted into an IP address to be able to connect to it. Here's where the 'hosts' file comes in. It's a simple text file with a record on each line that says redirect 'hostname' to 'ip-address'. So we put a line in that reads '127.0.0.1 analytics.admob.com'. This tells our device that any connection made to 'analytics.admob.com' needs to be redirected to '127.0.0.1', which is your device. Basically a dead-end, as you are not running their webserver serving ads on your device, so this results in a data connection error.

Now, usually you will surf to a site that loads images (advertisements) from a server that is listed in this hosts file, and as a result the ads will not load. That shouldn't popup any error windows. But if you try to visit http://analytics.admob.com in your browser, then yes, you will see an error.

If the latter happens with a site you do wish to visit, just open the hosts file in a text editor (one that supports UNIX-style line ends) and remove the line in question, or put a '#' in front of the line to comment it out.

Hope that made it clearer.
 
Last edited:
  • Like
Reactions: steppix

tmayne

Member
Apr 18, 2010
10
0
Yeah it did. No worries though since it seems that after pressing "Ok" everything works fine! Small trade off for blocked ads! Thanks!
 

carbonyle

Senior Member
Aug 23, 2007
81
0
Thanks for this How-TO!

So basicaly that mean we can restrict acces to certain websites from our phone?
eg: adding this line
Code:
127.0.0.1 xdaforums.com
and I'll no longer be able to browse XDA from my phone?

Keep writing such How-To, like this one and the one to sign update.zip, I found this interessant and usefull
 

phaelox

Senior Member
Feb 28, 2009
119
17
Yeah it did. No worries though since it seems that after pressing "Ok" everything works fine! Small trade off for blocked ads! Thanks!
You're welcome, glad I could help.

Thanks for this How-TO!

So basicaly that mean we can restrict acces to certain websites from our phone?
eg: adding this line
Code:
127.0.0.1 xdaforums.com
and I'll no longer be able to browse XDA from my phone?

Keep writing such How-To, like this one and the one to sign update.zip, I found this interessant and usefull
Cheers. :) And yes, that's exactly right. Just remember the hosts file takes FQDN's, so you can block a domain (or subdomain) this way, but not a directory or page on a domain. Also, blocking a domain does not also block its subdomains.

PS. this method of using the hosts file is not unique to your android phone, it works on most operating systems on PC as well. See this Wikipedia entry for more info.
 

bazzix

Senior Member
Nov 6, 2007
123
1
what about non rooted phones? I just got myself a htc desire, I'm happy with it but would be happier if I wouldn't be required to see all those ads.
 

phaelox

Senior Member
Feb 28, 2009
119
17
Unfortunately root is required to remount /system as writable to be able to overwrite the hosts file.

Without root you could use another free app found in Market called "AdBlock", which functions as a localhost proxy. Just set localhost as proxy in APN/wifi settings. It doesn't come with a prefilled list of keywords to block though, but it works on a URL level, not FQDN, so you can specify a url or part of it to block.
 

tmayne

Member
Apr 18, 2010
10
0
Just one more quick concern about the Data Connectivity issues: Certain areas of my university require a redirect page login in order to connect to wifi. However, it seems that at certain locations, I get the Data Connectivity error pop up repeatedly and my phone never makes it to the redirect page.

Actually it seems my phone only likes the wifi in my dorm. As stepping outside (to a library or classroom) and attempting to connect to the same wifi produces the error.

Is this an issue with the hosts file or with the phone itself??

Thanks!
 

phaelox

Senior Member
Feb 28, 2009
119
17
If you DO see the wifi redirect page at SOME locations, then the hosts file is not blocking it (wouldn't make sense as it's likely an intranet page anyway). Sounds like wifi reception is unstable on your phone.

This is getting off-topic, but..... Have you already updated your radio? (the part of the ROM that handles everything related to GSM/3G/WiFi/Bluetooth connections). If not, here for the latest radio update.zip - flash through recovery.
 

tmayne

Member
Apr 18, 2010
10
0
If you DO see the wifi redirect page at SOME locations, then the hosts file is not blocking it (wouldn't make sense as it's likely an intranet page anyway). Sounds like wifi reception is unstable on your phone.

This is getting off-topic, but..... Have you already updated your radio? (the part of the ROM that handles everything related to GSM/3G/WiFi/Bluetooth connections). If not, or the latest radio update.zip - flash through recovery.


I should note that I'm using a Motorola Cliq...Handler 1.5 ROM. There is a radio update available for the Motorola Cliq (I'm currently using 1.3.18 and 1.4.8 has been released) but there are some apk incompatibilities with it (particularly Swype which I love...since it's in closed beta right now, there are no accessible updates for it unfortunately).

Since I bought my phone off of ebay, I can't send it back for a new one. The essential things work but it is a bit frustrating that it has some problems.
 
Last edited:

carbonyle

Senior Member
Aug 23, 2007
81
0
I should note that I'm using a Motorola Cliq...Handler 1.5 ROM. There is a radio update available for the Motorola Cliq (I'm currently using 1.3.18 and 1.4.8 has been released) but there are some apk incompatibilities with it (particularly Swype which I love...since it's in closed beta right now, there are no accessible updates for it unfortunately).

Since I bought my phone off of ebay, I can't send it back for a new one. The essential things work but it is a bit frustrating that it has some problems.

I'm pretty sure that updating radio won't affect other softwares since "radio" is *just* the piece of code that can handle GSM/Wifi/BT/3G, ... signals
 

phaelox

Senior Member
Feb 28, 2009
119
17
I'll always keep an open mind, but from what I know, I'm with carbonyle on this.

Back on topic:

if you come across an app that still displays ad, regardless of my hosts file, please reply in this topic with the app/version (and a logcat output would be nice if you know how) and I'll see if I can find the ad provider domain and update the hosts file.
 

:No-Frost:

Senior Member
Sep 4, 2009
1,905
448
Santiago
twitter.com
Wooooooo thanks... worked like a charm in glympse shazam and others =D...

PS: Air Control still have adds... Mmm how can we know what's the host for the add in the apps so we can contribute into blocking them???
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    AdFree is a fantastic program created by XDA user delta_foxtrot2 (see this thread in the G1 forum) to facilitate using your hosts file to block ad servers. This makes it extremely easy. Of course you will need root access!


    Unfortunately I found some ads still weren't blocked and the last update to the AdFree hosts file happened 2010-02-27. So I decided to update the hosts file myself. I merged the hosts files from adfree/mvps/yoyo and added a bunch of mobile ad providers I've found myself. The list is free of duplicates and comments, so as to keep it as small as possible (it still amounts to about 635 kB).

    To install this hosts file, you still need root access obviously:

    1. download the zip
    2. unpack it to the directory where adb.exe is located (if you don't know what adb is or how to get it running, please use the search)
    3. open a command prompt
    Code:
    adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 
    adb push hosts.for.mobile.txt /etc/hosts
    adb shell mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system

    You might need to restart your phone. Also clearing the Android browser cache will apparently help in getting rid of already cached ads (worked for me, ymmv).


    As for ethical discussions on blocking ads for free apps, blah. I don't so much have a problem with ads, as I do with the personal data that gets send to the ad providers. I'm talking about location data and whatever else they might want to know about my device and what I'm running ("analytics" is a fancy name for "we want to find out as much about you as we possibly can get away with").

    Anyway.. use it, don't use it, up to you.

    Last updated

    15-4-2010 23:23 (20808 hosts blocked)


    .
    5
    Hello, since this is the top search result for this topic on Google I'd thought I'd share an update. This is a simple method:

    1. Boot into clockworkmod recovery
    2. partitions > mount /system
    3. adb push hosts /system/etc/hosts
    4. adb reboot

    No need to play with remount and permissions in recovery. Working on CM7 RC2 on HTC Aria. I have updated the hosts file using the sources in the comments as of March 8, 2011.

    Edit: Put mobile advertisers from original list back in and removed duplicates.
    2
    I've shamelessly stolen from the hosts files in this thread and then added my own to make an up-to-date list that mainly works for me.

    The file is sorted, (with the exception of the localhost entry), with duplicates removed.
    2
    caps are important - yes, however, it is strange that the hosts file is HOSTS on your Android ROM... but I guess nothing is impossible...

    @No-Frost: If you have Terminal Emulator and some Superuser app for granting root privileges, you can use the following:

    You need to place the hosts file on your SD card to begin with (in this example, the hosts file is: /mnt/sdcard/hosts.final)

    Next, you need to mount the filesystem in read-write mode, as it is read-only by default

    su
    mount -o remount,rw /dev/block/mtdblock3 /system
    mv /etc/hosts /etc/hosts.bak
    cp /mnt/sdcard/hosts.final /etc/hosts
    chmod 644 /etc/hosts
    mount -o remount,ro /dev/block/mtdblock3 /system
    ls -l /etc/hosts


    That should move the hosts.final file from the root of your SD card, into the /etc directory, and apply the filename: hosts

    Be weary of filenames and foldernames under linux - they are case-sensitive... you don't want System or ETC, etc.

    Once you've executed the last line in the script ls -l /etc/hosts, you should be able to verify that the hosts file exists, with the correct access rights.

    Maybe reboot at this point.

    Quit Terminal Emulator, open your browser, maybe clear the cache in the browser, and open one of the ad-servers listed in your hosts file, e.g.:
    http://00fun.com
    If the page fails to load, then everything worked!

    If you still get ads in apps or websites after the above test succeeded, then it could be that the specific app or website is sourcing it's ads from another host that is not yet in the hosts file, or via some other means...
    2
    Finally got it to work.

    Now there is no way I got this working from terminal app, adb + phone booted or default recovery mode (traingle screen). However if you boot into clockwork recovery mode, manually mount system and sdcard and than use the commands from this topic it will work.