• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help Blocking websites via the hosts file

LTK

Lurker
Dec 10, 2017
5
0
I've read that you can block websites by editing the hosts file in /system/etc but I haven't gotten this to work. I gave file manager root privileges and copied hosts to storage, and because none of my text editors would recognise it I renamed it to hosts.txt. Then I edited the file, renamed it back to hosts and copied it to the original directory, overwriting the older version. It doesn't give me any error messages, yet the website I want to block is still reachable. I tried including and excluding http://, https:// and www. What am I doing wrong?

The file looks like this now:

127.0.0.1 localhost
::1 ip6-localhost
127.0.0.1 http://www.imgur.com
 
Always delete your web browser's app cache after you've altered your hosts file. Rebooting can affect what DNS servers are in use but that won't delete the local DNS info held in the browser app cache.

Also, I'd avoid including http or https as some sites do retain both for some situations, and avoid www too as it's a legacy issue where a lot of sites don't even require it anymore.
 
Upvote 0
Always delete your web browser's app cache after you've altered your hosts file. Rebooting can affect what DNS servers are in use but that won't delete the local DNS info held in the browser app cache.

Also, I'd avoid including http or https as some sites do retain both for some situations, and avoid www too as it's a legacy issue where a lot of sites don't even require it anymore.
Ah, thanks, I could never figure out when those URL prefixes are required or not.

Now, I changed the entry in my hosts file to just imgur.com, cleared the browser cache, rebooted... no change. Maybe I should give Ad-Away a shot.

Edit: Well, I see a problem. The block works correctly on the default browser, but accessing the internet through any other browser (Chrome, DuckDuckGo) doesn't block it. Is that supposed to be the case?
 
Last edited:
Upvote 0
Host level ad blocking should affect everything on the phone, including those annoying in-app ads you normally cannot otherwise get rid of. That's kind of the whole point of it. Who knows what Chrome is doing, but I consider Chrome to be spyware with a browser front end (on all platforms) and don't use it anyway. Use FireFox, IceCatMobile, Torfox, or another open source browser. All those I mentioned are also available in F-Droid (a Free* Software repository), the same place you will find AdAway.

*as in freedom, not cost, more info here: https://www.fsf.org/about/what-is-free-software
 
Upvote 0
Host level ad blocking should affect everything on the phone, including those annoying in-app ads you normally cannot otherwise get rid of.
That's what I thought as well. So why doesn't it? For clarity, this is on a OnePlus One running Cyanogenmod 13 (Android 6.0.1).

Also, I believe the common expression is "Free as in speech, not free as in beer".
 
Upvote 0
So why doesn't it?

I have no idea. None whatsoever.

h5JKSA8.jpg
 
Upvote 0
Edit: Well, I see a problem. The block works correctly on the default browser, but accessing the internet through any other browser (Chrome, DuckDuckGo) doesn't block it. Is that supposed to be the case?
Just to confirm, you did clear the app caches for those other browsers too, yes? Clearing the app cache for just one won't have any affect on the others. Again, local DNS data is retained in the app cache. Eventually that local DNS info will expire on its own but wiping the cache is a non-destructive way to just speed up the process.
And yes, an altered host file should apply universally for browsers on your device.
 
Upvote 0
Just to confirm, you did clear the app caches for those other browsers too, yes? Clearing the app cache for just one won't have any affect on the others. Again, local DNS data is retained in the app cache. Eventually that local DNS info will expire on its own but wiping the cache is a non-destructive way to just speed up the process.
And yes, an altered host file should apply universally for browsers on your device.
Oh yeah, good point. The default browser didn't need to have its cache cleared but the DuckDuckGo browser did stop loading the website once I cleared the cache.

I eventually managed to do the same for Chrome, I just had to clear a bunch of different caches, including the user web cache and site settings. Bit of a fuss, but now it seems to be properly inaccessible. Thanks for the help!
 
Upvote 0
Ah, thanks, I could never figure out when those URL prefixes are required or not.

Now, I changed the entry in my hosts file to just imgur.com, cleared the browser cache, rebooted... no change. Maybe I should give Ad-Away a shot.

Edit: Well, I see a problem. The block works correctly on the default browser, but accessing the internet through any other browser (Chrome, DuckDuckGo) doesn't block it. Is that supposed to be the case?
I have used adaway for years, works great, never get any kind of adds while on the net or playing games.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones