Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix md's #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.DS_Store
# Files
*.swmp
node_modules
npm-debug.log
tmp

# Folders
tmp/
node_modules/
.DS_Store/
.vs/
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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

Expand Down
82 changes: 41 additions & 41 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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


<!--## Server Properties>