DNS Module for NaviServer 4.x
Release 0.8.0

This is NaviServer module that implements DNS server/proxy.
It can serve from it own database or perform forwarding to
another DNS server and cache results. The server doesn't
support any database directly, instead it provides commands similar
route add|del to add/remove DNS records to memory cache.

Version 0.8.0 adds compatibility with IPv6


Compiling and Installing

To compile this driver, just type make

dns.tcl file may go to /usr/local/ns/modules/tcl directory
to be loaded on startup. It loads /etc/hosts records into DNS cache as A
records and will act as primary DNS server for these hosts.


Here is an nsd.tcl excerpt for configuring the DNS module:

ns_section      ns/server/${server}/module/nsdns
ns_param	port		5354
ns_param	address		localhost
ns_param	ttl		86400
ns_param	negativettl	3600
ns_param	cachettl	0
ns_param	readtimeout	30
ns_param	writetimeout	30
ns_param	proxytimeout	3
ns_param	proxyretries	2
ns_param	proxyhost
ns_param	proxyport	53
ns_param	defaulthost	""
ns_param        debug           0

- port - local UDP/TCP ports to listen
- address - local addres to bind
- ttl - default ttl for the records
- cachettl - TTL to be used for cached records
- nagativettl - TTL to be used for negative responses
- readtimeout - timeout for reading
- proxyhost - remote DNS server where to proxy requests
- proxyport - port of the remote proxy server
- proxyretries - how many times to re-send UDP request to proxy server
- proxytimeout - how long to wait for proxy reply before timeout
- debug - debug level, higher level more information is written in the log
- defaulthost - if no proxyhost set and query host not found reply with default host


    ns_dns usage:

      ns_add name type value... ?ttl?

        adds DNS record to the cache.
        name is record domain name like
          wildcard names are supported:
             ns_dns add * A
             all requests for which are
             not in local cache will be replied with
        type is one of A,NS,PTR,NS,CNAME,MX
        value depends on record type:
         A - IP address
         MX - preference cname
         NS,PTR,CNAME - domain name
         NAPTR - naming authority (ENUM)

          ns_dns add A
          ns_dns add A
          ns_dns add CNAME
          ns_dns add NS
          ns_dns add MX 1
          ns_dns add NAPTR 1 100 u E2U+sip {!^.*$!!}

     ns_dns del name type ?value?

        delete DNS record(s) from memory cache

          ns_dns del A

     ns_dns list

        returns list with all DNS records from the cache including
        cached from remote proxy

         { A 86400}
         { A 86400}
         { MX 1 86400}
         { NS 86400}
         { CNAME 86400}

     ns_dns flush

        flushes all DNS records from memory cache

     ns_dns queue

        returns list with pending requests waiting reply from
        the remote proxy


Below is output from dig utility about the configuration
provided in the above example.

   % dig @localhost  -p 5354 -t any

   ; <<>> DiG 9.10.3-P4 <<>> @localhost -p 5354 -t any
   ; (3 servers found)
   ;; global options: +cmd
   ;; Got answer:
   ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34376
   ;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

   ; EDNS: version: 0, flags:; udp: 512
   ;			IN	ANY

   ;; ANSWER SECTION:		6422	IN	NS		6422	IN	NS		6422	IN	A		6422	IN	AAAA	2001:628:404:74::31		6422	IN	MX	10		6422	IN	SOA 2016041101 3600 1800 604800 3600

   ;; Query time: 0 msec
   ;; SERVER: ::1#5354(::1)
   ;; WHEN: Mon Apr 25 21:43:31 CEST 2016
   ;; MSG SIZE  rcvd: 205


     Vlad Seryakov
     Gustaf Neumann