Skip to main content

Simple DNS server written in python for use in development and testing.

Project description

dnserver

CI Coverage pypi docker versions license

Simple DNS server written in python for use in development and testing.

The DNS serves its own records, if none are found it proxies the request to an upstream DNS server eg. CloudFlare at 1.1.1.1.

You can set up records you want to serve with a custom zones.toml file, see example_zones.toml an example.

Installation from PyPI

Install with:

pip install dnserver

Usage:

dnserver --help

(or python -m dnserver --help)

For example, to serve a file called my_zones.toml file on port 5053, run:

dnserver --port 5053 my_zones.toml

Usage with Docker

To use with docker:

docker run -p 5053:53/udp -p 5053:53/tcp --rm samuelcolvin/dnserver

(See dnserver on hub.docker.com)

Or with a custom zone file:

docker run -p 5053:53/udp -v `pwd`/zones.toml:/zones/zones.toml --rm samuelcolvin/dnserver

(assuming you have your zone records at ./zones.toml, TCP isn't required to use dig, hence why it's omitted in this case.)

You can then test (either of the above) with

~   dig @localhost -p 5053 example.com MX
...
;; ANSWER SECTION:
example.com.		300	IN	MX	5 whatever.com.
example.com.		300	IN	MX	10 mx2.whatever.com.
example.com.		300	IN	MX	20 mx3.whatever.com.

;; Query time: 2 msec
;; SERVER: 127.0.0.1#5053(127.0.0.1)
;; WHEN: Sun Feb 26 18:14:52 GMT 2017
;; MSG SIZE  rcvd: 94

~   dig @localhost -p 5053 tutorcruncher.com MX
...
;; ANSWER SECTION:
tutorcruncher.com.	299	IN	MX	10 aspmx2.googlemail.com.
tutorcruncher.com.	299	IN	MX	5 alt1.aspmx.l.google.com.
tutorcruncher.com.	299	IN	MX	5 alt2.aspmx.l.google.com.
tutorcruncher.com.	299	IN	MX	1 aspmx.l.google.com.
tutorcruncher.com.	299	IN	MX	10 aspmx3.googlemail.com.

;; Query time: 39 msec
;; SERVER: 127.0.0.1#5053(127.0.0.1)
;; WHEN: Sun Feb 26 18:14:48 GMT 2017
;; MSG SIZE  rcvd: 176

You can see that the first query took 2ms and returned results from example_zones.toml, the second query took 39ms as dnserver didn't have any records for the domain so had to proxy the query to the upstream DNS server.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnserver-0.2.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

dnserver-0.2.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file dnserver-0.2.1.tar.gz.

File metadata

  • Download URL: dnserver-0.2.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for dnserver-0.2.1.tar.gz
Algorithm Hash digest
SHA256 194e07c70cf46287bc1cefb50b3894b266b845d56e4890f76b7118d061149932
MD5 60b1305595309fa6402e089bee733a9e
BLAKE2b-256 04ffcd51981e6762cf5dd55e66063d727f6811c270d428318bf02aff9a3c6d3a

See more details on using hashes here.

File details

Details for the file dnserver-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dnserver-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for dnserver-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00e3ba011bf14b0c5ea068dac8ce18baeaf4245a13d41a4f64060fdaa8445daf
MD5 26f9508852c45c917262e5add99a2e6e
BLAKE2b-256 345b6cff4ed40d1868e0f780aab1f2ee6eba1a25a261466465d8d366478ac57a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page