[Magisk][Module][Deprecated] Unified Hosts Adblocker

Search This thread

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
This mod has since been discontinued in favor of Adaway. Read on for information on how to use Unified Hosts with Adaway

What are Unified Host Files?
Unified host files combine many reputable sources into a single hosts file (with duplicates removed). Some examples include adaway, mvps, yoyo.org, and malware domain list (see Steven Black's page here for a complete list).

Adaway Installation for Magisk:
Adaway version 4.x now works properly with magisk systemless hosts. To enable it, just install the latest version from here (the main xda thread for it hasn't been updated for it yet). Then go to Preferences -> Enable systemless mode. This automatically enables the Systemless hosts option in magisk manager so no need to bother with that. Then use the app as normal.

How to Add Unified Hosts to Adaway:
In the adaway app, go to Preferences -> Redirection IP (NOT Allow Redirects). Change the value to 0.0.0.0. Read the readme on Steven Black's GitHub linked above for why.

Then go to Hosts Sources. Then add the url of the unified hosts you want (ONLY CHOOSE 1):
You can then uncheck the host sources already added by default to adaway since they're included in unified hosts sources already

**Note that the 'Social' filter does exactly what you think: blocks social networks. So if you use any kind of social networking, DO NOT CHOOSE THIS ANY SOURCE WITH THIS IN IT**

Using a APN that uses a proxy server or a subsidiary provider and unable to get adblocking working? See here for a fix


Original Mod Information:

Description
Blocks ads by using Steven Black's Unified Hosts
Comes with a small utility based off of LarappsOfDongle's RP modular host module that allows you to choose which kind of host file you want (adware/malware, fakenews, gambling, porn, social, or any combination)

Installation
Go to Settings in Magisk Manager and enable 'Systemless Hosts'
Flash module
Open terminal and type:
Code:
su
hosts
Then follow the prompts to install the host file of your choice.
OR
- Open terminal and type:
Code:
su -c hosts arg1 arg2 arg3
- The script will apply your arguments all at once and close. Useful for automation purposes
- For example: `su -c hosts m wr b`
- Script will apply the master filter, then your regex whitelist, then your blacklist

Updating Hosts:
Just run the hosts file again in terminal and it'll overwrite the old one
Note: The script will now notify you to say if you need to update or not at the top of it

Disabling Host Mod:
Just toggle the enable systemless hosts option in magisk manager

Whitelist Instructions:
  • Create an empty file on sdcard card called "whitelist"
  • Either add exact lines you want remove to it -> Run hosts script and choose whitelist option
    For example:
    Code:
    0.0.0.0 facebook.com
    Will unblock facebook.com
  • Or add regex for lines you want removed -> Run hosts script and choose whitelist regex option
    For example:
    Code:
    .*facebook.*
    Will unblock all domains with "facebook" in them

Blacklist Instructions:
  • Create an empty file on sdcard card called "blacklist"
  • Add exact lines you want to remove it (do not include the 0.0.0.0 -> so for example: "facebook.com")
  • Run hosts script and choose blacklist option
    For example:
    Code:
    google-analytics.com
    Will block the google-analytics.com domain (it will add the entry "0.0.0.0 google-analytics.com" to the hosts file - note the lack of the 0's here. The script takes care of it automatically for the blacklist feature)

To Remove Whitelist:
Just run hosts script and reinstall host file of choice

Latest Magisk Version Compatibility:
15.x

Source

Can't Boot?
Try rebooting into the bootloader, then boot into system. Thanks @rignfool for the tip

Bonus!
I made a quick automate flow to update the hosts file. Just import it, add a shortcut to your home screen, and you can update it in one click :)
Just change the 2nd block to whatever options you want

@Didgeridoohan made a tasker profile here for any who use tasker: https://forum.xda-developers.com/showpost.php?p=73369050&postcount=451

Download
 

Attachments

  • Unified-Hosts-Adblock-v3.7.zip
    1 MB · Views: 14,279
  • UnifiedHostsAdblock_Update_Automate_Flow.zip
    234 bytes · Views: 6,525
Last edited:

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
How does this differ from AdAway?
The unified hosts file combine many sources including AdAway, mvps, malware domains, and more. Check out steve black's page in the op for a full list.

Also, for some reason, adaway wouldn't detect the systemless hosts file for me so i had to set a custom path and symlink it
 

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
Updated module for latest magisk manager update (required changes to the readme). Doesn't change the functionality of the module at all so if you're in 1.1, there's no need to upgrade since these readme changes will only be reflected in magisk manager once this module is approved into the repo.
 
  • Like
Reactions: itssomraj

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
Damnit... Wrong thread...

OK...

Syntax...

su -c hosts ______

Please fill in the blank...

Code:
su
Give root permissions
Code:
hosts
Program will prompt for input. For example, if you want malware/adware (master) + fakenews + gambling, you're input would be:
Code:
fg

The reason for not including the master (adware/malware) in the arguments is that it's already included by default in each host file. So the fakenews host file is actually master + fakenews. It's how steven set it up so I have no control over it (and who wouldn't want the malware block anyways)
 
Last edited:

rignfool

Senior Member
Dec 8, 2010
5,010
2,730
The Poconos
Give root permissions

Program will prompt for input. For example, if you want malware/adware (master) + fakenews + gambling, you're input would be:
I'm looking to execute as a one line shell command with tasker...

So I'm using 'su -c' cuz SU detection in tasker with magisksu is broken...

Then hosts... But I want to run with an argument so I don't need to interact with the script... Just have it update the hosts file...
 

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
I'm looking to execute as a one line shell command with tasker...

So I'm using 'su -c' cuz SU detection in tasker with magisksu is broken...

Then hosts... But I want to run with an argument so I don't need to interact with the script... Just have it update the hosts file...

I've never used tasker (use automate instead). Perhaps
su -c; hosts; sleep 1; fgps; sleep 2; q

Not sure if the sleep command works for tasker (linux thing) but if there's a way to have it wait a half a second or so before inputting the next command, and then waiting 2 seconds or so to quit after the hosts is applied (not sure on the time, just guessing).


Edit, just saw you didn't want to deal with the script. The 'hosts' command is the script. If you look my source for the hosts script, it lists each url for the file and what it does. So all of the terminal code for fgps would be:
Code:
su -c
cd /magisk/.core
wget -O hosts --no-check-certificate https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts

This will replace the systemless hosts file with the one you want. Note you will at least need the wget portion of the module (system/bin) since it's not included in most roms
 
Last edited:

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
Using ze551ml, after rebooting, module disappeared. I can't find hosts command anywhere.
Does magisk manager say root is enabled? There's been an ongoing issue where root will disappear and so all modules will disappear as well. This isn't a module issue but a magisk issue
 
Last edited:

Yom

Senior Member
May 4, 2006
1,336
161
Cancun
Automating hosts update?

Hi Zack!

Love your module, thank you!

Is there a way I can update with FG running a shell command from Tasker?

When I try

Code:
echo fg|hosts

it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.

Could you please make it so hosts accepts arguments from the command line, instead of a menu?

Thank you!
 

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
Hi Zack!

Love your module, thank you!

Is there a way I can update with FG running a shell command from Tasker?

When I try

Code:
echo fg|hosts

it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.

Could you please make it so hosts accepts arguments from the command line, instead of a menu?

Thank you!

The menu is part of the command line. I don't have tasker however, maybe this post will help: https://forum.xda-developers.com/showpost.php?p=71117156&postcount=9
You can circumvent running the script completely and just wget your host of choice. In that post, I have a link to the source for the hosts file with all of the urls. For fg for example, it would be: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts
 
  • Like
Reactions: Yom

Didgeridoohan

Forum Moderator / Developer Relations
Staff member
May 31, 2012
11,481
11,781
Gothenburg
Google Nexus 4
Nexus 6
Hi Zack!

Love your module, thank you!

Is there a way I can update with FG running a shell command from Tasker?

When I try

Code:
echo fg|hosts

it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.

Could you please make it so hosts accepts arguments from the command line, instead of a menu?

Thank you!

As @Zackptg5 says, to automate with Tasker it's easier to just circumvent the script altogether...

I have a Tasker profile set up to fetch the hosts file directly from Steven Blacks GitHub and save it to /magisk/.core/hosts. I couldn't get wget to work properly with Taskers Run Shell, so I used the HTTP Get instead to fetch it to /sdcard and then Run Shell to move it to /magisk/.core/hosts (and to remove it from /sdcard afterwards).
 

Zackptg5

Recognized Developer
Sep 18, 2014
4,086
6,679
zackptg5.com
Is there a possibility of whitelists?

In theory, you shouldn't need a white list with these hosts files. I chose them because they are gone over with a fine tooth comb so you shouldn't have any issues. However, when I get on spring break, I could attempt to add a whitelist option to the script. I was thinking the easiest way to do this would be to read a text file (would be a blank one in the module folder by default but is editable the uses to add whatever) and remove any matches from the host file. Have any better ideas to implement this? I have no experience with GUI development and that would add unnecessary overhead anyways
 

Nomelas

Senior Member
Aug 21, 2014
376
136
Does this module work currently? I disabled adaway and enabled this but it's not blocking ads that adaway blocks.

Testcase: root check by Jrummy

Adaway blocks the in app ads. This module does not :(


EDIT: apparently I can't read... Lol. Followed the Op and now it works great!
 
Last edited:

Cheeky_Fink

Senior Member
Aug 24, 2011
195
60
29
Colorado Springs
Hi Zack!

Love your module, thank you!

Is there a way I can update with FG running a shell command from Tasker?

When I try

Code:
echo fg|hosts

it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.

Could you please make it so hosts accepts arguments from the command line, instead of a menu?

Thank you!

I have a profile set up to do this every 12 hours. If you still need it, I updated it to use your preferred settings and exported it. All you need to do is import it in Tasker (long-press Profiles header) and turn it on.
 

Attachments

  • Update_Hosts.prf.xml
    1.1 KB · Views: 173
Last edited:
  • Like
Reactions: anthony.wang

Top Liked Posts

Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone