Skip to main content

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 Python

from dnserver import DNSServer

server = DNSServer.from_toml('example_zones.toml', port=5053)
server.start()
assert server.is_running

# now you can do some requests with your favorite dns library

server.stop()

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.

Release files for dnserver 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnserver 0.4.0
File Size Uploaded
dnserver-0.4.0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dnserver 0.4.0
File Interpreter ABI Platform
dnserver-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / dnserver-0.4.0.tar.gz

Download URL dnserver-0.4.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bef5b7385c074be7b521628ead203bdd4511e335e8556953ccc59b41cbe10dca
BLAKE2b-256 checksum
How to use checksums
d2bd998ed6dd94a1717c1ab2acdad385148f776246ea884ec16463d1011aa5cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Release files / dnserver-0.4.0-py3-none-any.whl

Download URL dnserver-0.4.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbed0833bb9e510bbbecb8a7d7ec6c51a807146f2e7d4448afac4cee5a0ca9eb
BLAKE2b-256 checksum
How to use checksums
840ffa73f02422ed83c5774ddf1dc6bb70edd444b8d66b3063550450cf5b5c7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page