With the python3 module dnslib a quick and dirty overriding DNS proxy can be realized. Such a proxy is useful to redirect traffic targeted to one domain to another - for example to an mitmproxy instance in reverse proxy mode. To setup the proxy install dnslib, preferably in a virtualenv.
python3 -p venv dns_venv
source dns_venv/bin/activate
pip3 install dnslib
To start overriding a domain, start dnslib’s intercept module and specify a record to override:
sudo dns_venv/bin/python3 -m dnslib.intercept -i "*.example.com 300 IN A 127.0.0.1"
The code above redirects all traffic to a sub-domain of example.com to localhost. Multiple overrides can be specified by using multiple -i input switches.
Happy hacking.