A DNS proxy server that conditionally rewrites and filters A record requests
Project description
dns-rewrite-proxy
A DNS proxy server that conditionally rewrites and filters A record requests. Written in Python, all code is in a single module, and there is a single dependency, aiodnsresolver.
CNAMEs are followed and resolved by the proxy to IP addresses, and never returned to the client.
Usage
By default the proxy will listen on port 53, and proxy requests to the servers in /etc/resolve.conf
. However, by default all requests are blocked without explicit rules, so to proxy requests you must configure at least one rewrite rule.
from dnsrewriteproxy import DnsProxy
# Proxy all incoming A record requests without any rewriting
start = DnsProxy(rules=((r'(^.*$)', r'\1'),))
# Proxy is running, accepting UDP requests on port 53
stop = await start()
# Stopped
await stop()
The rules
parameter must be an iterable [e.g. a list or a tuple] of tuples, where each tuple is regex pattern/replacement pair, passed to re.subn under the hood. On each incoming DNS request from downstream for a domain
- this list is iterated over;
- the first rule that matches the incoming domain name is used to rewrite the domain, the upstream DNS server is queries for A records, and these records, or error code, is returned downstream;
- and if no rule matches a REFUSED response is returned downstream.
The response of REFUSED is deliberate for clients to be able to help differentiate between a configuration issue on the proxy, the proxy not working or not being contactable, and a domain actually not existing.
So to rewrite all queries for www.source.com
to www.target.com
, and to refuse to proxy any others, you can use the following configuration.
start = DnsProxy(rules=(
(r'^www\.source\.com$', r'www.target.com'),
))
Alternatively, do the same rewriting, but to allow all other requests, you can use the following.
start = DnsProxy(rules=(
(r'^www\.source\.com$', r'www.target.com'),
(r'(^.*$)', r'\1'),
))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dnsrewriteproxy-0.0.1.tar.gz
.
File metadata
- Download URL: dnsrewriteproxy-0.0.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa821650963a59590b9f90bf1535e340824f37a6b8a1f4afac872e459ca975ca |
|
MD5 | eee5d1b8b55de7ff3cb687f8d6607af4 |
|
BLAKE2b-256 | 1cc08eb4edde87ff8d4d1e9338c989cd868dd849cb52690ef8f0c4e411e682cc |
File details
Details for the file dnsrewriteproxy-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: dnsrewriteproxy-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e3a31671bcb09baba6f7d572f49d30441791750cd2a0d66b4ca41711d49ce61 |
|
MD5 | f24e0bab3376e20d7d2af5c482659d57 |
|
BLAKE2b-256 | 615cb203d7c76efdb6b46fc1705529c07cfaa08531fd461362c629f5165dcd9b |