1. Download our Official Android App: Forums for Android!

Support Blocking websites via the hosts file

Discussion in 'Android Help' started by LTK, Dec 10, 2017.

  1. LTK

    LTK Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Dec 10, 2017

    Dec 10, 2017
    5
    0
    5
    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

     

    Advertisement

  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator
    Rank:
     #2
    Points:
    4,488
    Posts:
    38,316
    Joined:
    Jun 23, 2010

    Jun 23, 2010
    38,316
    47,561
    4,488
    Male
    Douglas, MA
    Did you reboot? The DNS entry could be cached.
     
  3. LTK

    LTK Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Dec 10, 2017

    Dec 10, 2017
    5
    0
    5
    Yes, I forgot to mention that. I did a soft reboot after overwriting the file. I'll see whether a hard reboot does it.

    Nope, same story in both cases.
     
    #3 LTK, Dec 10, 2017
    Last edited: Dec 10, 2017
  4. svim

    svim Android Expert
    Rank:
     #30
    Points:
    708
    Posts:
    4,879
    Joined:
    Dec 19, 2013

    Dec 19, 2013
    4,879
    4,130
    708
    Illinois
    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.
     
  5. TRS-80

    TRS-80 Android Enthusiast
    Rank:
     #152
    Points:
    83
    Posts:
    409
    Joined:
    Dec 29, 2010

    AdAway FTW!

    I don't think it's available in Play Store any more, but you can still find it in F-Droid.
     
    BustaLime and Unforgiven like this.
  6. LTK

    LTK Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Dec 10, 2017

    Dec 10, 2017
    5
    0
    5
    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?
     
    #6 LTK, Dec 10, 2017
    Last edited: Dec 10, 2017
  7. TRS-80

    TRS-80 Android Enthusiast
    Rank:
     #152
    Points:
    83
    Posts:
    409
    Joined:
    Dec 29, 2010

    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
     
  8. LTK

    LTK Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Dec 10, 2017

    Dec 10, 2017
    5
    0
    5
    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".
     
  9. mikedt

    mikedt 你好
    Rank:
     #6
    Points:
    3,238
    Posts:
    27,475
    Joined:
    Sep 22, 2010

    Sep 22, 2010
    27,475
    16,962
    3,238
    Teachaaa
    Jinan, China
    Gratis versus libre. :thumbsupdroid:
     
  10. TRS-80

    TRS-80 Android Enthusiast
    Rank:
     #152
    Points:
    83
    Posts:
    409
    Joined:
    Dec 29, 2010

    I have no idea. None whatsoever.

    [​IMG]
     
  11. svim

    svim Android Expert
    Rank:
     #30
    Points:
    708
    Posts:
    4,879
    Joined:
    Dec 19, 2013

    Dec 19, 2013
    4,879
    4,130
    708
    Illinois
    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.
     
  12. LTK

    LTK Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Dec 10, 2017

    Dec 10, 2017
    5
    0
    5
    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!
     
  13. BustaLime

    BustaLime Member
    Rank:
    None
    Points:
    38
    Posts:
    62
    Joined:
    Aug 28, 2015

    Aug 28, 2015
    62
    24
    38
    Male
    I have used adaway for years, works great, never get any kind of adds while on the net or playing games.
     

Share This Page

Loading...