How to block URL's system-wide on Android (including wildcard domains)

Definition - Wildcard Domain

A wildcard domain in the context of AdGuardHome refers to a pattern that matches all subdomains of a given domain. It allows you to apply a rule (such as blocking or allowing) to an entire group of subdomains using a single entry. This is especially useful when a service dynamically assigns subdomains based on factors like device or location, or ever changing subdomains, making it impractical or impossible to list each one individually.

Not an alternative to hosts file.

Hosts file can only do exact domains. AdGuardHome does that and more.

Install AdGuardHomeForRoot Magisk module:

AdGuardHomeForRoot - Github

AdGuardHomeForRoot - Google Drive

Theoretically, you can backup the preconfigured module for flashing on other devices. Haven’t tried it yet.

once installed, head to http://localhost:3000

User - root
Password - root

How to change AdGuardHome password:

1. Install termux (you can uninstall after, no dependencies on termux)

Enter these commands (minus the “<” and “>”)

pkg install apache2
htpasswd -B -n -b <username> <new_password>

2. Copy the hash output

3. Open /data/adb/agh/bin/AdGuardHome.yaml for editing.

4. Paste the hash in the current ones place. Reboot.

Reboot. The password is now changed.

Syntax - Entering URL’s

Your blocklist and allowlist will either be written manually in:

Filters → Custom Filtering Rules,

or,

You can push a list to GitHub to update remotely (good for custom rom developers) and enter the list URLS in:

Filters → DNS Blocklists/DNS Allowlists.

example blocklist

example allowlist

Visit adguard-docs to see examples of the configuration you need.

Sample:

# Google Maps - block images/StreetView/ImmersiveView

||cbks4.googleapis.com^
||cbks3.googleapis.com^
||cbks2.googleapis.com^
||cbks1.googleapis.com^
||cbks0.googleapis.com^
||cbk0.googleapis.com^
||gz0.googleusercontent.com^
||karto.static.usercontent.goog^
||lh3.googleusercontent.com^
||streetviewpixels-pa.googleapis.com^
||bc.googleusercontent.com^
||arvr.google.com^

Save

Clear app data after entering list, and then reboot.
This will get rid of any cached files already loaded

pcapdroid - traffic capture

Thanks @KosherFlipper for posting this, it’s very helpful.

3 Likes