Metadata-Version: 2.1
Name: dnserver
Version: 0.1.0
Summary: Simple DNS server written in python for use in development and testing.
Project-URL: Homepage, https://github.com/samuelcolvin/dnserver
Project-URL: Documentation, https://github.com/samuelcolvin/dnserver
Project-URL: Source, https://github.com/samuelcolvin/dnserver
Project-URL: Changelog, https://github.com/samuelcolvin/dnserver/releases
Author-email: Samuel Colvin <s@muelcolvin.com>
License: The MIT License (MIT)
        
        Copyright (c) 2017, 2022 Samuel Colvin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Unix
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: Name Service (DNS)
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Testing :: Mocking
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.7
Requires-Dist: dnslib>=0.9.20
Requires-Dist: tomli; python_version < '3.11'
Requires-Dist: typing-extensions; python_version < '3.8'
Description-Content-Type: text/markdown

# dnserver

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`](https://1.1.1.1/).

You can set up records you want to serve with a custom `zones.toml` file,
see [example_zones.toml](example_zones.toml) for the format.

To use with docker:

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

(See [dnserver on hub.docker.com](https://hub.docker.com/r/samuelcolvin/dnserver/))

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.)

Or see [docker-compose.yml](docker-compose.yml) for example of using dnserver with docker compose.
It demonstrates using dnserver as the DNS server for another container which then tries to make DNS queries
for numerous domains.

To run without docker (assuming you have `dnslib==0.9.7` and python 3.6 installed):

    PORT=5053 ZONE_FILE='./example_zones.txt' ./dnserver.py

You can then test (either of the above) with

```shell
~ ➤  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](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.
