This is what Pi-hole basically does.
I run a PiHole in the cloud so I can PiHole my phone without exposing my home network at all.
EDIT: On my phone, I do use Firefox with uBlock Origin, but the PiHole blocks ads that aren't in the browser, or use an app's browser view.
The reports an dynamic modifications to rule sets are a big advantage of pi hole. Sure, you can do it with dnsmasq conf files and logs, but the web UI has a lot of niceties.
https://hub.docker.com/r/pihole/pihole/
I used synology's docker app. I had to enter the port numbers into their web GUI manually.