DNS

bmeck edited this page Jun 23, 2012 · 5 revisions
Clone this wiki locally

RFCS

Examples

Client

var client = dns.createClient(port, nameserver);
var request = client.request({
  opcode: 'query' || 0,
  recursionDesired: true
});
request.addQuestion({
  domain: 'x.local', /*trailing '.' will be added*/
  rrtype: 'a', /*defaulted to 'a'*/
  rrclass: 'in' /*defaulted to 'in'*/
});
request.send();

Server

var server = dns.createServer();
server.on('request', function (req, res) {
  res.writeHead(statusCode, {
    authoritive: true
  });
  res.addAnswer({
    domain: 'x.local', /*trailing '.' will be added*/
    rrtype: /*defaulted to req.questions[n].rrtype*/
    rrclass: /*defaulted to req.questions[n].rrtype*/
    ttl: /*default of 60*/
    rdata: new Buffer([127,0,0,1])
  });
  res.end();
});