Aesir NS ยท The DNS server
Njord NS Server: a DNS server in pure JavaScript
Njord does not keep records for you: it hands you each query as an object, you add the answers from wherever your records live, and you send the query back. It answers over UDP and TCP, including zone transfers, and has a recursor that asks other DNS servers for you.
- Version 2.3.0
- MIT licence
- On npm
- Node.js 20
At a glance
| Package | njord-ns-server |
|---|---|
| Version | 2.3.0 |
| Licence | MIT |
| Based on | node-named |
| Used by | Odin NS Manager and Freya NS API |
What it does
The common part of DNS, done carefully: the record types in use every day, the INET class, and EDNS0.
Queries as objects
A
queryevent hands you the name and the type. Add answers, set a response code, and send it, at once or later.UDP and TCP
Listen on both on the same port. DNS over TCP has limits you can set: connections, per client, idle time, lifetime and buffered data.
Zone transfers
AXFR over TCP, for secondary name servers that copy a whole zone.
A recursor
Answers a query by asking other DNS servers, the ones of the system unless you name them, for A, AAAA, CNAME, MX, NS, PTR, SOA, SRV and TXT.
EDNS0
The OPT record: larger answers over UDP, and the errors the standard asks for.
Records that check themselves
A, AAAA, CNAME, NS, PTR, MX, SRV, TXT and SOA.
valid()andinvalid()say whether a record can be sent, before a user’s typo breaks an answer.Counters
stats()reports the limits in force and what they did: open, refused and closed TCP connections, and EDNS errors.Examples that run
The examples of its README are run by its tests, so they stay correct. Complete servers come with it: reflect, zone transfer, recursor and one per CPU.
Get started
Install it, and a few lines make a server.
Install
From npm.
npm install njord-ns-server
A first server
Answers every A query with one address and refuses everything else, then asks itself one question and stops.
const { Resolver } = require('node:dns').promises;
const named = require('njord-ns-server');
const server = named.createServer();
server.on('query', (query) => {
if (query.type() === 'A')
query.addAnswer(query.name(), new named.ARecord('192.0.2.10'), 300);
else
query.setError('erefuse');
server.send(query);
});
server.listen(15301, '127.0.0.1', async () => {
const resolver = new Resolver();
resolver.setServers(['127.0.0.1:15301']);
console.log(await resolver.resolve4('www.example.com')); // [ '192.0.2.10' ]
server.close();
});
What it needs
| Node.js | 20 or newer |
|---|---|
| Dependencies | Two: a logger (bunyan) and an IP address parser (ipaddr.js) |
| Not included | DNSSEC signing, and classes other than INET |
The other modules
Each module has its own repository and version. A release of Odin pins the versions of the others, and the installer installs exactly those.
-
Odin NS Manager
The service you install. It brings the others together: the DNS server, the management API, the interface and the installers.
-
Freya NS API
The management API: zones and records, blocking, monitoring, users and sign-in, export and import, and the HTTPS certificate.
-
Bragi NS Client
A cached replacement of Node.js
dns.lookupfor outgoing connections, with round-robin and optional DNSSEC validation.