1. NaviServer
  2. NaviServer Project
  3. nsdns


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 www.cisco.com
          wildcard names are supported:
             ns_dns add *.domain.com A
             all requests for host.domain.com 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 www.mydomain.com A
          ns_dns add ns.mydomain.com A
          ns_dns add ftp.mydomain.com CNAME www.mydomain.com
          ns_dns add mydomain.com NS ns.mydomain.com
          ns_dns add mydomain.com MX 1 ns.mydomain.com
          ns_dns add NAPTR 1 100 u E2U+sip {!^.*$!sip:123456@sipproxy.net:5060!}

     ns_dns del name type ?value?

        delete DNS record(s) from memory cache

          ns_dns del www.mydomain.com A

     ns_dns list

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

         {ns.mydomain.com A 86400}
         {www.mydomain.com A 86400}
         {mydomain.com MX ns.mydomain.com 1 86400}
         {mydomain.com NS ns.mydomain.com 86400}
         {ftp.mydomain.com CNAME www.mydomain.com 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 openacs.org

   ; <<>> DiG 9.10.3-P4 <<>> @localhost -p 5354 -t any openacs.org
   ; (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
   ;openacs.org.			IN	ANY

   openacs.org.		6422	IN	NS	ns1.wu-wien.ac.at.
   openacs.org.		6422	IN	NS	ns2.wu-wien.ac.at.
   openacs.org.		6422	IN	A
   openacs.org.		6422	IN	AAAA	2001:628:404:74::31
   openacs.org.		6422	IN	MX	10 smtp.openacs.org.
   openacs.org.		6422	IN	SOA	ns0.wu-wien.ac.at. postmaster.wu-wien.ac.at. 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  vlad@crystalballinc.com
     Gustaf Neumann neumann@wu-wien.ac.at