You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Michal Charemza 7f92b6d3bb
(docs) Remove out of date comment
5 years ago
.circleci (build) Run tests in Circle CI 5 years ago
.coveragerc (build) Code coverage only for files in repo 5 years ago
.gitignore Initial commit 5 years ago
.pre-commit-config.yaml (feat) Initial behaviour 5 years ago
LICENSE Initial commit 5 years ago
README.md (docs) Clarity 5 years ago
dnsrewriteproxy.py (docs) Remove out of date comment 5 years ago
setup.py (feat) Initial behaviour 5 years ago
test.py (tests) More tests pushing limits 5 years ago

README.md

dns-rewrite-proxy CircleCI Test Coverage

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.

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.