yashsingh1/xdaforums huggingface dataset:
[Hero, G2 Touch General] designerfx:
Yes, essentially.

*BRIEF EXPLANATION OF HOSTS FILE FOR Non-technical folks* aka HOSTS 101

You are basically telling your phone (same works on your computer, FYI), that for a specific address, go to a specific location. We point it to 127.0.0.1 (this is a standard computer setting that is commonly known as localhost - it's defined as the device itself) as it is the most simple but you can also point things elsewhere. 169.0.0.1 and 192.168.1.1 will both work as well. You can't just put 0, you have to put all 4 parts of the numerical (IP) address. as in xxx.xxx.xxx.xxx. (you know, like 192.168.1.1 or whatever your IP is at whatismyip.com).

You're not really defining a site though, you're more defining everything that connects to that address. So you're not really blocking an ad specifically, you're blocking where the ad is downloaded aka that specific website/server. The list is huge because there are tons of sites that post ads, and lots of them have multiple names. Meanwhile, since it's a just a text list having a huge list doesn't affect your performance at all unless you had about 10-50 times more sites than the current host file has, which is like 20 thousand. So with maybe 200 thousand to 5 million, it might affect it - but that's super unlikely to be necessary. Remember, you already have a host list, we're just modifying it. This affects any connections on your device, not just the browser. Applications that say "open this website" will basically check the hosts file first, as well. So that's how you can block admob, etc. Remember, sites pay money monthly to have an address that you can go to over the net, so these kinds of things don't change that often and adding another 1 or 2 is not a difficult matter.

*extra stuff*:

For those who want to, you can also make a specific word go to a location as well. You could add for example google = 72.14.204.99 . This would mean you don't need to add www or .com at the end, that merely typing google and pressing go would send the device to google.com. Considering we have bookmarks anyway, this is useless on a pc but probably more useful on a phone. When you do this without putting it in your host file, you get to google anyway, but it takes longer. Reason is that your phone does a search for the word/words you're looking for and then either takes you to the site or takes you to google search results for that word.
[Hero, G2 Touch General] phaelox:
Just installed Air Control (free version of course) from Market, but it didn't show ads with my hosts file installed.

The dev did make a placeholder - that says to buy the pro version - where the ad would be, but that's not an advertisement pulled from internet, so can't be helped (blocked) via hosts file. However it doesn't display during gameplay. So if the placeholder annoys you, I recommend you support the dev. ;)

About how to get the info on the ad providers to contribute; you need to look at logcat output - it's Android's event log. You can do this by installing the free app aLogcat, or via DroidExplorer (Logcat viewer or DDMS), or install Android SDK Tools and run DDMS from there.

For "Air Control" Logcat tells me it's trying to pull admob ads, and not succeeding, as you can see here:

04-26 16:32:47.540: DEBUG/InetAddress(1388): ad.qwapi.com: 127.0.0.1 (family 2, proto 6)

04-26 16:32:47.680: DEBUG/InetAddress(1388): mm.admob.com: 127.0.0.1 (family 2, proto 6)

04-26 16:32:47.780: DEBUG/InetAddress(1388): r.admob.com: 127.0.0.1 (family 2, proto 6)

04-26 16:32:47.840: WARN/AdMob SDK(1388): Could not get ad from AdMob servers.

There's more about http connection errors/exceptions, with exact URLs, but these lines sum it up nicely.

Pssst..... already provided a 101 a few replies back. ;) Nice explanation though. One little thing however, strictly speaking, apps don't check the hosts file for name resolution. Name resolution (including checking hosts file) is done by the TCP/IP stack, via API calls. Otherwise it would be very easy for an app to not check the hosts file and simply resolve the FQDN, connect and get the ads regardless.
[Hero, G2 Touch General] imfloflo:
Is there any possiblity to use adblock's filter and run script each night to always have an up to date files.?

BTW Very usefull file.
[Hero, G2 Touch General] phaelox:
Well, I should have mentioned, AdBlock does not block ads in apps, only in your browser. That's according to the app's About screen, I haven't verified it myself:

Also, since AdBlock is somewhat like AdBlockPlus for FireFox, it also blocks based on URLs or parts of URLs. The hosts file I provide only lists domain names, which of course COULD be used in AdBlock, but I think AdBlock might get very slow if you added 20,000+ entries.

Anyway, to summarize; from best case to worst:

manual push - my hosts file(need root)

AdFree - hosts file (need root)

AdBlock - APN proxy (still ads in apps)

no ad blocking
[Hero, G2 Touch General] timothydonohue:
great work! out of curiosity, is the push destination the same if i am using app2sd?
[Hero, G2 Touch General] phaelox:
Yes, it is. Apps2SD only affects /data/app and /data/app-private.
[Hero, G2 Touch General] hanschke:
i try to do this with the root explorer but dont can look inside the host folder or is there another path?
[Hero, G2 Touch General] phaelox:
"hosts" is not a folder, it's a file without an extension. The folder is "/system/etc".
[Hero, G2 Touch General] MilkPudding:
Is it possible to use terminal emulator to install it? If yes, could you include the commands? Thanks :D
[Hero, G2 Touch General] beav_35:
Yes, it should be possible to use terminal emulator. Assuming that the file is in the root of your sd card try:

su

cp /sdcard/hosts.for.mobile.txt /etc/hosts
[Hero, G2 Touch General] Decaux:
Im apparently terrible at adb, so I had to go through root explorer. Enough of that; on my phone this thing just makes the add scenes white. Sure it blocks them, but I was hoping for one more graphical line in some apps.

Just to check, is this hosts-file just to make the adds go white, or are the file supposed to remove the add banner fully?
[Hero, G2 Touch General] MilkPudding:
It works SO well on those annoying ads. Thanks ;)

Just in case anyone uses the terminal, the full command is as follow

su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
cp hosts.for.mobile.txt /etc/hosts
mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system
[Hero, G2 Touch General] phaelox:
It only stops your phone from making any connection to ad servers. Nothing more or less. It saves you bandwidth (which can be a big deal if you're not on an unlimited data plan), and shields your privacy. Some apps have a dedicated space were they display the app, which is usually white, sometimes black. And other apps display the ad on top of other graphics, so when they're not loaded, you don't even notice. The latter case is very nice, but in case of the former, it's still much better than having ads.

Nice one! ;)
[Hero, G2 Touch General] tkm89:
This is brilliant, thanks! Keep up the good work!
[Hero, G2 Touch General] MilkPudding:
Hmm somehow it doesn't work on Cyanogen 5-test2 for me.

Edit: Nvm I figured out. Forgot about /sdcard
[Hero, G2 Touch General] youareme7:
IGN podcasts broken by ad blocking

This is a bit of an FYI, I haven't found a workaround myself on this one yet. If you have a podcast manager like Listen or ACast and subscribe to any of the IGN games podcasts, doing this will break the ability for them to stream or download. IGN seems to use pheedo.com to serve their podcasts which is also an ad server. There are several pheedo sites in this hosts file. So, if you try to just remove pheedo from it, you'll still get ads in your aps, but if you don't, you won't be able to get these episodes. I couldn't understand why there were errors downloading new episodes with ACast, this is the reason. If anyone has a good workaround for this I'd be glad to hear it. I'm sure I could just sync it with my computer and download it that way, but I rarely connect my Nex1 to a computer, so that would be kinda a pain and not so seemless and automatic.
[Hero, G2 Touch General] jmbneaf:
most excellent! kills ads in all apps!

subscribed!

Sent from my Nexus One using the XDA mobile application powered by Tapatalk
[Hero, G2 Touch General] jimbobmcginty:
Nice work.

Now I just need a tiny webserver sitting on my Hero, serving a 1x1 pixel jpeg to any request - I get "web page not available" where the ad should be.

Makes sense, seeing as I have no :80 service running.
[Hero, G2 Touch General] Airbag888:
I've been looking for this solution. Sadly my N1 is unrooted and I'm keeping it that way until Froyo.

On the ethical side, I understand devs need the revenue via ads and it helps keep those apps free. Sadly for me this means a lot of bandwidth used up only for ads on apps that dont even require an internet connection otherwise and since where I live there are no real plans (we have 150, 250 and 300MB plans PER MONTH for ridiculous amounts) I'd be better off paying for the app a 1 time fee and be done with it. But then updates via market become weird.

Btw I'd be glad if you turned this in an app that could discriminate between cellular Data connection and load the full adblocking host file and wifi connection (generally not bw limited here - home/work/etc) and use the normal host file.

And like jimbobmcginty said a super light http server to push a 1x1 black pixel tiled on the background of a page.

Obviously those are cosmetics, I'm just glad a way exists.

A bit off topic, I have netcounter but sadly it only shows total data usage per period, I'm looking for an app that can tell me data usage PER application, cause not even browsing (only gmail sync, twitter sync (per 1hr), fb sync (per 3hrs) I get to about 90MB used per day. I want to know what app is using up my bw :(

Thanks
[Hero, G2 Touch General] intronauta:
Great!! :)

There is any possibility to apply the changes without rebooting?.

When adfree update the hosts file, reboot isn't necessary.
[Hero, G2 Touch General] cauli:
SpareParts claims to do this but that is the one feature of it which has never worked for me on my gsm Hero running MCR 3.2. It does work for some people though, so probably relies on an OS or hardware feature I'm lacking.
[Hero, G2 Touch General] Airbag888:
It's working on my N1 Thanks. It seems to have it under battery usage but when you pick details of every app listed (I dont see a lot) it the amount of bytes in and out so I suppose that's a start.

It also seems that there's a record of what app's been using the network prior to install, so I suspect there's a sort of log somewhere. I wonder if it'd be possible to know where and get an app that reads it to give details.
[Hero, G2 Touch General] petsasj:
I know this question might sound stupid, but i'll ask it anyway.

Does this effect persist through ROM changes (+wipes)?

I believe the answer is no (pretty sure it is), but what the heck :)

Thanks!
[Hero, G2 Touch General] H3g3m0n:
It might be worth while changing the default host from 127.0.0.1 to 0.0.0.0 (actually I think technically it's an 'any' address, but that only makes sense for binding a listening socket as you can connect to 'any' its dropped).

127.0.0.1 is the loopback address which means the browser will try to make a connection to the local system and waste some time. The latter is the null ip address which should just get nuked before any connection attempt.
[Hero, G2 Touch General] phaelox:
Well, what happens is same as with adfree: the hosts file is replaced. Just to be on the safe side, I said reboot. Very well possibly it will work straight off, without rebooting.

You are correct, it does not persist when factory resetting or flashing new rom. The /etc directory is part of the system volume which gets wiped.

As I understand it, 0.0.0.0 is a special address for interfaces that are down, and received packets sent from a (local) source not expecting a reply. Could work, but never seen anyone use it in a hosts file, which makes me wonder. No idea how TCP/IP stack would handle it. If you try it, let us know.
[Hero, G2 Touch General] hanschke:
will there be a new update soon :confused:
[Hero, G2 Touch General] dazzling:
it's working :)

i just change cp /sdcard/hosts.for.mobile.txt /etc/hosts

because i put txt on my sd card

thank you for the lecturing everyone :)
[Hero, G2 Touch General] stegg:
sorry for my noobness...

using my rooted legend, with usb debug mode.

I enter the first ADB command (mount), it's ok, but the second one

adb push hosts.for.mobile.txt /etc/hosts

gives this error

failed to copy 'hosts.for.mobile.txt' to '/etc/hosts': Directory not empty

what can I do to copy this file? :)

btw the phone reboots itself after that error
[Hero, G2 Touch General] Igor02:
same here... any ideas?
[Hero, G2 Touch General] cryshop:
I got this message also, failed
[Hero, G2 Touch General] stegg:
done!

I successfully copied the hosts file on the legend.

OF COURSE you must be knowing rooting procedures and recovery and console command, and whatever happens it's not my fault.

instructions:

1) have your legend rooted, of course

2) put a suited hosts.txt file in the etc folder of your recovery directory, e.g. "C:\r4-legend-root\files\hosts.txt" --- in this way we 'll temporarily have the hosts.txt file into your phone

3) enter into recovery mode

4) in your administrator console on your pc, type:

adb shell mount -o rw -t yaffs2 /dev/block/mtdblock3 /system
adb shell cp /etc/hosts /system/etc/hosts
adb shell mount -o ro -t yaffs2 /dev/block/mtdblock3 /system

(the latter command returns "system busy" to me, maybe yours won't)

5) wait a couple of seconds, just for sake, then reboot your phone

et voilà :D at next reboot, the new hosts file works!

cool people may want to set hosts file properties, but I didn't do.

after all, at the next reboot the system is still read-only so it shouldn't be necessary to set permissions
[Hero, G2 Touch General] equk:
just wanted to say thanks for this :)

have put the hosts file onto my phone using ssh (cba plugging usb in) and seems to be working fine :D
[Hero, G2 Touch General] xlxl:
same for me
[Hero, G2 Touch General] Treatcon:
N1, CM 5.0.7.1-N1

Works flawlessly! Thanks!! BTW the ADB commands in the zip worked fine for me.

adb remount
adb push hosts.for.mobile.txt /etc/hosts
adb reboot
[Hero, G2 Touch General] Szadzik:
Problems Here

Hi everyone,

So I uploaded the hosts file to /etc, rebooted and cleared browser cache and still seeing ads in my apps.

Can anyone help?

I copied the hosts file using root explorer, do I need to set permissions to the hosts file?

I am running a stock Milestone ROM, rooted of course and used to use AdFree but it stopped working.

TiA,

Szadzik
[Hero, G2 Touch General] nesquix:
Adfree don't work on Htc Desire with froyo.. just reboot my phone.. is there another solution ?
[Hero, G2 Touch General] ionstorm3:
Detect ad servers

Hi I was wondering how to detect ad servers on android. In OSX there is an app called Little Snitch that will detect outgoing connections and report the url. I was wondering if there is a way to detect outgoing connections' urls in android. If so then I could add those to my phone's hosts file.
[Hero, G2 Touch General] tbrummell:
Logcat.

The message you have entered is too short. Please lengthen your message to at least 10 characters.
[Hero, G2 Touch General] ionstorm3:
Umm, I looked at logcat and saw the log file for my phobne, but i do not see any urls. The only 3 urls I see in the log file are from google. Where are the urls for the ads in the apps? I installed apps with ads in them just to test out the log file, but I dont see the urls that the adds are requesting. How exactly do I find the urls or IP addresses?
[Hero, G2 Touch General] pulser_g2:
I don't think you will necessarily see the URLs of the ads in logcat. Usually only google-related stuff writes to logcat the URLs (or at lease it's mainly native apps in my experience).

I think the best way to do this would be to connect by WiFi, and use a protocol analyser on a PC (dunno if one exists for android) to get the URL out of the http packets.

But is it worth it? It's a lot of work to remove a couple of little adverts.
[Hero, G2 Touch General] Migel0:
I get: failed to copy 'hosts.for.mobile.txt' to 'etc/hosts' : Directory not empty

I'm using HTC Desire (rooted)
[Hero, G2 Touch General] fanello123:
Try flashing this zip file, it worked for me.

http://www.android-hilfe.de/374000-post54.html
[Hero, G2 Touch General] Hacre:
Sounds like on some of these phones, /system/etc/hosts is a directory.

Try adb ls -al /system/etc/hosts and report back.

By the way, for the install instructions, there's no need for a reboot after updating /system/etc/hosts.
[Hero, G2 Touch General] TEEDLE_21:
Just wondering...what would I have to do to undo this?

Would it just involve removing the hosts.for.mobile.txt file or something far more complex?
[Hero, G2 Touch General] ionstorm3:
answer

Just replace new hosts file with original hosts file. This will undo the entire process. Do not delete, rather replace.
[Hero, G2 Touch General] TEEDLE_21:
Does anyone have the original hosts file? I didn't think to back my up.

HTC Incredible BTW
[Hero, G2 Touch General] ionstorm3:
If you dont have the original, just delete all text in the hosts file that you have now, then save the file as the new hosts file. Simple as that. Will undo entire process. Alternatively you could just comment out (put a # infront of) all the lines, but thats a waste of time.
[Hero, G2 Touch General] OrganizedFellow:
Researched.

Tested.

DONE!!!

Successful on NexusOne running MoDaCo Froyo FRF85B

don't forget to backup your hosts file!!!
[Hero, G2 Touch General] Rptynan:
Great Thanks!!

This is awesome, thanks!!

Btw, my unistaller app (apex uninstaller) checks if you're blocking ads and then won't let you use the app if you are:(. Going to look for a new app..(any suggestions?)
[Hero, G2 Touch General] wakedmichel:
hi all great members,

does anyone know if this work on samsung galaxy s? thanks in advance
[Hero, G2 Touch General] uk786:
Works!, Thank you very much.
[Hero, G2 Touch General] frans0023:
GREAT mod :p

Thank you so much !!!!!!
[Hero, G2 Touch General] phaelox:
Instead of using ADB, try this in a terminal emulator app (like SUFBS or search market for a free app):

su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
cp hosts.for.mobile.txt /etc/hosts
mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system

That's right, except a standard hosts file needs at least one line for the loopback address:

127.0.0.1 localhost

For me, the ads I was hunting did actually show up in logcat, but I guess it would depend on the app and it's verbosity in logging. If anyone knows how to set a proxy for the Wifi connection, you could use Webscarab proxy on your PC to see all HTTP requests. I would love to know this, I haven't looked into setting a proxy for wifi yet.

Also I'm updating the hosts file very soon.... so those thinking "why doesn't he update more often?"; I didn't come across any ads my hosts file wasn't blocking, and no one posted about any apps that still showed ads, so no update seemed necessary. But MVPS has released updates since, so I'll update.
[Hero, G2 Touch General] croques:
Annoyed of Tunbridge Wells....

I'm still getting ads!!

I've merged hosts.for.android.txt with the contents of http://pgl.yoyo.org/adservers/serverlist.php?showintro=0&hostformat=hosts ; I've sorted the file; removed duplicates and added googleads.g.com.

The file has been successfully pushed to /system/etc/hosts. It sits there with rw permissions. But still I get ads.

I find them in Astro file manager and Mixzing. The last one is pretty annoying as it contacts data.flurry.com to tell them where I am.

I un-installed mixzing, removed its left-overs with a shell command and re-booted. Re-installed mixzing. Still I get ads

All the foregoing is true if I'm using the phone network for a data connection.

If I use wifi, ads are blocked.

So... how can I make the phone's data connection read the hosts file??? Or what have I missed? (And please don't say buy the apps! I really enjoy the anarchy despite being a paid app developer myself!)
[Hero, G2 Touch General] tigershouse:
The WordPress for Android app's stats tab doesn't work if you have this installed. Any reason why stats.wordpress.com is blocked?
[Hero, G2 Touch General] lychnecross:
It is probably blocked because somewhere along the line of development of the hosts file, someone thought it was a malicious tracking site. Just open the hosts file in a text editor, search for stats.wordpress.com, and delete the line.
[Hero, G2 Touch General] myth1001:
I'm in Malaysia and non of the ads are blocked. I wonder where can I find host list for my region so that I can edit the host file manually myself.
[Hero, G2 Touch General] lychnecross:
The only regional list site I can think of is Fanboy's adblock lists. Its not entirely a hosts list; however, his ad block lists are general enough to be ported over easily enough (plus he's very helpful too). Due to forum restrictions (and me being a noob member), I cannot post the link to his site, so just google the terms "fanboy adblock list" and you'll find it.
[Hero, G2 Touch General] projectDz:
Hello, I am also having the problem of ads showing up when I am on 3G. It works find when I'm on WiFi. Doesn't anyone know why, or how i can fix it? Thanks.
[Hero, G2 Touch General] croques:
I asked this question at #74 and got no response. Good 'ere innit?

It appears when on wifi the hosts file is read and used first for all dns lookups. When on 3G you're using the proxy server of your airtime provider which does not consult your hosts file. However, some applications, like the web browser do seem to have some independence and apparently use the /system/etc/hosts file for first dns lookup.

Additionally, the nslookup function that is provided in the current kernels is broken.
[Hero, G2 Touch General] projectDz:
^Thanks for explaining it... for awhile I thought something was wrong with it. Hope this gets an update soon.
[Hero, G2 Touch General] akuma24:
I may get alot of stick for saying this but...

.....the ads support developers that provide free apps, giving android users more choice, it doesn't cost you any thing to click on an add, so why disable them?

:confused:
[Hero, G2 Touch General] croques:
It is a point of view. However, an advert that appears on my handset has arrived there at my expense; using my bandwidth; taking up my time. I'm sorry, but I, for one, won't play that game.

If I never saw another advert in my lifetime... it would be too soon. But if you wish to be a good model consumer; a marketing man's wet dream; then consume away. The words 'poor' and 'sap' come to mind.
[Hero, G2 Touch General] james_2k:
erm, when i try to follow the instructions it wont let me saying 'cant push insufficient permissions' or something ive tried setting /etc/hosts to 4755 with chmod but no joy.. :(
[Hero, G2 Touch General] pulser_g2:
Did you remount the file system with adb remount first?
[Hero, G2 Touch General] pharaohdk:
Have not read trough the whole topic.

Do anyone know if this works on a sgs?
[Hero, G2 Touch General] btdag:
Well said that man!

@pharaohdk - first read the topic - why should we do that for you? - secondly - try it but remember to backup any files your changing
[Hero, G2 Touch General] slackwaresupport:
anyone got an update??? now the greystripe site has come in with ads..

thanks
[Hero, G2 Touch General] croques:
This site updates around every two weeks:-

http://pgl.yoyo.org/adservers/serverlist.php?showintro=0&hostformat=hosts

You'll need to add 127.0.0.1 localhost
[Hero, G2 Touch General] nolimit78:
Awesome, Thanks for finding and sharing.
[Hero, G2 Touch General] ratratrat:
I love this app!

Can't say how much I like this. hehehe

Glad I'm Rooted~~

Thx
[Hero, G2 Touch General] someonenewhere:
adfree failed to remount system partition read-only.

does anybody know how to fix this problem????
[Hero, G2 Touch General] tsheeley:
You mean this?

mount -o ro,remount /system
[Hero, G2 Touch General] techgeekandmore:
Thank you

Just wanted to add my thank you for this. Used it on my EVO and it worked perfectly.