Skip to main content

DNS Name Server Framework

Project description

NServer: a high-level Python DNS Name Server Framework.

PyPi Python Versions License

NServer is a Python (3.6+) framework for building customised DNS name servers with a focuses on ease of use over completeness. It implements high level APIs for interacting with DNS queries whilst making very few assumptions about how responses are generated.

It is not intended to act like traditional DNS servers such as BIND or CoreDNS and should not be considered a general DNS resolver.

NServer has been built upon dnslib however uses high level abstractions that does not give access to the full DNS specification. If this is your desired behaviour I suggest using dnslib and its server API.

NServer has been inspired by easy to use high level frameworks such as Flask or Requests.

NServer is currently Alpha software and does not have complete documentation, testing, or implementation of certain features. Specific APIs may change in the future, but NServer uses semantic versioning so you can have more stable interfaces using version specifiers (e.g. nserver>=0.0.1,<1.0).


Install via pip

pip3 install nserver

Quick Start

from nserver import NameServer, Response, A, NS, TXT

ns = NameServer("example")

# Responses can have answers records, additional records and authority records.
@ns.rule("", ["NS"])
def my_name_servers(query):
    response = Response()
    for i in range(4):
        my_ns = "ns{}".format(i + 1)
        response.answers.append(NS(, my_ns))
        response.additional.append(A(my_ns, ""))
    return response

# Rules can use wildcards for both single-segment (*) or many-segment (**)
# wildcards will not match mising segments (equivilent to regex `+`)
# You can also construct simple responses by return records directly.

@ns.rule("**", ["A"])
def wildcard_example(query):
    """All subdomains are at"""
    return A(, "")

# Rules are processed in the order they are registered so if a query matches
# this rule, it will not reach the `australian_catchall` below.
# Wildcards can appear in names, but the above segment limits apply.

@ns.rule("www.*", ["A"])
def all_australian_www(query):
    return A(, "")

# Wildcard domains also allow special substitutions.
# base_name will provide the domain less any subdomains.

@ns.rule("hello.{base_domain}", ["TXT"])
def say_hello(query):
        return TXT(, "G'day mate")
    return TXT(, "Hello friend")

# Rules can apply to multiple query types.

@ns.rule("**", ["A", "AAAA", "ANY"])
def australian_catchall(query):
    return Response()  # Empty response, avoids default NXDOMAIN

# Anything that does not match will return NXDOMAIN

if __name__ == "__main__":
    ns.settings.SERVER_PORT = 9001  # It's over 9000!

Once running, interact using dig:

dig -p 9001 @localhost NS

dig -p 9001 @localhost A
dig -p 9001 @localhost A

dig -p 9001 @localhost A
dig -p 9001 @localhost A

dig -p 9001 @localhost TXT
dig -p 9001 @localhost TXT

dig -p 9001 @localhost A
dig -p 9001 @localhost AAAA
dig -p 9001 @localhost ANY

Bugs, Feature Requests etc

TLDR: Please submit an issue on github.

In the case of bug reports, please help me help you by following best practices 1 2.

In the case of feature requests, please provide background to the problem you are trying to solve so to help find a solution that makes the most sense for the library as well as your usecase. Before making a feature request consider looking at my (roughly written) design notes.


The only development dependency is bash and docker. All actions are run within docker for ease of use. See ./ help for commands. Typical commands are format, lint, test, repl, build.

I am still working through open source licencing and contributing, so not taking PRs at this point in time. Instead raise and issue and I'll try get to it as soon a feasible.


This project is licenced under the MIT Licence - see LICENCE.

This project may include other open source licenced software - see NOTICE.


A project by Nicholas Hairs -

Project details

Download files

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

Files for nserver, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size nserver-0.0.3-py3-none-any.whl (14.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size nserver-0.0.3.tar.gz (17.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page