Coder Social home page Coder Social logo

dns_host's Introduction

DNS Host

DNS Host is a NodeJS framework which allows for a DNS server to be created and managed in code rather than as zone files.

Zone files can still be used however by reading and parsing files. Utility functions to handle this (will be provided but currently NYI)

Basic Server

To create a basic DNS Server which is authoritative for a domain,

const server: DNSServer = new DNSServer();

const queekus_com_name: DomainName = new DomainName("queekus.com.");

const com_queekus_records: DNSProtocolResourceRecord<DNSProtocolResourceRecordAcceptedTypes>[] = [
    DNSProtocolResourceRecord.of("@", Type.A, Class.IN, 60 * 5, new IPv4("192.30.252.153")),
    DNSProtocolResourceRecord.of("@", Type.A, Class.IN, 60 * 5, new IPv4("192.30.252.154"))
];

/**
 * Server is automatically authoritative for the root zone,
 * Add our authoritative handler as a sub zone of root
 */
server.subZone(
    new ZoneHandler(queekus_com_name)
        .use(simpleLoggingResponder)
        .authoritative(simpleResponder([
            {
                authoritativeName: "",
                recordClass: Class.IN,
                recordType: Type.A,
                records: com_queekus_records
            },
            {
                authoritativeName: "www",
                recordClass: Class.IN,
                recordType: Type.A,
                records: [
                    DNSProtocolResourceRecord.of(queekus_com_name.asSubdomain("www"), Type.CNAME, Class.IN, 60 * 5, queekus_com_name),
                    ...com_queekus_records
                ]
            }
        ])));

server.listen(() => console.log("DNS Server listening on port 53"));

Basic Server with Custom Handler

const server: DNSServer = new DNSServer();

const queekus_com_name: DomainName = new DomainName("queekus.com.");

/**
 * Server is automatically authoritative for the root zone,
 * Add our authoritative handler as a sub zone of root
 */
server
    .subZone(new ZoneHandler(queekus_com_name)
        .authoritative(ZoneHandler.createResponder((zone: string, request: DNSZoneRequest, response: DNSZoneResponse): void =>
        {
            if (request.zoneQuestion.qClass.value !== Class.IN) // Only handle Internet Requests for now
                return;

            switch (request.zoneQuestion.qType.value)
            {
                case Type.A:
                {
                    switch (request.getAuthoritativeQueryForZone(zone))
                    {
                        // Example CNAME
                        case "www":
                            response.addAnswers(DNSProtocolResourceRecord.of(queekus_com_name.asSubdomain("www"), Type.CNAME, Class.IN, 60 * 5, queekus_com_name));
                        /**
                         * In this example we fallthrough into the
                         * default return values so that we return
                         * the CNAME with data relevant to its return value
                         */
                        case "":
                            response.addAnswers(DNSProtocolResourceRecord.of(queekus_com_name, Type.A, Class.IN, 60 * 5, new IPv4("192.168.0.10")));
                            break;
                    }
                }
            }
        })));

server.listen(() => console.log("DNS Server listening on port 53"));

dns_host's People

Contributors

queekusme avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

dns_host's Issues

Implement Unit Tests for Protocol Classes

The following classes would be good to be added to Unit Tests

  • DNSProtocolHeader
  • DNSProtocolQuestion
  • DNSProtocolResourceRecord
  • DNSProtocol (shoukd encompass the above classes as well)

as well as the following methods

  • DNSProtocol.createFromRequest
  • DNSProtocolResourceRecord.of

Add in-built zone handlers to read from zone files

Other dns servers operate using zone files on the filesystem to determine the zone data.

Utility functions should be added to allow for a quick setup to load one fo these files in and use it as the aswerer for zone questions.

Regarding Zone transfer, these util functions should handle updating the files on the hard disk based on zone transfer information

Implement support for master/slave zones

Currently the server is uathoritative for its own data. It would be beneficial to support slave servers for if the master server is not online.

This could be handled on a server-wide basis or on a zone by zone basis.

Implement more Cache variants

The cache system is very rudementry with a single class running an in-memory cache.

It would be of benefit to have some built in cache handlers such as:

  • Redis cache
  • MongoDB cache
  • Filesystem cache (write to file on filesystem)
    handlers so that other, more persistant, caches can be used

Implement Recursion

Currently the DNS Server can handle authoritative requests however if the server cannot handle a request, it should be configurable with upstream servers to provide answers for the question.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.