diff --git a/lib/dns/dns.js b/lib/dns/dns.js index 0eb4014..88cff84 100644 --- a/lib/dns/dns.js +++ b/lib/dns/dns.js @@ -9,6 +9,7 @@ const { readFile } = core //const { strerror } = system const decoder = new TextDecoder() +const default_bind_ip = lo.getenv('LO_DNS_BIND_IP') || '127.0.0.1' function parseLine (line) { const parts = line.split(/\s+/) @@ -104,7 +105,7 @@ class Resolver { * @param {Uint8Array} buf Buffer for DNS response * @returns {void} */ - lookup (query = 'localhost', onRecord = (err, ip) => {}, address = '127.0.0.1', port = 53, buf = new Uint8Array(65536)) { + lookup (query = 'localhost', onRecord = (err, ip) => {}, address = '127.0.0.1', port = 53, buf = new Uint8Array(65536), bind_ip = default_bind_ip) { if (this.cache.has(query)) { console.log('dns from cache') onRecord(null, this.cache.get(query)) @@ -128,7 +129,7 @@ class Resolver { let timer const node = new Node(this.loop) node.peer(address, port) - node.bind('127.0.0.1', () => { + node.bind(bind_ip, () => { const len = node.recv(buf) if (len <= 0) { if (timer) timer.close()