-
Notifications
You must be signed in to change notification settings - Fork 10
dWeb DNS Plug
Jared Rice Sr edited this page Jul 1, 2018
·
1 revision
A simple DNS proxy that lets you intercept domains and route them to whatever IP you decide.
It's available through npm:
npm install @distdns/plug
It's easy to use:
var dWebPlug = require('@distdns/plug').createServer();
dWebPlug.route('www.google.com', '127.0.0.1'); // route all requests to www.google.com to localhost
dWebPlug.listen(); // it listens on the standard DNS port of 53 per default
// route all domains to 127.0.0.1
dWebPlug.route(function(data, callback) {
callback(null, '127.0.0.1');
});
// route all google domains to 127.0.0.1
dWebPlug.route(['google.com', '*.google.com'], function(data, callback) {
callback(null, '127.0.0.1');
});
// now all requests to google.com should be routed localhost
require('http').createServer(function(req, res) {
res.writeHead(200);
res.end('dWeb says hi!');
}).listen(80);You probably need to run the above example with sudo as we need to listen to port 80 and 53.
Now change your local DNS server to 127.0.0.1 and visit http://www.google.com in your browser.
DNSJack will forward all request that you don't route yourself to Google's DNS server or whatever DNS
you provide in .createServer().
You can also use it to monitor your DNS resolutions which can be super useful for debugging:
var dWebPlug = require('@distdns/plug').createServer();
dWebPlug.on('resolve', function(data) {
console.log(data.rinfo.address, 'is resolving', data.domain);
});
dWebPlug.listen();You can also pass along the TTL when responding to a DNS request:
dWebPlug.route(['google.com', '*.google.com'], function(data, callback) {
callback(null, {ip: '127.0.0.1', ttl: 3600});
});