[Android Apps and Games] zgfg:
Yes, I can fix it (force Chrome to use hosts file and hence to block ads) but only by manually changing the DNS server through Static config for that particular WLAN connection

For me, no use of resolve.conf, DNS props and dnsmasq to enforce a DNS server of my choice for ALL WLAN (and maybe Mobile Data) connections

And no use of nsswitch.conf to enforce that local hosts file would ALWAYS have precedence over the public DNS server -

when my Chrome detects that Google or Cloudflare DNS servers are used, Chrome starts ignoring the local hosts file with the sites blocked by AdAway and ads start showing on the Web pages)

---

Putting my results all together:

I use AdAway root mode and Systemless hosts in Magisk.

AdAway pathches /data/adb/modules/hosts/etc/hosts file, and Magisk (upon reboot) mounts to /etc/hosts file.

Therefore, about 310K ads sites are blocked (redirected to localhost) and they cannot push ads

I don't use private DNS server (like AdGuard) or firewall (like AFWall) to additionaly help to block ads

1) Problem: WLAN with Google/Cloudflare DNS - ignoring hosts file

- When DHCP on the WLAN pushes me Google DNS server 8.8.8.8, then my Chrome starts ignoring the local /etc/hosts file.

Therefore, ads are no more blocked and they show elsewhere in Chrome

Interestingly, ads are not showing in the other apps

Solution:

- I open native Settings, WiFi, Details for the connected WiFi and switch configuration from DHCP to Static.

It offers me everything as it was pushed by DHCP, I just replace DNS1 server from Google 8.8.8.8 to eg. Quad9 DNS 9.9.9.9 and Save

I force-close and reopen Chrome and it starts using the local hosts file - hence ads are no more showing

Good thing is that my phone remembers and next time when I come and connect to the same WLAN, it uses that Static config with the DNS1 server (9.9.9.9) as I previously defined, Chrome then obeys the hosts file and ads are not showing

I can also reproduce the other way around:

- On the WLAN (eg. my home) where DNS configures some other DNS server (and therefore my Chrome obeys the hosts file and blocks ads),

I also go to Settings for the connected WiFi, switch from DHCP to Static and force Google 8.8.8.8 for DNS1 server

Then Chrome ignores the hosts file and shows the ads -

proving that my problem with Chrome (ignoring hosts file and showing ads) is triggered by Chrome detecting that a particular DNS server (Google, Cloudflare) is being used

That way I have played with Google DNS servers 8.8.8.8 and 8.8.4.4, and Cloudflare 1.1.1.1 and 1.0.0.1

All those four DNS servers cause my Chrome to ignore hosts file and to show ads

However, when I configure DNS1 server to any of the following:

Quad9 DNS

9.9.9.9

149.112.112.112

DNSWatch:

84.200.69.80

84.200.70.40

OpenDNS:

208.67.222.123

208.67.220.123

OpenNIC:

185.121.177.177

169.239.202.202

then Chrome processes the hosts file and does not show ads

---

2) No problem: Mobile Data

I have SIM cards from two major Mobile providers in my country and I tested on 3G, 4G and 5G for both providers.

DHCP always configures their own DNS servers, Chrome does not ignore local hosts file and ads are not showing, hence I didn't need to play further with DNS settings for the Mobile Data

---

3) No use: nsswitch.conf and resolv.conf

As described earlier, I have tested with /etc/nsswitch.conf and /etc/resolv.conf files, but they didn't help to change anything.

Btw, I originally did not find any of those two files on my phone

Since I have A12, my System is read only, hence I need to use systemless approach to mount these files.

I (mis)use Systemless hosts module and put those files to /data/adb/modules/hosts/system/hosts and after reboot, Magisk mounts them to /etc

However, it seems that Android does not use those conf files (Linux does)

- Eg, I have in nsswitch.conf:

hosts: files dns

that should enforce precedence for local hosts file over the DNS server

Still, it's ignored as in the case (1) above (Chrome ignores hosts file when it detects that eg Google DNS server is used)

- Similarly, resolv.conf defines DNS servers to use, like Quad9 DNS:

nameserver 9.9.9.9

nameserver 149.112.112.112

but nevertheless, it's ignored in the case (1) above

(and DHCP or Static config define the actual DNS servers that will be used for the particular WLAN connection)

---

4) No use: DNS props

I have also tested by using /data/adb/modules/hosts/system.prop with the definition of various props for DNS servers (none of those props was originally found on my phone):

Spoiler content hidden.

that Magisk then mounts upon reboot, but they also did not enforce the use of the given DNS1 and DNS2 servers

---

5) No use: dnsmasq -d

I can run dnsmasq, it starts and reads hosts and resolv.conf files.

Then, when I use nslookup (also from Terminal emulator) it will use that DNS server (eg 9.9.9.9) from resolv.conf file,

and if I ask for the hostname that is blocked in the hosts file, nslookup will correctly resolves it to the localhost 127.0.0.1

On the other side, Chrome then still ignores the hosts file and shows ads if Google or Cloudflare DNS servers are used for the active (WLAN) connection