DNS Encoder, Decoder, and Server

0.9.8 · abandoned · verified Tue Apr 21

hbo-dnsd (also known as dnsd) is a Node.js package providing functionalities for encoding and decoding DNS messages, as well as an API to run custom authoritative DNS servers. Currently at version 0.9.8, its development appears to have ceased around 2012, judging by the provided examples and the specified Node.js engine compatibility (>= 0.8). The package differentiates itself by offering direct programmatic control over DNS message structures as JavaScript objects, allowing developers to implement highly customized DNS resolution logic. It enables the creation of dynamic DNS responses based on request parameters, unlike static DNS server configurations. Due to its age, it relies solely on CommonJS modules and is not actively maintained, making it potentially incompatible with modern Node.js versions or ESM-first projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a dynamic DNS server that responds to A and SOA queries with custom logic, including logging requests and setting dynamic TTLs.

const dnsd = require('dnsd')

const server = dnsd.createServer(handler)
server.zone('example.com', 'ns1.example.com', 'us@example.com', 'now', '2h', '30m', '2w', '10m')
      .listen(5353, '127.0.0.1')
console.log('Server running at 127.0.0.1:5353')

function handler(req, res) {
  console.log('%s:%s/%s %j', req.connection.remoteAddress, req.connection.remotePort, req.connection.type, req)

  const question = res.question[0]
    , hostname = question.name
    , length = hostname.length
    , ttl = Math.floor(Math.random() * 3600)

  if(question.type == 'A') {
    res.answer.push({name:hostname, type:'A', data:"1.1.1."+length, 'ttl':ttl})
    res.answer.push({name:hostname, type:'A', data:"2.2.2."+length, 'ttl':ttl})
  }
  res.end()
}

// To test, run this script and then in your terminal:
// $ dig @localhost -p 5353 example.com soa
// $ dig @localhost -p 5353 example.com a

view raw JSON →