diff --git a/.gitignore b/.gitignore index a918375..51ca813 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ -.DS_Store +# Files *.swmp -node_modules npm-debug.log -tmp + +# Folders +tmp/ +node_modules/ +.DS_Store/ +.vs/ \ No newline at end of file diff --git a/README.md b/README.md index 9c5d05e..af9ed3a 100644 --- a/README.md +++ b/README.md @@ -4,26 +4,26 @@ Node-named is a lightweight DNS server written in pure javascript. It has limited support for the DNS spec, but aims to implement all of the *common* functionality that is in use today. - - ## Creating a DNS Server -```javascript - var named = require('./lib/index'); - var server = named.createServer(); - var ttl = 300; - - server.listen(9999, '127.0.0.1', function() { - console.log('DNS server started on port 9999'); - }); - - server.on('query', function(query) { - var domain = query.name(); - console.log('DNS Query: %s', domain) - var target = new named.SOARecord(domain, {serial: 12345}); - query.addAnswer(domain, target, ttl); - server.send(query); - }); + +```js +var named = require('./lib/index'); +var server = named.createServer(); +var ttl = 300; + +server.listen(9999, '127.0.0.1', function() { + console.log('DNS server started on port 9999'); +}); + +server.on('query', function(query) { + var domain = query.name(); + console.log('DNS Query: %s', domain) + var target = new named.SOARecord(domain, {serial: 12345}); + query.addAnswer(domain, target, ttl); + server.send(query); +}); ``` + ## Creating DNS Records node-named provides helper functions for creating DNS records. @@ -32,12 +32,13 @@ of ['A', 'AAAA', 'CNAME', 'SOA', 'MX', 'NS', 'TXT, 'SRV']. It is important to remember that these DNS records are not permanently added to the server. They only exist for the length of the particular request. After that, they are destroyed. This means you have to create your own lookup mechanism. -```javascript - var named = require('node-named'); - - var soaRecord = new named.SOARecord('example.com', {serial: 201205150000}); - console.log(soaRecord); +```js +var named = require('node-named'); + +var soaRecord = new named.SOARecord('example.com', {serial: 201205150000}); +console.log(soaRecord); ``` + ### Supported Record Types The following record types are supported @@ -53,15 +54,15 @@ The following record types are supported ## Logging -node-named uses [http://github.com/trentm/node-bunyan](bunyan) for logging. +node-named uses [bunyan](http://github.com/trentm/node-bunyan) for logging. It's a lot nicer to use if you npm install bunyan and put the bunyan tool in your path. Otherwise, you will end up with JSON formatted log output by default. ### Replacing the default logger You can pass in an alternate logger if you wish. If you do not, then it will use -bunyan by default. Your logger must expose the functions 'info', 'debug', -'warn', 'trace', 'error', and 'notice'. +bunyan by default. Your logger must expose the functions `info`, `debug`, +`warn`, `trace`, `error`, and `notice`. ### TODO diff --git a/docs/index.md b/docs/index.md index 455b054..78ab0b4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,54 +18,55 @@ pluggable storage mechanisms. This DNS server is good for creating services where your records may change frequently, or you would like to access records stored in a central system using a mechanism of your choosing. - # Installation - $ npm install named +`$ npm install named` # Server API - var named = require('./lib/index'); - var server = named.createServer(); +```js +var named = require('./lib/index'); +var server = named.createServer(); - server.listen(9999, '127.0.0.1', function() { - console.log('DNS server started on port 9999'); - }); +server.listen(9999, '127.0.0.1', function() { + console.log('DNS server started on port 9999'); +}); - server.on('query', function(query) { - var domain = query.name(); - var target = new named.SOARecord(domain, {serial: 12345}); - // 300 is the ttl for this record - query.addAnswer(domain, target, 300); - server.send(query); - }); +server.on('query', function(query) { + var domain = query.name(); + var target = new named.SOARecord(domain, { serial: 12345 }); + // 300 is the ttl for this record + query.addAnswer(domain, target, 300); + server.send(query); +}); +``` Hit this DNS server with `dig` to see some results. Because we are only handling DNS responses for one record type (SOA or 'Start of Authority'), that is the response we will see, regardless of the type we make a request for. Dig is nice about this. +``` +$ dig @localhost -p9999 example.com SOA - $ dig @localhost -p9999 example.com SOA - - ; <<>> DiG 9.7.3-P3 <<>> @localhost -p9999 example.com SOA - ; (3 servers found) - ;; global options: +cmd - ;; Got answer: - ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32739 - ;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 - ;; WARNING: recursion requested but not available - - ;; QUESTION SECTION: - ;example.com. IN SOA +; <<>> DiG 9.7.3-P3 <<>> @localhost -p9999 example.com SOA +; (3 servers found) +;; global options: +cmd +;; Got answer: +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32739 +;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 +;; WARNING: recursion requested but not available - ;; ANSWER SECTION: - example.com. 5 IN SOA example.com. hostmaster.example.com. 12345 10 10 10 10 +;; QUESTION SECTION: + ;example.com. IN SOA - ;; Query time: 10 msec - ;; SERVER: ::1#9999(::1) - ;; WHEN: Wed May 23 19:24:09 2012 - ;; MSG SIZE rcvd: 109 +;; ANSWER SECTION: + example.com.5 IN SOA example.com. hostmaster.example.com. 12345 10 10 10 10 +;; Query time: 10 msec +;; SERVER: ::1#9999(::1) +;; WHEN: Wed May 23 19:24:09 2012 +;; MSG SIZE rcvd: 109 +``` ## Named API @@ -79,14 +80,15 @@ options is an object which may specify: - name: an optional name used to identify the server Here is an example a named server listening on port 53 +```js +var named = require('named'); - var named = require('named'); +var server = named.createServer({ + name: 'named0' +}); - var server = named.createServer({ - name: 'named0' - }); - - server.listen(53); +server.listen(53); +``` ## Class: named.Server @@ -301,6 +303,4 @@ DnsErrors are: Returns the message that was passed in to the error. The message is a string, and can be used for logging purposes -## Server Properties - - +