11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html lang="en">
31cb0ef41Sopenharmony_ci<head>
41cb0ef41Sopenharmony_ci  <meta charset="utf-8">
51cb0ef41Sopenharmony_ci  <meta name="viewport" content="width=device-width">
61cb0ef41Sopenharmony_ci  <meta name="nodejs.org:node-version" content="v18.20.1">
71cb0ef41Sopenharmony_ci  <title>DNS | Node.js v18.20.1 Documentation</title>
81cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
91cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/style.css">
101cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/hljs.css">
111cb0ef41Sopenharmony_ci  <link rel="canonical" href="https://nodejs.org/api/dns.html">
121cb0ef41Sopenharmony_ci  <script async defer src="assets/api.js" type="text/javascript"></script>
131cb0ef41Sopenharmony_ci  
141cb0ef41Sopenharmony_ci</head>
151cb0ef41Sopenharmony_ci<body class="alt apidoc" id="api-section-dns">
161cb0ef41Sopenharmony_ci  <div id="content" class="clearfix">
171cb0ef41Sopenharmony_ci    <div id="column2" class="interior">
181cb0ef41Sopenharmony_ci      <div id="intro" class="interior">
191cb0ef41Sopenharmony_ci        <a href="/" title="Go back to the home page">
201cb0ef41Sopenharmony_ci          Node.js
211cb0ef41Sopenharmony_ci        </a>
221cb0ef41Sopenharmony_ci      </div>
231cb0ef41Sopenharmony_ci      <ul>
241cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
251cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
261cb0ef41Sopenharmony_ci</ul>
271cb0ef41Sopenharmony_ci<hr class="line">
281cb0ef41Sopenharmony_ci<ul>
291cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
301cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
311cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
321cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
331cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
341cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
351cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
361cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
371cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
381cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
391cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
401cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
411cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
421cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
431cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
441cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
451cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns active">DNS</a></li>
461cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
471cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
481cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
491cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
501cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
511cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
521cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
531cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
541cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
551cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
561cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
571cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
581cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
591cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
601cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
611cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
621cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
631cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
641cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
651cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
661cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
671cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
681cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
691cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
701cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
711cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
721cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
731cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
741cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
751cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
761cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
771cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
781cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
791cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
801cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
811cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
821cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
831cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
841cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
851cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
861cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
871cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
881cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
891cb0ef41Sopenharmony_ci</ul>
901cb0ef41Sopenharmony_ci<hr class="line">
911cb0ef41Sopenharmony_ci<ul>
921cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
931cb0ef41Sopenharmony_ci</ul>
941cb0ef41Sopenharmony_ci    </div>
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci    <div id="column1" data-id="dns" class="interior">
971cb0ef41Sopenharmony_ci      <header class="header">
981cb0ef41Sopenharmony_ci        <div class="header-container">
991cb0ef41Sopenharmony_ci          <h1>Node.js v18.20.1 documentation</h1>
1001cb0ef41Sopenharmony_ci          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
1011cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
1021cb0ef41Sopenharmony_ci              <path fill="none" d="M0 0h24v24H0z" />
1031cb0ef41Sopenharmony_ci              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
1041cb0ef41Sopenharmony_ci              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
1051cb0ef41Sopenharmony_ci            </svg>
1061cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
1071cb0ef41Sopenharmony_ci              <path d="M0 0h24v24H0z" fill="none" />
1081cb0ef41Sopenharmony_ci              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
1091cb0ef41Sopenharmony_ci            </svg>
1101cb0ef41Sopenharmony_ci          </button>
1111cb0ef41Sopenharmony_ci        </div>
1121cb0ef41Sopenharmony_ci        <div id="gtoc">
1131cb0ef41Sopenharmony_ci          <ul>
1141cb0ef41Sopenharmony_ci            <li class="pinned-header">Node.js v18.20.1</li>
1151cb0ef41Sopenharmony_ci            
1161cb0ef41Sopenharmony_ci    <li class="picker-header">
1171cb0ef41Sopenharmony_ci      <a href="#">
1181cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
1191cb0ef41Sopenharmony_ci        Table of contents
1201cb0ef41Sopenharmony_ci      </a>
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci      <div class="picker"><div class="toc"><ul>
1231cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#dns">DNS</a></span>
1241cb0ef41Sopenharmony_ci<ul>
1251cb0ef41Sopenharmony_ci<li><a href="#class-dnsresolver">Class: <code>dns.Resolver</code></a>
1261cb0ef41Sopenharmony_ci<ul>
1271cb0ef41Sopenharmony_ci<li><a href="#resolveroptions"><code>Resolver([options])</code></a></li>
1281cb0ef41Sopenharmony_ci<li><a href="#resolvercancel"><code>resolver.cancel()</code></a></li>
1291cb0ef41Sopenharmony_ci<li><a href="#resolversetlocaladdressipv4-ipv6"><code>resolver.setLocalAddress([ipv4][, ipv6])</code></a></li>
1301cb0ef41Sopenharmony_ci</ul>
1311cb0ef41Sopenharmony_ci</li>
1321cb0ef41Sopenharmony_ci<li><a href="#dnsgetservers"><code>dns.getServers()</code></a></li>
1331cb0ef41Sopenharmony_ci<li><a href="#dnslookuphostname-options-callback"><code>dns.lookup(hostname[, options], callback)</code></a>
1341cb0ef41Sopenharmony_ci<ul>
1351cb0ef41Sopenharmony_ci<li><a href="#supported-getaddrinfo-flags">Supported getaddrinfo flags</a></li>
1361cb0ef41Sopenharmony_ci</ul>
1371cb0ef41Sopenharmony_ci</li>
1381cb0ef41Sopenharmony_ci<li><a href="#dnslookupserviceaddress-port-callback"><code>dns.lookupService(address, port, callback)</code></a></li>
1391cb0ef41Sopenharmony_ci<li><a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve(hostname[, rrtype], callback)</code></a></li>
1401cb0ef41Sopenharmony_ci<li><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4(hostname[, options], callback)</code></a></li>
1411cb0ef41Sopenharmony_ci<li><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6(hostname[, options], callback)</code></a></li>
1421cb0ef41Sopenharmony_ci<li><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny(hostname, callback)</code></a></li>
1431cb0ef41Sopenharmony_ci<li><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname(hostname, callback)</code></a></li>
1441cb0ef41Sopenharmony_ci<li><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa(hostname, callback)</code></a></li>
1451cb0ef41Sopenharmony_ci<li><a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx(hostname, callback)</code></a></li>
1461cb0ef41Sopenharmony_ci<li><a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr(hostname, callback)</code></a></li>
1471cb0ef41Sopenharmony_ci<li><a href="#dnsresolvenshostname-callback"><code>dns.resolveNs(hostname, callback)</code></a></li>
1481cb0ef41Sopenharmony_ci<li><a href="#dnsresolveptrhostname-callback"><code>dns.resolvePtr(hostname, callback)</code></a></li>
1491cb0ef41Sopenharmony_ci<li><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa(hostname, callback)</code></a></li>
1501cb0ef41Sopenharmony_ci<li><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv(hostname, callback)</code></a></li>
1511cb0ef41Sopenharmony_ci<li><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt(hostname, callback)</code></a></li>
1521cb0ef41Sopenharmony_ci<li><a href="#dnsreverseip-callback"><code>dns.reverse(ip, callback)</code></a></li>
1531cb0ef41Sopenharmony_ci<li><a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder(order)</code></a></li>
1541cb0ef41Sopenharmony_ci<li><a href="#dnsgetdefaultresultorder"><code>dns.getDefaultResultOrder()</code></a></li>
1551cb0ef41Sopenharmony_ci<li><a href="#dnssetserversservers"><code>dns.setServers(servers)</code></a></li>
1561cb0ef41Sopenharmony_ci<li><a href="#dns-promises-api">DNS promises API</a>
1571cb0ef41Sopenharmony_ci<ul>
1581cb0ef41Sopenharmony_ci<li><a href="#class-dnspromisesresolver">Class: <code>dnsPromises.Resolver</code></a></li>
1591cb0ef41Sopenharmony_ci<li><a href="#resolvercancel_1"><code>resolver.cancel()</code></a></li>
1601cb0ef41Sopenharmony_ci<li><a href="#dnspromisesgetservers"><code>dnsPromises.getServers()</code></a></li>
1611cb0ef41Sopenharmony_ci<li><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup(hostname[, options])</code></a></li>
1621cb0ef41Sopenharmony_ci<li><a href="#dnspromiseslookupserviceaddress-port"><code>dnsPromises.lookupService(address, port)</code></a></li>
1631cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvehostname-rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</code></a></li>
1641cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4(hostname[, options])</code></a></li>
1651cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6(hostname[, options])</code></a></li>
1661cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolveanyhostname"><code>dnsPromises.resolveAny(hostname)</code></a></li>
1671cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvecaahostname"><code>dnsPromises.resolveCaa(hostname)</code></a></li>
1681cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvecnamehostname"><code>dnsPromises.resolveCname(hostname)</code></a></li>
1691cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx(hostname)</code></a></li>
1701cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr(hostname)</code></a></li>
1711cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvenshostname"><code>dnsPromises.resolveNs(hostname)</code></a></li>
1721cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolveptrhostname"><code>dnsPromises.resolvePtr(hostname)</code></a></li>
1731cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa(hostname)</code></a></li>
1741cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv(hostname)</code></a></li>
1751cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt(hostname)</code></a></li>
1761cb0ef41Sopenharmony_ci<li><a href="#dnspromisesreverseip"><code>dnsPromises.reverse(ip)</code></a></li>
1771cb0ef41Sopenharmony_ci<li><a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder(order)</code></a></li>
1781cb0ef41Sopenharmony_ci<li><a href="#dnspromisesgetdefaultresultorder"><code>dnsPromises.getDefaultResultOrder()</code></a></li>
1791cb0ef41Sopenharmony_ci<li><a href="#dnspromisessetserversservers"><code>dnsPromises.setServers(servers)</code></a></li>
1801cb0ef41Sopenharmony_ci</ul>
1811cb0ef41Sopenharmony_ci</li>
1821cb0ef41Sopenharmony_ci<li><a href="#error-codes">Error codes</a></li>
1831cb0ef41Sopenharmony_ci<li><a href="#implementation-considerations">Implementation considerations</a>
1841cb0ef41Sopenharmony_ci<ul>
1851cb0ef41Sopenharmony_ci<li><a href="#dnslookup"><code>dns.lookup()</code></a></li>
1861cb0ef41Sopenharmony_ci<li><a href="#dnsresolve-dnsresolve-and-dnsreverse"><code>dns.resolve()</code>, <code>dns.resolve*()</code>, and <code>dns.reverse()</code></a></li>
1871cb0ef41Sopenharmony_ci</ul>
1881cb0ef41Sopenharmony_ci</li>
1891cb0ef41Sopenharmony_ci</ul>
1901cb0ef41Sopenharmony_ci</li>
1911cb0ef41Sopenharmony_ci</ul></div></div>
1921cb0ef41Sopenharmony_ci    </li>
1931cb0ef41Sopenharmony_ci  
1941cb0ef41Sopenharmony_ci            
1951cb0ef41Sopenharmony_ci    <li class="picker-header">
1961cb0ef41Sopenharmony_ci      <a href="#">
1971cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
1981cb0ef41Sopenharmony_ci        Index
1991cb0ef41Sopenharmony_ci      </a>
2001cb0ef41Sopenharmony_ci
2011cb0ef41Sopenharmony_ci      <div class="picker"><ul>
2021cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
2031cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci      <li>
2061cb0ef41Sopenharmony_ci        <a href="index.html">Index</a>
2071cb0ef41Sopenharmony_ci      </li>
2081cb0ef41Sopenharmony_ci    </ul>
2091cb0ef41Sopenharmony_ci  
2101cb0ef41Sopenharmony_ci<hr class="line">
2111cb0ef41Sopenharmony_ci<ul>
2121cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
2131cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
2141cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
2151cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
2161cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
2171cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
2181cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
2191cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
2201cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
2211cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
2221cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
2231cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
2241cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
2251cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
2261cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
2271cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
2281cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns active">DNS</a></li>
2291cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
2301cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
2311cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
2321cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
2331cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
2341cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
2351cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
2361cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
2371cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
2381cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
2391cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
2401cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
2411cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
2421cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
2431cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
2441cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
2451cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
2461cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
2471cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
2481cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
2491cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
2501cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
2511cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
2521cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
2531cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
2541cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
2551cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
2561cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
2571cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
2581cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
2591cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
2601cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
2611cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
2621cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
2631cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
2641cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
2651cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
2661cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
2671cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
2681cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
2691cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
2701cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
2711cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
2721cb0ef41Sopenharmony_ci</ul>
2731cb0ef41Sopenharmony_ci<hr class="line">
2741cb0ef41Sopenharmony_ci<ul>
2751cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
2761cb0ef41Sopenharmony_ci</ul></div>
2771cb0ef41Sopenharmony_ci    </li>
2781cb0ef41Sopenharmony_ci  
2791cb0ef41Sopenharmony_ci            
2801cb0ef41Sopenharmony_ci    <li class="picker-header">
2811cb0ef41Sopenharmony_ci      <a href="#">
2821cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2831cb0ef41Sopenharmony_ci        Other versions
2841cb0ef41Sopenharmony_ci      </a>
2851cb0ef41Sopenharmony_ci      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/dns.html">21.x</a></li>
2861cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v20.x/api/dns.html">20.x <b>LTS</b></a></li>
2871cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v19.x/api/dns.html">19.x</a></li>
2881cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v18.x/api/dns.html">18.x <b>LTS</b></a></li>
2891cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v17.x/api/dns.html">17.x</a></li>
2901cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v16.x/api/dns.html">16.x</a></li>
2911cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v15.x/api/dns.html">15.x</a></li>
2921cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v14.x/api/dns.html">14.x</a></li>
2931cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v13.x/api/dns.html">13.x</a></li>
2941cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v12.x/api/dns.html">12.x</a></li>
2951cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v11.x/api/dns.html">11.x</a></li>
2961cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v10.x/api/dns.html">10.x</a></li>
2971cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v9.x/api/dns.html">9.x</a></li>
2981cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v8.x/api/dns.html">8.x</a></li>
2991cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v7.x/api/dns.html">7.x</a></li>
3001cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v6.x/api/dns.html">6.x</a></li>
3011cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v5.x/api/dns.html">5.x</a></li>
3021cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v4.x/api/dns.html">4.x</a></li>
3031cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/dns.html">0.12.x</a></li>
3041cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/dns.html">0.10.x</a></li></ol></div>
3051cb0ef41Sopenharmony_ci    </li>
3061cb0ef41Sopenharmony_ci  
3071cb0ef41Sopenharmony_ci            <li class="picker-header">
3081cb0ef41Sopenharmony_ci              <a href="#">
3091cb0ef41Sopenharmony_ci                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
3101cb0ef41Sopenharmony_ci                Options
3111cb0ef41Sopenharmony_ci              </a>
3121cb0ef41Sopenharmony_ci        
3131cb0ef41Sopenharmony_ci              <div class="picker">
3141cb0ef41Sopenharmony_ci                <ul>
3151cb0ef41Sopenharmony_ci                  <li>
3161cb0ef41Sopenharmony_ci                    <a href="all.html">View on single page</a>
3171cb0ef41Sopenharmony_ci                  </li>
3181cb0ef41Sopenharmony_ci                  <li>
3191cb0ef41Sopenharmony_ci                    <a href="dns.json">View as JSON</a>
3201cb0ef41Sopenharmony_ci                  </li>
3211cb0ef41Sopenharmony_ci                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/dns.md">Edit on GitHub</a></li>    
3221cb0ef41Sopenharmony_ci                </ul>
3231cb0ef41Sopenharmony_ci              </div>
3241cb0ef41Sopenharmony_ci            </li>
3251cb0ef41Sopenharmony_ci          </ul>
3261cb0ef41Sopenharmony_ci        </div>
3271cb0ef41Sopenharmony_ci        <hr>
3281cb0ef41Sopenharmony_ci      </header>
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ci      <details id="toc" open><summary>Table of contents</summary><ul>
3311cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#dns">DNS</a></span>
3321cb0ef41Sopenharmony_ci<ul>
3331cb0ef41Sopenharmony_ci<li><a href="#class-dnsresolver">Class: <code>dns.Resolver</code></a>
3341cb0ef41Sopenharmony_ci<ul>
3351cb0ef41Sopenharmony_ci<li><a href="#resolveroptions"><code>Resolver([options])</code></a></li>
3361cb0ef41Sopenharmony_ci<li><a href="#resolvercancel"><code>resolver.cancel()</code></a></li>
3371cb0ef41Sopenharmony_ci<li><a href="#resolversetlocaladdressipv4-ipv6"><code>resolver.setLocalAddress([ipv4][, ipv6])</code></a></li>
3381cb0ef41Sopenharmony_ci</ul>
3391cb0ef41Sopenharmony_ci</li>
3401cb0ef41Sopenharmony_ci<li><a href="#dnsgetservers"><code>dns.getServers()</code></a></li>
3411cb0ef41Sopenharmony_ci<li><a href="#dnslookuphostname-options-callback"><code>dns.lookup(hostname[, options], callback)</code></a>
3421cb0ef41Sopenharmony_ci<ul>
3431cb0ef41Sopenharmony_ci<li><a href="#supported-getaddrinfo-flags">Supported getaddrinfo flags</a></li>
3441cb0ef41Sopenharmony_ci</ul>
3451cb0ef41Sopenharmony_ci</li>
3461cb0ef41Sopenharmony_ci<li><a href="#dnslookupserviceaddress-port-callback"><code>dns.lookupService(address, port, callback)</code></a></li>
3471cb0ef41Sopenharmony_ci<li><a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve(hostname[, rrtype], callback)</code></a></li>
3481cb0ef41Sopenharmony_ci<li><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4(hostname[, options], callback)</code></a></li>
3491cb0ef41Sopenharmony_ci<li><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6(hostname[, options], callback)</code></a></li>
3501cb0ef41Sopenharmony_ci<li><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny(hostname, callback)</code></a></li>
3511cb0ef41Sopenharmony_ci<li><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname(hostname, callback)</code></a></li>
3521cb0ef41Sopenharmony_ci<li><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa(hostname, callback)</code></a></li>
3531cb0ef41Sopenharmony_ci<li><a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx(hostname, callback)</code></a></li>
3541cb0ef41Sopenharmony_ci<li><a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr(hostname, callback)</code></a></li>
3551cb0ef41Sopenharmony_ci<li><a href="#dnsresolvenshostname-callback"><code>dns.resolveNs(hostname, callback)</code></a></li>
3561cb0ef41Sopenharmony_ci<li><a href="#dnsresolveptrhostname-callback"><code>dns.resolvePtr(hostname, callback)</code></a></li>
3571cb0ef41Sopenharmony_ci<li><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa(hostname, callback)</code></a></li>
3581cb0ef41Sopenharmony_ci<li><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv(hostname, callback)</code></a></li>
3591cb0ef41Sopenharmony_ci<li><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt(hostname, callback)</code></a></li>
3601cb0ef41Sopenharmony_ci<li><a href="#dnsreverseip-callback"><code>dns.reverse(ip, callback)</code></a></li>
3611cb0ef41Sopenharmony_ci<li><a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder(order)</code></a></li>
3621cb0ef41Sopenharmony_ci<li><a href="#dnsgetdefaultresultorder"><code>dns.getDefaultResultOrder()</code></a></li>
3631cb0ef41Sopenharmony_ci<li><a href="#dnssetserversservers"><code>dns.setServers(servers)</code></a></li>
3641cb0ef41Sopenharmony_ci<li><a href="#dns-promises-api">DNS promises API</a>
3651cb0ef41Sopenharmony_ci<ul>
3661cb0ef41Sopenharmony_ci<li><a href="#class-dnspromisesresolver">Class: <code>dnsPromises.Resolver</code></a></li>
3671cb0ef41Sopenharmony_ci<li><a href="#resolvercancel_1"><code>resolver.cancel()</code></a></li>
3681cb0ef41Sopenharmony_ci<li><a href="#dnspromisesgetservers"><code>dnsPromises.getServers()</code></a></li>
3691cb0ef41Sopenharmony_ci<li><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup(hostname[, options])</code></a></li>
3701cb0ef41Sopenharmony_ci<li><a href="#dnspromiseslookupserviceaddress-port"><code>dnsPromises.lookupService(address, port)</code></a></li>
3711cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvehostname-rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</code></a></li>
3721cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4(hostname[, options])</code></a></li>
3731cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6(hostname[, options])</code></a></li>
3741cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolveanyhostname"><code>dnsPromises.resolveAny(hostname)</code></a></li>
3751cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvecaahostname"><code>dnsPromises.resolveCaa(hostname)</code></a></li>
3761cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvecnamehostname"><code>dnsPromises.resolveCname(hostname)</code></a></li>
3771cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx(hostname)</code></a></li>
3781cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr(hostname)</code></a></li>
3791cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvenshostname"><code>dnsPromises.resolveNs(hostname)</code></a></li>
3801cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolveptrhostname"><code>dnsPromises.resolvePtr(hostname)</code></a></li>
3811cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa(hostname)</code></a></li>
3821cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv(hostname)</code></a></li>
3831cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt(hostname)</code></a></li>
3841cb0ef41Sopenharmony_ci<li><a href="#dnspromisesreverseip"><code>dnsPromises.reverse(ip)</code></a></li>
3851cb0ef41Sopenharmony_ci<li><a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder(order)</code></a></li>
3861cb0ef41Sopenharmony_ci<li><a href="#dnspromisesgetdefaultresultorder"><code>dnsPromises.getDefaultResultOrder()</code></a></li>
3871cb0ef41Sopenharmony_ci<li><a href="#dnspromisessetserversservers"><code>dnsPromises.setServers(servers)</code></a></li>
3881cb0ef41Sopenharmony_ci</ul>
3891cb0ef41Sopenharmony_ci</li>
3901cb0ef41Sopenharmony_ci<li><a href="#error-codes">Error codes</a></li>
3911cb0ef41Sopenharmony_ci<li><a href="#implementation-considerations">Implementation considerations</a>
3921cb0ef41Sopenharmony_ci<ul>
3931cb0ef41Sopenharmony_ci<li><a href="#dnslookup"><code>dns.lookup()</code></a></li>
3941cb0ef41Sopenharmony_ci<li><a href="#dnsresolve-dnsresolve-and-dnsreverse"><code>dns.resolve()</code>, <code>dns.resolve*()</code>, and <code>dns.reverse()</code></a></li>
3951cb0ef41Sopenharmony_ci</ul>
3961cb0ef41Sopenharmony_ci</li>
3971cb0ef41Sopenharmony_ci</ul>
3981cb0ef41Sopenharmony_ci</li>
3991cb0ef41Sopenharmony_ci</ul></details>
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ci      <div id="apicontent">
4021cb0ef41Sopenharmony_ci        <h2>DNS<span><a class="mark" href="#dns" id="dns">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns"></a></h2>
4031cb0ef41Sopenharmony_ci
4041cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</div><p></p>
4051cb0ef41Sopenharmony_ci<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/dns.js">lib/dns.js</a></p>
4061cb0ef41Sopenharmony_ci<p>The <code>node:dns</code> module enables name resolution. For example, use it to look up IP
4071cb0ef41Sopenharmony_ciaddresses of host names.</p>
4081cb0ef41Sopenharmony_ci<p>Although named for the <a href="https://en.wikipedia.org/wiki/Domain_Name_System">Domain Name System (DNS)</a>, it does not always use the
4091cb0ef41Sopenharmony_ciDNS protocol for lookups. <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> uses the operating system
4101cb0ef41Sopenharmony_cifacilities to perform name resolution. It may not need to perform any network
4111cb0ef41Sopenharmony_cicommunication. To perform name resolution the way other applications on the same
4121cb0ef41Sopenharmony_cisystem do, use <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>.</p>
4131cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>);
4141cb0ef41Sopenharmony_ci
4151cb0ef41Sopenharmony_cidns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.org'</span>, <span class="hljs-function">(<span class="hljs-params">err, address, family</span>) =></span> {
4161cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'address: %j family: IPv%s'</span>, address, family);
4171cb0ef41Sopenharmony_ci});
4181cb0ef41Sopenharmony_ci<span class="hljs-comment">// address: "93.184.216.34" family: IPv4</span></code> <button class="copy-button">copy</button></pre>
4191cb0ef41Sopenharmony_ci<p>All other functions in the <code>node:dns</code> module connect to an actual DNS server to
4201cb0ef41Sopenharmony_ciperform name resolution. They will always use the network to perform DNS
4211cb0ef41Sopenharmony_ciqueries. These functions do not use the same set of configuration files used by
4221cb0ef41Sopenharmony_ci<a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> (e.g. <code>/etc/hosts</code>). Use these functions to always perform
4231cb0ef41Sopenharmony_ciDNS queries, bypassing other name-resolution facilities.</p>
4241cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>);
4251cb0ef41Sopenharmony_ci
4261cb0ef41Sopenharmony_cidns.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'archive.org'</span>, <span class="hljs-function">(<span class="hljs-params">err, addresses</span>) =></span> {
4271cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">throw</span> err;
4281cb0ef41Sopenharmony_ci
4291cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`addresses: <span class="hljs-subst">${<span class="hljs-built_in">JSON</span>.stringify(addresses)}</span>`</span>);
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci  addresses.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">a</span>) =></span> {
4321cb0ef41Sopenharmony_ci    dns.<span class="hljs-title function_">reverse</span>(a, <span class="hljs-function">(<span class="hljs-params">err, hostnames</span>) =></span> {
4331cb0ef41Sopenharmony_ci      <span class="hljs-keyword">if</span> (err) {
4341cb0ef41Sopenharmony_ci        <span class="hljs-keyword">throw</span> err;
4351cb0ef41Sopenharmony_ci      }
4361cb0ef41Sopenharmony_ci      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`reverse for <span class="hljs-subst">${a}</span>: <span class="hljs-subst">${<span class="hljs-built_in">JSON</span>.stringify(hostnames)}</span>`</span>);
4371cb0ef41Sopenharmony_ci    });
4381cb0ef41Sopenharmony_ci  });
4391cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
4401cb0ef41Sopenharmony_ci<p>See the <a href="#implementation-considerations">Implementation considerations section</a> for more information.</p>
4411cb0ef41Sopenharmony_ci<section><h3>Class: <code>dns.Resolver</code><span><a class="mark" href="#class-dnsresolver" id="class-dnsresolver">#</a></span><a aria-hidden="true" class="legacy" id="dns_class_dns_resolver"></a></h3>
4421cb0ef41Sopenharmony_ci<div class="api_metadata">
4431cb0ef41Sopenharmony_ci<span>Added in: v8.3.0</span>
4441cb0ef41Sopenharmony_ci</div>
4451cb0ef41Sopenharmony_ci<p>An independent resolver for DNS requests.</p>
4461cb0ef41Sopenharmony_ci<p>Creating a new resolver uses the default server settings. Setting
4471cb0ef41Sopenharmony_cithe servers used for a resolver using
4481cb0ef41Sopenharmony_ci<a href="#dnssetserversservers"><code>resolver.setServers()</code></a> does not affect
4491cb0ef41Sopenharmony_ciother resolvers:</p>
4501cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">Resolver</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>);
4511cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Resolver</span>();
4521cb0ef41Sopenharmony_ciresolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'</span>]);
4531cb0ef41Sopenharmony_ci
4541cb0ef41Sopenharmony_ci<span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global settings.</span>
4551cb0ef41Sopenharmony_ciresolver.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>, <span class="hljs-function">(<span class="hljs-params">err, addresses</span>) =></span> {
4561cb0ef41Sopenharmony_ci  <span class="hljs-comment">// ...</span>
4571cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
4581cb0ef41Sopenharmony_ci<p>The following methods from the <code>node:dns</code> module are available:</p>
4591cb0ef41Sopenharmony_ci<ul>
4601cb0ef41Sopenharmony_ci<li><a href="#dnsgetservers"><code>resolver.getServers()</code></a></li>
4611cb0ef41Sopenharmony_ci<li><a href="#dnsresolvehostname-rrtype-callback"><code>resolver.resolve()</code></a></li>
4621cb0ef41Sopenharmony_ci<li><a href="#dnsresolve4hostname-options-callback"><code>resolver.resolve4()</code></a></li>
4631cb0ef41Sopenharmony_ci<li><a href="#dnsresolve6hostname-options-callback"><code>resolver.resolve6()</code></a></li>
4641cb0ef41Sopenharmony_ci<li><a href="#dnsresolveanyhostname-callback"><code>resolver.resolveAny()</code></a></li>
4651cb0ef41Sopenharmony_ci<li><a href="#dnsresolvecaahostname-callback"><code>resolver.resolveCaa()</code></a></li>
4661cb0ef41Sopenharmony_ci<li><a href="#dnsresolvecnamehostname-callback"><code>resolver.resolveCname()</code></a></li>
4671cb0ef41Sopenharmony_ci<li><a href="#dnsresolvemxhostname-callback"><code>resolver.resolveMx()</code></a></li>
4681cb0ef41Sopenharmony_ci<li><a href="#dnsresolvenaptrhostname-callback"><code>resolver.resolveNaptr()</code></a></li>
4691cb0ef41Sopenharmony_ci<li><a href="#dnsresolvenshostname-callback"><code>resolver.resolveNs()</code></a></li>
4701cb0ef41Sopenharmony_ci<li><a href="#dnsresolveptrhostname-callback"><code>resolver.resolvePtr()</code></a></li>
4711cb0ef41Sopenharmony_ci<li><a href="#dnsresolvesoahostname-callback"><code>resolver.resolveSoa()</code></a></li>
4721cb0ef41Sopenharmony_ci<li><a href="#dnsresolvesrvhostname-callback"><code>resolver.resolveSrv()</code></a></li>
4731cb0ef41Sopenharmony_ci<li><a href="#dnsresolvetxthostname-callback"><code>resolver.resolveTxt()</code></a></li>
4741cb0ef41Sopenharmony_ci<li><a href="#dnsreverseip-callback"><code>resolver.reverse()</code></a></li>
4751cb0ef41Sopenharmony_ci<li><a href="#dnssetserversservers"><code>resolver.setServers()</code></a></li>
4761cb0ef41Sopenharmony_ci</ul>
4771cb0ef41Sopenharmony_ci<h4><code>Resolver([options])</code><span><a class="mark" href="#resolveroptions" id="resolveroptions">#</a></span><a aria-hidden="true" class="legacy" id="dns_resolver_options"></a></h4>
4781cb0ef41Sopenharmony_ci<div class="api_metadata">
4791cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
4801cb0ef41Sopenharmony_ci<table>
4811cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
4821cb0ef41Sopenharmony_ci<tr><td>v16.7.0, v14.18.0</td>
4831cb0ef41Sopenharmony_ci<td><p>The <code>options</code> object now accepts a <code>tries</code> option.</p></td></tr>
4841cb0ef41Sopenharmony_ci<tr><td>v12.18.3</td>
4851cb0ef41Sopenharmony_ci<td><p>The constructor now accepts an <code>options</code> object. The single supported option is <code>timeout</code>.</p></td></tr>
4861cb0ef41Sopenharmony_ci<tr><td>v8.3.0</td>
4871cb0ef41Sopenharmony_ci<td><p><span>Added in: v8.3.0</span></p></td></tr>
4881cb0ef41Sopenharmony_ci</tbody></table>
4891cb0ef41Sopenharmony_ci</details>
4901cb0ef41Sopenharmony_ci</div>
4911cb0ef41Sopenharmony_ci<p>Create a new resolver.</p>
4921cb0ef41Sopenharmony_ci<ul>
4931cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
4941cb0ef41Sopenharmony_ci<ul>
4951cb0ef41Sopenharmony_ci<li><code>timeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Query timeout in milliseconds, or <code>-1</code> to use the
4961cb0ef41Sopenharmony_cidefault timeout.</li>
4971cb0ef41Sopenharmony_ci<li><code>tries</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> The number of tries the resolver will try contacting
4981cb0ef41Sopenharmony_cieach name server before giving up. <strong>Default:</strong> <code>4</code></li>
4991cb0ef41Sopenharmony_ci</ul>
5001cb0ef41Sopenharmony_ci</li>
5011cb0ef41Sopenharmony_ci</ul>
5021cb0ef41Sopenharmony_ci<h4><code>resolver.cancel()</code><span><a class="mark" href="#resolvercancel" id="resolvercancel">#</a></span><a aria-hidden="true" class="legacy" id="dns_resolver_cancel"></a></h4>
5031cb0ef41Sopenharmony_ci<div class="api_metadata">
5041cb0ef41Sopenharmony_ci<span>Added in: v8.3.0</span>
5051cb0ef41Sopenharmony_ci</div>
5061cb0ef41Sopenharmony_ci<p>Cancel all outstanding DNS queries made by this resolver. The corresponding
5071cb0ef41Sopenharmony_cicallbacks will be called with an error with code <code>ECANCELLED</code>.</p>
5081cb0ef41Sopenharmony_ci<h4><code>resolver.setLocalAddress([ipv4][, ipv6])</code><span><a class="mark" href="#resolversetlocaladdressipv4-ipv6" id="resolversetlocaladdressipv4-ipv6">#</a></span><a aria-hidden="true" class="legacy" id="dns_resolver_setlocaladdress_ipv4_ipv6"></a></h4>
5091cb0ef41Sopenharmony_ci<div class="api_metadata">
5101cb0ef41Sopenharmony_ci<span>Added in: v15.1.0, v14.17.0</span>
5111cb0ef41Sopenharmony_ci</div>
5121cb0ef41Sopenharmony_ci<ul>
5131cb0ef41Sopenharmony_ci<li><code>ipv4</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A string representation of an IPv4 address.
5141cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>'0.0.0.0'</code></li>
5151cb0ef41Sopenharmony_ci<li><code>ipv6</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A string representation of an IPv6 address.
5161cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>'::0'</code></li>
5171cb0ef41Sopenharmony_ci</ul>
5181cb0ef41Sopenharmony_ci<p>The resolver instance will send its requests from the specified IP address.
5191cb0ef41Sopenharmony_ciThis allows programs to specify outbound interfaces when used on multi-homed
5201cb0ef41Sopenharmony_cisystems.</p>
5211cb0ef41Sopenharmony_ci<p>If a v4 or v6 address is not specified, it is set to the default and the
5221cb0ef41Sopenharmony_cioperating system will choose a local address automatically.</p>
5231cb0ef41Sopenharmony_ci<p>The resolver will use the v4 local address when making requests to IPv4 DNS
5241cb0ef41Sopenharmony_ciservers, and the v6 local address when making requests to IPv6 DNS servers.
5251cb0ef41Sopenharmony_ciThe <code>rrtype</code> of resolution requests has no impact on the local address used.</p>
5261cb0ef41Sopenharmony_ci</section><section><h3><code>dns.getServers()</code><span><a class="mark" href="#dnsgetservers" id="dnsgetservers">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_getservers"></a></h3>
5271cb0ef41Sopenharmony_ci<div class="api_metadata">
5281cb0ef41Sopenharmony_ci<span>Added in: v0.11.3</span>
5291cb0ef41Sopenharmony_ci</div>
5301cb0ef41Sopenharmony_ci<ul>
5311cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
5321cb0ef41Sopenharmony_ci</ul>
5331cb0ef41Sopenharmony_ci<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
5341cb0ef41Sopenharmony_cithat are currently configured for DNS resolution. A string will include a port
5351cb0ef41Sopenharmony_cisection if a custom port is used.</p>
5361cb0ef41Sopenharmony_ci<!-- eslint-disable semi-->
5371cb0ef41Sopenharmony_ci<pre><code class="language-js">[
5381cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4'</span>,
5391cb0ef41Sopenharmony_ci  <span class="hljs-string">'2001:4860:4860::8888'</span>,
5401cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4:1053'</span>,
5411cb0ef41Sopenharmony_ci  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
5421cb0ef41Sopenharmony_ci]</code> <button class="copy-button">copy</button></pre>
5431cb0ef41Sopenharmony_ci</section><section><h3><code>dns.lookup(hostname[, options], callback)</code><span><a class="mark" href="#dnslookuphostname-options-callback" id="dnslookuphostname-options-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_lookup_hostname_options_callback"></a></h3>
5441cb0ef41Sopenharmony_ci<div class="api_metadata">
5451cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
5461cb0ef41Sopenharmony_ci<table>
5471cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
5481cb0ef41Sopenharmony_ci<tr><td>v18.4.0</td>
5491cb0ef41Sopenharmony_ci<td><p>For compatibility with <code>node:net</code>, when passing an option object the <code>family</code> option can be the string <code>'IPv4'</code> or the string <code>'IPv6'</code>.</p></td></tr>
5501cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
5511cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
5521cb0ef41Sopenharmony_ci<tr><td>v17.0.0</td>
5531cb0ef41Sopenharmony_ci<td><p>The <code>verbatim</code> options defaults to <code>true</code> now.</p></td></tr>
5541cb0ef41Sopenharmony_ci<tr><td>v8.5.0</td>
5551cb0ef41Sopenharmony_ci<td><p>The <code>verbatim</code> option is supported now.</p></td></tr>
5561cb0ef41Sopenharmony_ci<tr><td>v1.2.0</td>
5571cb0ef41Sopenharmony_ci<td><p>The <code>all</code> option is supported now.</p></td></tr>
5581cb0ef41Sopenharmony_ci<tr><td>v0.1.90</td>
5591cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.90</span></p></td></tr>
5601cb0ef41Sopenharmony_ci</tbody></table>
5611cb0ef41Sopenharmony_ci</details>
5621cb0ef41Sopenharmony_ci</div>
5631cb0ef41Sopenharmony_ci<ul>
5641cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
5651cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
5661cb0ef41Sopenharmony_ci<ul>
5671cb0ef41Sopenharmony_ci<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. For
5681cb0ef41Sopenharmony_cibackward compatibility reasons,<code>'IPv4'</code> and <code>'IPv6'</code> are interpreted as <code>4</code>
5691cb0ef41Sopenharmony_ciand <code>6</code> respectively. The value <code>0</code> indicates that IPv4 and IPv6 addresses
5701cb0ef41Sopenharmony_ciare both returned. <strong>Default:</strong> <code>0</code>.</li>
5711cb0ef41Sopenharmony_ci<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> One or more <a href="#supported-getaddrinfo-flags">supported <code>getaddrinfo</code> flags</a>. Multiple
5721cb0ef41Sopenharmony_ciflags may be passed by bitwise <code>OR</code>ing their values.</li>
5731cb0ef41Sopenharmony_ci<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the callback returns all resolved addresses in
5741cb0ef41Sopenharmony_cian array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
5751cb0ef41Sopenharmony_ci<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the callback receives IPv4 and IPv6
5761cb0ef41Sopenharmony_ciaddresses in the order the DNS resolver returned them. When <code>false</code>,
5771cb0ef41Sopenharmony_ciIPv4 addresses are placed before IPv6 addresses.
5781cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>true</code> (addresses are not reordered). Default value is
5791cb0ef41Sopenharmony_ciconfigurable using <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> or
5801cb0ef41Sopenharmony_ci<a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>.</li>
5811cb0ef41Sopenharmony_ci</ul>
5821cb0ef41Sopenharmony_ci</li>
5831cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
5841cb0ef41Sopenharmony_ci<ul>
5851cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
5861cb0ef41Sopenharmony_ci<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A string representation of an IPv4 or IPv6 address.</li>
5871cb0ef41Sopenharmony_ci<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <code>4</code> or <code>6</code>, denoting the family of <code>address</code>, or <code>0</code> if
5881cb0ef41Sopenharmony_cithe address is not an IPv4 or IPv6 address. <code>0</code> is a likely indicator of a
5891cb0ef41Sopenharmony_cibug in the name resolution service used by the operating system.</li>
5901cb0ef41Sopenharmony_ci</ul>
5911cb0ef41Sopenharmony_ci</li>
5921cb0ef41Sopenharmony_ci</ul>
5931cb0ef41Sopenharmony_ci<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or
5941cb0ef41Sopenharmony_ciAAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
5951cb0ef41Sopenharmony_ciinteger, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is <code>0</code> or not provided, then
5961cb0ef41Sopenharmony_ciIPv4 and IPv6 addresses are both returned if found.</p>
5971cb0ef41Sopenharmony_ci<p>With the <code>all</code> option set to <code>true</code>, the arguments for <code>callback</code> change to
5981cb0ef41Sopenharmony_ci<code>(err, addresses)</code>, with <code>addresses</code> being an array of objects with the
5991cb0ef41Sopenharmony_ciproperties <code>address</code> and <code>family</code>.</p>
6001cb0ef41Sopenharmony_ci<p>On error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code> is the error code.
6011cb0ef41Sopenharmony_ciKeep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when
6021cb0ef41Sopenharmony_cithe host name does not exist but also when the lookup fails in other ways
6031cb0ef41Sopenharmony_cisuch as no available file descriptors.</p>
6041cb0ef41Sopenharmony_ci<p><code>dns.lookup()</code> does not necessarily have anything to do with the DNS protocol.
6051cb0ef41Sopenharmony_ciThe implementation uses an operating system facility that can associate names
6061cb0ef41Sopenharmony_ciwith addresses and vice versa. This implementation can have subtle but
6071cb0ef41Sopenharmony_ciimportant consequences on the behavior of any Node.js program. Please take some
6081cb0ef41Sopenharmony_citime to consult the <a href="#implementation-considerations">Implementation considerations section</a> before using
6091cb0ef41Sopenharmony_ci<code>dns.lookup()</code>.</p>
6101cb0ef41Sopenharmony_ci<p>Example usage:</p>
6111cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>);
6121cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> options = {
6131cb0ef41Sopenharmony_ci  <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>,
6141cb0ef41Sopenharmony_ci  <span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<span class="hljs-property">V4MAPPED</span>,
6151cb0ef41Sopenharmony_ci};
6161cb0ef41Sopenharmony_cidns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options, <span class="hljs-function">(<span class="hljs-params">err, address, family</span>) =></span>
6171cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'address: %j family: IPv%s'</span>, address, family));
6181cb0ef41Sopenharmony_ci<span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span>
6191cb0ef41Sopenharmony_ci
6201cb0ef41Sopenharmony_ci<span class="hljs-comment">// When options.all is true, the result will be an Array.</span>
6211cb0ef41Sopenharmony_cioptions.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>;
6221cb0ef41Sopenharmony_cidns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options, <span class="hljs-function">(<span class="hljs-params">err, addresses</span>) =></span>
6231cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'addresses: %j'</span>, addresses));
6241cb0ef41Sopenharmony_ci<span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]</span></code> <button class="copy-button">copy</button></pre>
6251cb0ef41Sopenharmony_ci<p>If this method is invoked as its <a href="util.html#utilpromisifyoriginal"><code>util.promisify()</code></a>ed version, and <code>all</code>
6261cb0ef41Sopenharmony_ciis not set to <code>true</code>, it returns a <code>Promise</code> for an <code>Object</code> with <code>address</code> and
6271cb0ef41Sopenharmony_ci<code>family</code> properties.</p>
6281cb0ef41Sopenharmony_ci<h4>Supported getaddrinfo flags<span><a class="mark" href="#supported-getaddrinfo-flags" id="supported-getaddrinfo-flags">#</a></span><a aria-hidden="true" class="legacy" id="dns_supported_getaddrinfo_flags"></a></h4>
6291cb0ef41Sopenharmony_ci<div class="api_metadata">
6301cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
6311cb0ef41Sopenharmony_ci<table>
6321cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
6331cb0ef41Sopenharmony_ci<tr><td>v13.13.0, v12.17.0</td>
6341cb0ef41Sopenharmony_ci<td><p>Added support for the <code>dns.ALL</code> flag.</p></td></tr>
6351cb0ef41Sopenharmony_ci</tbody></table>
6361cb0ef41Sopenharmony_ci</details>
6371cb0ef41Sopenharmony_ci</div>
6381cb0ef41Sopenharmony_ci<p>The following flags can be passed as hints to <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>.</p>
6391cb0ef41Sopenharmony_ci<ul>
6401cb0ef41Sopenharmony_ci<li><code>dns.ADDRCONFIG</code>: Limits returned address types to the types of non-loopback
6411cb0ef41Sopenharmony_ciaddresses configured on the system. For example, IPv4 addresses are only
6421cb0ef41Sopenharmony_cireturned if the current system has at least one IPv4 address configured.</li>
6431cb0ef41Sopenharmony_ci<li><code>dns.V4MAPPED</code>: If the IPv6 family was specified, but no IPv6 addresses were
6441cb0ef41Sopenharmony_cifound, then return IPv4 mapped IPv6 addresses. It is not supported
6451cb0ef41Sopenharmony_cion some operating systems (e.g. FreeBSD 10.1).</li>
6461cb0ef41Sopenharmony_ci<li><code>dns.ALL</code>: If <code>dns.V4MAPPED</code> is specified, return resolved IPv6 addresses as
6471cb0ef41Sopenharmony_ciwell as IPv4 mapped IPv6 addresses.</li>
6481cb0ef41Sopenharmony_ci</ul>
6491cb0ef41Sopenharmony_ci</section><section><h3><code>dns.lookupService(address, port, callback)</code><span><a class="mark" href="#dnslookupserviceaddress-port-callback" id="dnslookupserviceaddress-port-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_lookupservice_address_port_callback"></a></h3>
6501cb0ef41Sopenharmony_ci<div class="api_metadata">
6511cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
6521cb0ef41Sopenharmony_ci<table>
6531cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
6541cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
6551cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
6561cb0ef41Sopenharmony_ci<tr><td>v0.11.14</td>
6571cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.14</span></p></td></tr>
6581cb0ef41Sopenharmony_ci</tbody></table>
6591cb0ef41Sopenharmony_ci</details>
6601cb0ef41Sopenharmony_ci</div>
6611cb0ef41Sopenharmony_ci<ul>
6621cb0ef41Sopenharmony_ci<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
6631cb0ef41Sopenharmony_ci<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
6641cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
6651cb0ef41Sopenharmony_ci<ul>
6661cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
6671cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> e.g. <code>example.com</code></li>
6681cb0ef41Sopenharmony_ci<li><code>service</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> e.g. <code>http</code></li>
6691cb0ef41Sopenharmony_ci</ul>
6701cb0ef41Sopenharmony_ci</li>
6711cb0ef41Sopenharmony_ci</ul>
6721cb0ef41Sopenharmony_ci<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
6731cb0ef41Sopenharmony_cithe operating system's underlying <code>getnameinfo</code> implementation.</p>
6741cb0ef41Sopenharmony_ci<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
6751cb0ef41Sopenharmony_ciThe <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>
6761cb0ef41Sopenharmony_ciwill be thrown.</p>
6771cb0ef41Sopenharmony_ci<p>On an error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code> is the error code.</p>
6781cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>);
6791cb0ef41Sopenharmony_cidns.<span class="hljs-title function_">lookupService</span>(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-number">22</span>, <span class="hljs-function">(<span class="hljs-params">err, hostname, service</span>) =></span> {
6801cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(hostname, service);
6811cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Prints: localhost ssh</span>
6821cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
6831cb0ef41Sopenharmony_ci<p>If this method is invoked as its <a href="util.html#utilpromisifyoriginal"><code>util.promisify()</code></a>ed version, it returns a
6841cb0ef41Sopenharmony_ci<code>Promise</code> for an <code>Object</code> with <code>hostname</code> and <code>service</code> properties.</p>
6851cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolve(hostname[, rrtype], callback)</code><span><a class="mark" href="#dnsresolvehostname-rrtype-callback" id="dnsresolvehostname-rrtype-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolve_hostname_rrtype_callback"></a></h3>
6861cb0ef41Sopenharmony_ci<div class="api_metadata">
6871cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
6881cb0ef41Sopenharmony_ci<table>
6891cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
6901cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
6911cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
6921cb0ef41Sopenharmony_ci<tr><td>v0.1.27</td>
6931cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.27</span></p></td></tr>
6941cb0ef41Sopenharmony_ci</tbody></table>
6951cb0ef41Sopenharmony_ci</details>
6961cb0ef41Sopenharmony_ci</div>
6971cb0ef41Sopenharmony_ci<ul>
6981cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
6991cb0ef41Sopenharmony_ci<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Resource record type. <strong>Default:</strong> <code>'A'</code>.</li>
7001cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
7011cb0ef41Sopenharmony_ci<ul>
7021cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
7031cb0ef41Sopenharmony_ci<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
7041cb0ef41Sopenharmony_ci</ul>
7051cb0ef41Sopenharmony_ci</li>
7061cb0ef41Sopenharmony_ci</ul>
7071cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array
7081cb0ef41Sopenharmony_ciof the resource records. The <code>callback</code> function has arguments
7091cb0ef41Sopenharmony_ci<code>(err, records)</code>. When successful, <code>records</code> will be an array of resource
7101cb0ef41Sopenharmony_cirecords. The type and structure of individual results varies based on <code>rrtype</code>:</p>
7111cb0ef41Sopenharmony_ci
7121cb0ef41Sopenharmony_ci
7131cb0ef41Sopenharmony_ci
7141cb0ef41Sopenharmony_ci
7151cb0ef41Sopenharmony_ci
7161cb0ef41Sopenharmony_ci
7171cb0ef41Sopenharmony_ci
7181cb0ef41Sopenharmony_ci
7191cb0ef41Sopenharmony_ci
7201cb0ef41Sopenharmony_ci
7211cb0ef41Sopenharmony_ci
7221cb0ef41Sopenharmony_ci
7231cb0ef41Sopenharmony_ci
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ci
7261cb0ef41Sopenharmony_ci
7271cb0ef41Sopenharmony_ci
7281cb0ef41Sopenharmony_ci
7291cb0ef41Sopenharmony_ci
7301cb0ef41Sopenharmony_ci
7311cb0ef41Sopenharmony_ci
7321cb0ef41Sopenharmony_ci
7331cb0ef41Sopenharmony_ci
7341cb0ef41Sopenharmony_ci
7351cb0ef41Sopenharmony_ci
7361cb0ef41Sopenharmony_ci
7371cb0ef41Sopenharmony_ci
7381cb0ef41Sopenharmony_ci
7391cb0ef41Sopenharmony_ci
7401cb0ef41Sopenharmony_ci
7411cb0ef41Sopenharmony_ci
7421cb0ef41Sopenharmony_ci
7431cb0ef41Sopenharmony_ci
7441cb0ef41Sopenharmony_ci
7451cb0ef41Sopenharmony_ci
7461cb0ef41Sopenharmony_ci
7471cb0ef41Sopenharmony_ci
7481cb0ef41Sopenharmony_ci
7491cb0ef41Sopenharmony_ci
7501cb0ef41Sopenharmony_ci
7511cb0ef41Sopenharmony_ci
7521cb0ef41Sopenharmony_ci
7531cb0ef41Sopenharmony_ci
7541cb0ef41Sopenharmony_ci
7551cb0ef41Sopenharmony_ci
7561cb0ef41Sopenharmony_ci
7571cb0ef41Sopenharmony_ci
7581cb0ef41Sopenharmony_ci
7591cb0ef41Sopenharmony_ci
7601cb0ef41Sopenharmony_ci
7611cb0ef41Sopenharmony_ci
7621cb0ef41Sopenharmony_ci
7631cb0ef41Sopenharmony_ci
7641cb0ef41Sopenharmony_ci
7651cb0ef41Sopenharmony_ci
7661cb0ef41Sopenharmony_ci
7671cb0ef41Sopenharmony_ci
7681cb0ef41Sopenharmony_ci
7691cb0ef41Sopenharmony_ci
7701cb0ef41Sopenharmony_ci
7711cb0ef41Sopenharmony_ci
7721cb0ef41Sopenharmony_ci
7731cb0ef41Sopenharmony_ci
7741cb0ef41Sopenharmony_ci
7751cb0ef41Sopenharmony_ci
7761cb0ef41Sopenharmony_ci
7771cb0ef41Sopenharmony_ci
7781cb0ef41Sopenharmony_ci
7791cb0ef41Sopenharmony_ci
7801cb0ef41Sopenharmony_ci
7811cb0ef41Sopenharmony_ci
7821cb0ef41Sopenharmony_ci
7831cb0ef41Sopenharmony_ci
7841cb0ef41Sopenharmony_ci
7851cb0ef41Sopenharmony_ci
7861cb0ef41Sopenharmony_ci
7871cb0ef41Sopenharmony_ci
7881cb0ef41Sopenharmony_ci
7891cb0ef41Sopenharmony_ci
7901cb0ef41Sopenharmony_ci
7911cb0ef41Sopenharmony_ci
7921cb0ef41Sopenharmony_ci
7931cb0ef41Sopenharmony_ci
7941cb0ef41Sopenharmony_ci<table><thead><tr><th><code>rrtype</code></th><th><code>records</code> contains</th><th>Result type</th><th>Shorthand method</th></tr></thead><tbody><tr><td><code>'A'</code></td><td>IPv4 addresses (default)</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4()</code></a></td></tr><tr><td><code>'AAAA'</code></td><td>IPv6 addresses</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6()</code></a></td></tr><tr><td><code>'ANY'</code></td><td>any records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny()</code></a></td></tr><tr><td><code>'CAA'</code></td><td>CA authorization records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa()</code></a></td></tr><tr><td><code>'CNAME'</code></td><td>canonical name records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname()</code></a></td></tr><tr><td><code>'MX'</code></td><td>mail exchange records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>name authority pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td>name server records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnsresolvenshostname-callback"><code>dns.resolveNs()</code></a></td></tr><tr><td><code>'PTR'</code></td><td>pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnsresolveptrhostname-callback"><code>dns.resolvePtr()</code></a></td></tr><tr><td><code>'SOA'</code></td><td>start of authority records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>service records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><td>text records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></td><td><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt()</code></a></td></tr></tbody></table>
7951cb0ef41Sopenharmony_ci<p>On error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code> is one of the
7961cb0ef41Sopenharmony_ci<a href="#error-codes">DNS error codes</a>.</p>
7971cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolve4(hostname[, options], callback)</code><span><a class="mark" href="#dnsresolve4hostname-options-callback" id="dnsresolve4hostname-options-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolve4_hostname_options_callback"></a></h3>
7981cb0ef41Sopenharmony_ci<div class="api_metadata">
7991cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
8001cb0ef41Sopenharmony_ci<table>
8011cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
8021cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
8031cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
8041cb0ef41Sopenharmony_ci<tr><td>v7.2.0</td>
8051cb0ef41Sopenharmony_ci<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p></td></tr>
8061cb0ef41Sopenharmony_ci<tr><td>v0.1.16</td>
8071cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.16</span></p></td></tr>
8081cb0ef41Sopenharmony_ci</tbody></table>
8091cb0ef41Sopenharmony_ci</details>
8101cb0ef41Sopenharmony_ci</div>
8111cb0ef41Sopenharmony_ci<ul>
8121cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
8131cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
8141cb0ef41Sopenharmony_ci<ul>
8151cb0ef41Sopenharmony_ci<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieves the Time-To-Live value (TTL) of each record.
8161cb0ef41Sopenharmony_ciWhen <code>true</code>, the callback receives an array of
8171cb0ef41Sopenharmony_ci<code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings,
8181cb0ef41Sopenharmony_ciwith the TTL expressed in seconds.</li>
8191cb0ef41Sopenharmony_ci</ul>
8201cb0ef41Sopenharmony_ci</li>
8211cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
8221cb0ef41Sopenharmony_ci<ul>
8231cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
8241cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
8251cb0ef41Sopenharmony_ci</ul>
8261cb0ef41Sopenharmony_ci</li>
8271cb0ef41Sopenharmony_ci</ul>
8281cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve a IPv4 addresses (<code>A</code> records) for the
8291cb0ef41Sopenharmony_ci<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function
8301cb0ef41Sopenharmony_ciwill contain an array of IPv4 addresses (e.g.
8311cb0ef41Sopenharmony_ci<code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>
8321cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolve6(hostname[, options], callback)</code><span><a class="mark" href="#dnsresolve6hostname-options-callback" id="dnsresolve6hostname-options-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolve6_hostname_options_callback"></a></h3>
8331cb0ef41Sopenharmony_ci<div class="api_metadata">
8341cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
8351cb0ef41Sopenharmony_ci<table>
8361cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
8371cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
8381cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
8391cb0ef41Sopenharmony_ci<tr><td>v7.2.0</td>
8401cb0ef41Sopenharmony_ci<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p></td></tr>
8411cb0ef41Sopenharmony_ci<tr><td>v0.1.16</td>
8421cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.16</span></p></td></tr>
8431cb0ef41Sopenharmony_ci</tbody></table>
8441cb0ef41Sopenharmony_ci</details>
8451cb0ef41Sopenharmony_ci</div>
8461cb0ef41Sopenharmony_ci<ul>
8471cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
8481cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
8491cb0ef41Sopenharmony_ci<ul>
8501cb0ef41Sopenharmony_ci<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieve the Time-To-Live value (TTL) of each record.
8511cb0ef41Sopenharmony_ciWhen <code>true</code>, the callback receives an array of
8521cb0ef41Sopenharmony_ci<code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of
8531cb0ef41Sopenharmony_cistrings, with the TTL expressed in seconds.</li>
8541cb0ef41Sopenharmony_ci</ul>
8551cb0ef41Sopenharmony_ci</li>
8561cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
8571cb0ef41Sopenharmony_ci<ul>
8581cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
8591cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
8601cb0ef41Sopenharmony_ci</ul>
8611cb0ef41Sopenharmony_ci</li>
8621cb0ef41Sopenharmony_ci</ul>
8631cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the
8641cb0ef41Sopenharmony_ci<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function
8651cb0ef41Sopenharmony_ciwill contain an array of IPv6 addresses.</p>
8661cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveAny(hostname, callback)</code><span><a class="mark" href="#dnsresolveanyhostname-callback" id="dnsresolveanyhostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolveany_hostname_callback"></a></h3>
8671cb0ef41Sopenharmony_ci<div class="api_metadata">
8681cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
8691cb0ef41Sopenharmony_ci<table>
8701cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
8711cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
8721cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
8731cb0ef41Sopenharmony_ci</tbody></table>
8741cb0ef41Sopenharmony_ci</details>
8751cb0ef41Sopenharmony_ci</div>
8761cb0ef41Sopenharmony_ci<ul>
8771cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
8781cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
8791cb0ef41Sopenharmony_ci<ul>
8801cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
8811cb0ef41Sopenharmony_ci<li><code>ret</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
8821cb0ef41Sopenharmony_ci</ul>
8831cb0ef41Sopenharmony_ci</li>
8841cb0ef41Sopenharmony_ci</ul>
8851cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).
8861cb0ef41Sopenharmony_ciThe <code>ret</code> argument passed to the <code>callback</code> function will be an array containing
8871cb0ef41Sopenharmony_civarious types of records. Each object has a property <code>type</code> that indicates the
8881cb0ef41Sopenharmony_citype of the current record. And depending on the <code>type</code>, additional properties
8891cb0ef41Sopenharmony_ciwill be present on the object:</p>
8901cb0ef41Sopenharmony_ci
8911cb0ef41Sopenharmony_ci
8921cb0ef41Sopenharmony_ci
8931cb0ef41Sopenharmony_ci
8941cb0ef41Sopenharmony_ci
8951cb0ef41Sopenharmony_ci
8961cb0ef41Sopenharmony_ci
8971cb0ef41Sopenharmony_ci
8981cb0ef41Sopenharmony_ci
8991cb0ef41Sopenharmony_ci
9001cb0ef41Sopenharmony_ci
9011cb0ef41Sopenharmony_ci
9021cb0ef41Sopenharmony_ci
9031cb0ef41Sopenharmony_ci
9041cb0ef41Sopenharmony_ci
9051cb0ef41Sopenharmony_ci
9061cb0ef41Sopenharmony_ci
9071cb0ef41Sopenharmony_ci
9081cb0ef41Sopenharmony_ci
9091cb0ef41Sopenharmony_ci
9101cb0ef41Sopenharmony_ci
9111cb0ef41Sopenharmony_ci
9121cb0ef41Sopenharmony_ci
9131cb0ef41Sopenharmony_ci
9141cb0ef41Sopenharmony_ci
9151cb0ef41Sopenharmony_ci
9161cb0ef41Sopenharmony_ci
9171cb0ef41Sopenharmony_ci
9181cb0ef41Sopenharmony_ci
9191cb0ef41Sopenharmony_ci
9201cb0ef41Sopenharmony_ci
9211cb0ef41Sopenharmony_ci
9221cb0ef41Sopenharmony_ci
9231cb0ef41Sopenharmony_ci
9241cb0ef41Sopenharmony_ci
9251cb0ef41Sopenharmony_ci
9261cb0ef41Sopenharmony_ci
9271cb0ef41Sopenharmony_ci
9281cb0ef41Sopenharmony_ci
9291cb0ef41Sopenharmony_ci
9301cb0ef41Sopenharmony_ci
9311cb0ef41Sopenharmony_ci
9321cb0ef41Sopenharmony_ci
9331cb0ef41Sopenharmony_ci
9341cb0ef41Sopenharmony_ci
9351cb0ef41Sopenharmony_ci
9361cb0ef41Sopenharmony_ci
9371cb0ef41Sopenharmony_ci
9381cb0ef41Sopenharmony_ci
9391cb0ef41Sopenharmony_ci<table><thead><tr><th>Type</th><th>Properties</th></tr></thead><tbody><tr><td><code>'A'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'AAAA'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'CNAME'</code></td><td><code>value</code></td></tr><tr><td><code>'MX'</code></td><td>Refer to <a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>Refer to <a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td><code>value</code></td></tr><tr><td><code>'PTR'</code></td><td><code>value</code></td></tr><tr><td><code>'SOA'</code></td><td>Refer to <a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>Refer to <a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><td>This type of record contains an array property called <code>entries</code> which refers to <a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt()</code></a>, e.g. <code>{ entries: ['...'], type: 'TXT' }</code></td></tr></tbody></table>
9401cb0ef41Sopenharmony_ci<p>Here is an example of the <code>ret</code> object passed to the callback:</p>
9411cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
9421cb0ef41Sopenharmony_ci<pre><code class="language-js">[ { <span class="hljs-attr">type</span>: <span class="hljs-string">'A'</span>, <span class="hljs-attr">address</span>: <span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-attr">ttl</span>: <span class="hljs-number">299</span> },
9431cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'CNAME'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'example.com'</span> },
9441cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'MX'</span>, <span class="hljs-attr">exchange</span>: <span class="hljs-string">'alt4.aspmx.l.example.com'</span>, <span class="hljs-attr">priority</span>: <span class="hljs-number">50</span> },
9451cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'NS'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'ns1.example.com'</span> },
9461cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'TXT'</span>, <span class="hljs-attr">entries</span>: [ <span class="hljs-string">'v=spf1 include:_spf.example.com ~all'</span> ] },
9471cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>,
9481cb0ef41Sopenharmony_ci    <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>,
9491cb0ef41Sopenharmony_ci    <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>,
9501cb0ef41Sopenharmony_ci    <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>,
9511cb0ef41Sopenharmony_ci    <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>,
9521cb0ef41Sopenharmony_ci    <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>,
9531cb0ef41Sopenharmony_ci    <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>,
9541cb0ef41Sopenharmony_ci    <span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code> <button class="copy-button">copy</button></pre>
9551cb0ef41Sopenharmony_ci<p>DNS server operators may choose not to respond to <code>ANY</code>
9561cb0ef41Sopenharmony_ciqueries. It may be better to call individual methods like <a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4()</code></a>,
9571cb0ef41Sopenharmony_ci<a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx()</code></a>, and so on. For more details, see <a href="https://tools.ietf.org/html/rfc8482">RFC 8482</a>.</p>
9581cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveCname(hostname, callback)</code><span><a class="mark" href="#dnsresolvecnamehostname-callback" id="dnsresolvecnamehostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvecname_hostname_callback"></a></h3>
9591cb0ef41Sopenharmony_ci<div class="api_metadata">
9601cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9611cb0ef41Sopenharmony_ci<table>
9621cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9631cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
9641cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
9651cb0ef41Sopenharmony_ci<tr><td>v0.3.2</td>
9661cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.3.2</span></p></td></tr>
9671cb0ef41Sopenharmony_ci</tbody></table>
9681cb0ef41Sopenharmony_ci</details>
9691cb0ef41Sopenharmony_ci</div>
9701cb0ef41Sopenharmony_ci<ul>
9711cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
9721cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
9731cb0ef41Sopenharmony_ci<ul>
9741cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
9751cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
9761cb0ef41Sopenharmony_ci</ul>
9771cb0ef41Sopenharmony_ci</li>
9781cb0ef41Sopenharmony_ci</ul>
9791cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. The
9801cb0ef41Sopenharmony_ci<code>addresses</code> argument passed to the <code>callback</code> function
9811cb0ef41Sopenharmony_ciwill contain an array of canonical name records available for the <code>hostname</code>
9821cb0ef41Sopenharmony_ci(e.g. <code>['bar.example.com']</code>).</p>
9831cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveCaa(hostname, callback)</code><span><a class="mark" href="#dnsresolvecaahostname-callback" id="dnsresolvecaahostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvecaa_hostname_callback"></a></h3>
9841cb0ef41Sopenharmony_ci<div class="api_metadata">
9851cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9861cb0ef41Sopenharmony_ci<table>
9871cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9881cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
9891cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
9901cb0ef41Sopenharmony_ci<tr><td>v15.0.0, v14.17.0</td>
9911cb0ef41Sopenharmony_ci<td><p><span>Added in: v15.0.0, v14.17.0</span></p></td></tr>
9921cb0ef41Sopenharmony_ci</tbody></table>
9931cb0ef41Sopenharmony_ci</details>
9941cb0ef41Sopenharmony_ci</div>
9951cb0ef41Sopenharmony_ci<ul>
9961cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
9971cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
9981cb0ef41Sopenharmony_ci<ul>
9991cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
10001cb0ef41Sopenharmony_ci<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
10011cb0ef41Sopenharmony_ci</ul>
10021cb0ef41Sopenharmony_ci</li>
10031cb0ef41Sopenharmony_ci</ul>
10041cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. The
10051cb0ef41Sopenharmony_ci<code>addresses</code> argument passed to the <code>callback</code> function
10061cb0ef41Sopenharmony_ciwill contain an array of certification authority authorization records
10071cb0ef41Sopenharmony_ciavailable for the <code>hostname</code> (e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]</code>).</p>
10081cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveMx(hostname, callback)</code><span><a class="mark" href="#dnsresolvemxhostname-callback" id="dnsresolvemxhostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvemx_hostname_callback"></a></h3>
10091cb0ef41Sopenharmony_ci<div class="api_metadata">
10101cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
10111cb0ef41Sopenharmony_ci<table>
10121cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
10131cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
10141cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
10151cb0ef41Sopenharmony_ci<tr><td>v0.1.27</td>
10161cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.27</span></p></td></tr>
10171cb0ef41Sopenharmony_ci</tbody></table>
10181cb0ef41Sopenharmony_ci</details>
10191cb0ef41Sopenharmony_ci</div>
10201cb0ef41Sopenharmony_ci<ul>
10211cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
10221cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
10231cb0ef41Sopenharmony_ci<ul>
10241cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
10251cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
10261cb0ef41Sopenharmony_ci</ul>
10271cb0ef41Sopenharmony_ci</li>
10281cb0ef41Sopenharmony_ci</ul>
10291cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
10301cb0ef41Sopenharmony_ci<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
10311cb0ef41Sopenharmony_cicontain an array of objects containing both a <code>priority</code> and <code>exchange</code>
10321cb0ef41Sopenharmony_ciproperty (e.g. <code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>
10331cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveNaptr(hostname, callback)</code><span><a class="mark" href="#dnsresolvenaptrhostname-callback" id="dnsresolvenaptrhostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvenaptr_hostname_callback"></a></h3>
10341cb0ef41Sopenharmony_ci<div class="api_metadata">
10351cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
10361cb0ef41Sopenharmony_ci<table>
10371cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
10381cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
10391cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
10401cb0ef41Sopenharmony_ci<tr><td>v0.9.12</td>
10411cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.9.12</span></p></td></tr>
10421cb0ef41Sopenharmony_ci</tbody></table>
10431cb0ef41Sopenharmony_ci</details>
10441cb0ef41Sopenharmony_ci</div>
10451cb0ef41Sopenharmony_ci<ul>
10461cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
10471cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
10481cb0ef41Sopenharmony_ci<ul>
10491cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
10501cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
10511cb0ef41Sopenharmony_ci</ul>
10521cb0ef41Sopenharmony_ci</li>
10531cb0ef41Sopenharmony_ci</ul>
10541cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve regular expression-based records (<code>NAPTR</code>
10551cb0ef41Sopenharmony_cirecords) for the <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code>
10561cb0ef41Sopenharmony_cifunction will contain an array of objects with the following properties:</p>
10571cb0ef41Sopenharmony_ci<ul>
10581cb0ef41Sopenharmony_ci<li><code>flags</code></li>
10591cb0ef41Sopenharmony_ci<li><code>service</code></li>
10601cb0ef41Sopenharmony_ci<li><code>regexp</code></li>
10611cb0ef41Sopenharmony_ci<li><code>replacement</code></li>
10621cb0ef41Sopenharmony_ci<li><code>order</code></li>
10631cb0ef41Sopenharmony_ci<li><code>preference</code></li>
10641cb0ef41Sopenharmony_ci</ul>
10651cb0ef41Sopenharmony_ci<!-- eslint-skip -->
10661cb0ef41Sopenharmony_ci<pre><code class="language-js">{
10671cb0ef41Sopenharmony_ci  <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>,
10681cb0ef41Sopenharmony_ci  <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>,
10691cb0ef41Sopenharmony_ci  <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>,
10701cb0ef41Sopenharmony_ci  <span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</span>,
10711cb0ef41Sopenharmony_ci  <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>,
10721cb0ef41Sopenharmony_ci  <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span>
10731cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
10741cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveNs(hostname, callback)</code><span><a class="mark" href="#dnsresolvenshostname-callback" id="dnsresolvenshostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvens_hostname_callback"></a></h3>
10751cb0ef41Sopenharmony_ci<div class="api_metadata">
10761cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
10771cb0ef41Sopenharmony_ci<table>
10781cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
10791cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
10801cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
10811cb0ef41Sopenharmony_ci<tr><td>v0.1.90</td>
10821cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.90</span></p></td></tr>
10831cb0ef41Sopenharmony_ci</tbody></table>
10841cb0ef41Sopenharmony_ci</details>
10851cb0ef41Sopenharmony_ci</div>
10861cb0ef41Sopenharmony_ci<ul>
10871cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
10881cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
10891cb0ef41Sopenharmony_ci<ul>
10901cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
10911cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
10921cb0ef41Sopenharmony_ci</ul>
10931cb0ef41Sopenharmony_ci</li>
10941cb0ef41Sopenharmony_ci</ul>
10951cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
10961cb0ef41Sopenharmony_ci<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
10971cb0ef41Sopenharmony_cicontain an array of name server records available for <code>hostname</code>
10981cb0ef41Sopenharmony_ci(e.g. <code>['ns1.example.com', 'ns2.example.com']</code>).</p>
10991cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolvePtr(hostname, callback)</code><span><a class="mark" href="#dnsresolveptrhostname-callback" id="dnsresolveptrhostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolveptr_hostname_callback"></a></h3>
11001cb0ef41Sopenharmony_ci<div class="api_metadata">
11011cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
11021cb0ef41Sopenharmony_ci<table>
11031cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
11041cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
11051cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
11061cb0ef41Sopenharmony_ci<tr><td>v6.0.0</td>
11071cb0ef41Sopenharmony_ci<td><p><span>Added in: v6.0.0</span></p></td></tr>
11081cb0ef41Sopenharmony_ci</tbody></table>
11091cb0ef41Sopenharmony_ci</details>
11101cb0ef41Sopenharmony_ci</div>
11111cb0ef41Sopenharmony_ci<ul>
11121cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
11131cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
11141cb0ef41Sopenharmony_ci<ul>
11151cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
11161cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
11171cb0ef41Sopenharmony_ci</ul>
11181cb0ef41Sopenharmony_ci</li>
11191cb0ef41Sopenharmony_ci</ul>
11201cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
11211cb0ef41Sopenharmony_ci<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
11221cb0ef41Sopenharmony_cibe an array of strings containing the reply records.</p>
11231cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveSoa(hostname, callback)</code><span><a class="mark" href="#dnsresolvesoahostname-callback" id="dnsresolvesoahostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvesoa_hostname_callback"></a></h3>
11241cb0ef41Sopenharmony_ci<div class="api_metadata">
11251cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
11261cb0ef41Sopenharmony_ci<table>
11271cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
11281cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
11291cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
11301cb0ef41Sopenharmony_ci<tr><td>v0.11.10</td>
11311cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.10</span></p></td></tr>
11321cb0ef41Sopenharmony_ci</tbody></table>
11331cb0ef41Sopenharmony_ci</details>
11341cb0ef41Sopenharmony_ci</div>
11351cb0ef41Sopenharmony_ci<ul>
11361cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
11371cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
11381cb0ef41Sopenharmony_ci<ul>
11391cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
11401cb0ef41Sopenharmony_ci<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
11411cb0ef41Sopenharmony_ci</ul>
11421cb0ef41Sopenharmony_ci</li>
11431cb0ef41Sopenharmony_ci</ul>
11441cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
11451cb0ef41Sopenharmony_cithe <code>hostname</code>. The <code>address</code> argument passed to the <code>callback</code> function will
11461cb0ef41Sopenharmony_cibe an object with the following properties:</p>
11471cb0ef41Sopenharmony_ci<ul>
11481cb0ef41Sopenharmony_ci<li><code>nsname</code></li>
11491cb0ef41Sopenharmony_ci<li><code>hostmaster</code></li>
11501cb0ef41Sopenharmony_ci<li><code>serial</code></li>
11511cb0ef41Sopenharmony_ci<li><code>refresh</code></li>
11521cb0ef41Sopenharmony_ci<li><code>retry</code></li>
11531cb0ef41Sopenharmony_ci<li><code>expire</code></li>
11541cb0ef41Sopenharmony_ci<li><code>minttl</code></li>
11551cb0ef41Sopenharmony_ci</ul>
11561cb0ef41Sopenharmony_ci<!-- eslint-skip -->
11571cb0ef41Sopenharmony_ci<pre><code class="language-js">{
11581cb0ef41Sopenharmony_ci  <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>,
11591cb0ef41Sopenharmony_ci  <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>,
11601cb0ef41Sopenharmony_ci  <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>,
11611cb0ef41Sopenharmony_ci  <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>,
11621cb0ef41Sopenharmony_ci  <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>,
11631cb0ef41Sopenharmony_ci  <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>,
11641cb0ef41Sopenharmony_ci  <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span>
11651cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
11661cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveSrv(hostname, callback)</code><span><a class="mark" href="#dnsresolvesrvhostname-callback" id="dnsresolvesrvhostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvesrv_hostname_callback"></a></h3>
11671cb0ef41Sopenharmony_ci<div class="api_metadata">
11681cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
11691cb0ef41Sopenharmony_ci<table>
11701cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
11711cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
11721cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
11731cb0ef41Sopenharmony_ci<tr><td>v0.1.27</td>
11741cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.27</span></p></td></tr>
11751cb0ef41Sopenharmony_ci</tbody></table>
11761cb0ef41Sopenharmony_ci</details>
11771cb0ef41Sopenharmony_ci</div>
11781cb0ef41Sopenharmony_ci<ul>
11791cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
11801cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
11811cb0ef41Sopenharmony_ci<ul>
11821cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
11831cb0ef41Sopenharmony_ci<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
11841cb0ef41Sopenharmony_ci</ul>
11851cb0ef41Sopenharmony_ci</li>
11861cb0ef41Sopenharmony_ci</ul>
11871cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
11881cb0ef41Sopenharmony_ci<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
11891cb0ef41Sopenharmony_cibe an array of objects with the following properties:</p>
11901cb0ef41Sopenharmony_ci<ul>
11911cb0ef41Sopenharmony_ci<li><code>priority</code></li>
11921cb0ef41Sopenharmony_ci<li><code>weight</code></li>
11931cb0ef41Sopenharmony_ci<li><code>port</code></li>
11941cb0ef41Sopenharmony_ci<li><code>name</code></li>
11951cb0ef41Sopenharmony_ci</ul>
11961cb0ef41Sopenharmony_ci<!-- eslint-skip -->
11971cb0ef41Sopenharmony_ci<pre><code class="language-js">{
11981cb0ef41Sopenharmony_ci  <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>,
11991cb0ef41Sopenharmony_ci  <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>,
12001cb0ef41Sopenharmony_ci  <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>,
12011cb0ef41Sopenharmony_ci  <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span>
12021cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
12031cb0ef41Sopenharmony_ci</section><section><h3><code>dns.resolveTxt(hostname, callback)</code><span><a class="mark" href="#dnsresolvetxthostname-callback" id="dnsresolvetxthostname-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolvetxt_hostname_callback"></a></h3>
12041cb0ef41Sopenharmony_ci<div class="api_metadata">
12051cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12061cb0ef41Sopenharmony_ci<table>
12071cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12081cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
12091cb0ef41Sopenharmony_ci<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
12101cb0ef41Sopenharmony_ci<tr><td>v0.1.27</td>
12111cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.27</span></p></td></tr>
12121cb0ef41Sopenharmony_ci</tbody></table>
12131cb0ef41Sopenharmony_ci</details>
12141cb0ef41Sopenharmony_ci</div>
12151cb0ef41Sopenharmony_ci<!--lint disable no-undefined-references list-item-bullet-indent-->
12161cb0ef41Sopenharmony_ci<ul>
12171cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12181cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
12191cb0ef41Sopenharmony_ci<ul>
12201cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
12211cb0ef41Sopenharmony_ci<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[][]></a></li>
12221cb0ef41Sopenharmony_ci</ul>
12231cb0ef41Sopenharmony_ci</li>
12241cb0ef41Sopenharmony_ci</ul>
12251cb0ef41Sopenharmony_ci<!--lint enable no-undefined-references list-item-bullet-indent-->
12261cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
12271cb0ef41Sopenharmony_ci<code>hostname</code>. The <code>records</code> argument passed to the <code>callback</code> function is a
12281cb0ef41Sopenharmony_citwo-dimensional array of the text records available for <code>hostname</code> (e.g.
12291cb0ef41Sopenharmony_ci<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of
12301cb0ef41Sopenharmony_cione record. Depending on the use case, these could be either joined together or
12311cb0ef41Sopenharmony_citreated separately.</p>
12321cb0ef41Sopenharmony_ci</section><section><h3><code>dns.reverse(ip, callback)</code><span><a class="mark" href="#dnsreverseip-callback" id="dnsreverseip-callback">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_reverse_ip_callback"></a></h3>
12331cb0ef41Sopenharmony_ci<div class="api_metadata">
12341cb0ef41Sopenharmony_ci<span>Added in: v0.1.16</span>
12351cb0ef41Sopenharmony_ci</div>
12361cb0ef41Sopenharmony_ci<ul>
12371cb0ef41Sopenharmony_ci<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12381cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
12391cb0ef41Sopenharmony_ci<ul>
12401cb0ef41Sopenharmony_ci<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
12411cb0ef41Sopenharmony_ci<li><code>hostnames</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
12421cb0ef41Sopenharmony_ci</ul>
12431cb0ef41Sopenharmony_ci</li>
12441cb0ef41Sopenharmony_ci</ul>
12451cb0ef41Sopenharmony_ci<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
12461cb0ef41Sopenharmony_ciarray of host names.</p>
12471cb0ef41Sopenharmony_ci<p>On error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code> is
12481cb0ef41Sopenharmony_cione of the <a href="#error-codes">DNS error codes</a>.</p>
12491cb0ef41Sopenharmony_ci</section><section><h3><code>dns.setDefaultResultOrder(order)</code><span><a class="mark" href="#dnssetdefaultresultorderorder" id="dnssetdefaultresultorderorder">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_setdefaultresultorder_order"></a></h3>
12501cb0ef41Sopenharmony_ci<div class="api_metadata">
12511cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12521cb0ef41Sopenharmony_ci<table>
12531cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12541cb0ef41Sopenharmony_ci<tr><td>v17.0.0</td>
12551cb0ef41Sopenharmony_ci<td><p>Changed default value to <code>verbatim</code>.</p></td></tr>
12561cb0ef41Sopenharmony_ci<tr><td>v16.4.0, v14.18.0</td>
12571cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.4.0, v14.18.0</span></p></td></tr>
12581cb0ef41Sopenharmony_ci</tbody></table>
12591cb0ef41Sopenharmony_ci</details>
12601cb0ef41Sopenharmony_ci</div>
12611cb0ef41Sopenharmony_ci<ul>
12621cb0ef41Sopenharmony_ci<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> must be <code>'ipv4first'</code> or <code>'verbatim'</code>.</li>
12631cb0ef41Sopenharmony_ci</ul>
12641cb0ef41Sopenharmony_ci<p>Set the default value of <code>verbatim</code> in <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and
12651cb0ef41Sopenharmony_ci<a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
12661cb0ef41Sopenharmony_ci<ul>
12671cb0ef41Sopenharmony_ci<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
12681cb0ef41Sopenharmony_ci<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
12691cb0ef41Sopenharmony_ci</ul>
12701cb0ef41Sopenharmony_ci<p>The default is <code>verbatim</code> and <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> have higher
12711cb0ef41Sopenharmony_cipriority than <a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>. When using <a href="worker_threads.html">worker threads</a>,
12721cb0ef41Sopenharmony_ci<a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> from the main thread won't affect the default
12731cb0ef41Sopenharmony_cidns orders in workers.</p>
12741cb0ef41Sopenharmony_ci</section><section><h3><code>dns.getDefaultResultOrder()</code><span><a class="mark" href="#dnsgetdefaultresultorder" id="dnsgetdefaultresultorder">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_getdefaultresultorder"></a></h3>
12751cb0ef41Sopenharmony_ci<div class="api_metadata">
12761cb0ef41Sopenharmony_ci<span>Added in: v18.17.0</span>
12771cb0ef41Sopenharmony_ci</div>
12781cb0ef41Sopenharmony_ci<p>Get the default value for <code>verbatim</code> in <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and
12791cb0ef41Sopenharmony_ci<a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
12801cb0ef41Sopenharmony_ci<ul>
12811cb0ef41Sopenharmony_ci<li><code>ipv4first</code>: for <code>verbatim</code> defaulting to <code>false</code>.</li>
12821cb0ef41Sopenharmony_ci<li><code>verbatim</code>: for <code>verbatim</code> defaulting to <code>true</code>.</li>
12831cb0ef41Sopenharmony_ci</ul>
12841cb0ef41Sopenharmony_ci</section><section><h3><code>dns.setServers(servers)</code><span><a class="mark" href="#dnssetserversservers" id="dnssetserversservers">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_setservers_servers"></a></h3>
12851cb0ef41Sopenharmony_ci<div class="api_metadata">
12861cb0ef41Sopenharmony_ci<span>Added in: v0.11.3</span>
12871cb0ef41Sopenharmony_ci</div>
12881cb0ef41Sopenharmony_ci<ul>
12891cb0ef41Sopenharmony_ci<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li>
12901cb0ef41Sopenharmony_ci</ul>
12911cb0ef41Sopenharmony_ci<p>Sets the IP address and port of servers to be used when performing DNS
12921cb0ef41Sopenharmony_ciresolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted
12931cb0ef41Sopenharmony_ciaddresses. If the port is the IANA default DNS port (53) it can be omitted.</p>
12941cb0ef41Sopenharmony_ci<pre><code class="language-js">dns.<span class="hljs-title function_">setServers</span>([
12951cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4'</span>,
12961cb0ef41Sopenharmony_ci  <span class="hljs-string">'[2001:4860:4860::8888]'</span>,
12971cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4:1053'</span>,
12981cb0ef41Sopenharmony_ci  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
12991cb0ef41Sopenharmony_ci]);</code> <button class="copy-button">copy</button></pre>
13001cb0ef41Sopenharmony_ci<p>An error will be thrown if an invalid address is provided.</p>
13011cb0ef41Sopenharmony_ci<p>The <code>dns.setServers()</code> method must not be called while a DNS query is in
13021cb0ef41Sopenharmony_ciprogress.</p>
13031cb0ef41Sopenharmony_ci<p>The <a href="#dnssetserversservers"><code>dns.setServers()</code></a> method affects only <a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve()</code></a>,
13041cb0ef41Sopenharmony_ci<code>dns.resolve*()</code> and <a href="#dnsreverseip-callback"><code>dns.reverse()</code></a> (and specifically <em>not</em>
13051cb0ef41Sopenharmony_ci<a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>).</p>
13061cb0ef41Sopenharmony_ci<p>This method works much like
13071cb0ef41Sopenharmony_ci<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
13081cb0ef41Sopenharmony_ciThat is, if attempting to resolve with the first server provided results in a
13091cb0ef41Sopenharmony_ci<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with
13101cb0ef41Sopenharmony_cisubsequent servers provided. Fallback DNS servers will only be used if the
13111cb0ef41Sopenharmony_ciearlier ones time out or result in some other error.</p>
13121cb0ef41Sopenharmony_ci</section><section><h3>DNS promises API<span><a class="mark" href="#dns-promises-api" id="dns-promises-api">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_promises_api"></a></h3>
13131cb0ef41Sopenharmony_ci<div class="api_metadata">
13141cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13151cb0ef41Sopenharmony_ci<table>
13161cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13171cb0ef41Sopenharmony_ci<tr><td>v15.0.0</td>
13181cb0ef41Sopenharmony_ci<td><p>Exposed as <code>require('dns/promises')</code>.</p></td></tr>
13191cb0ef41Sopenharmony_ci<tr><td>v11.14.0, v10.17.0</td>
13201cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
13211cb0ef41Sopenharmony_ci<tr><td>v10.6.0</td>
13221cb0ef41Sopenharmony_ci<td><p><span>Added in: v10.6.0</span></p></td></tr>
13231cb0ef41Sopenharmony_ci</tbody></table>
13241cb0ef41Sopenharmony_ci</details>
13251cb0ef41Sopenharmony_ci</div>
13261cb0ef41Sopenharmony_ci<p>The <code>dns.promises</code> API provides an alternative set of asynchronous DNS methods
13271cb0ef41Sopenharmony_cithat return <code>Promise</code> objects rather than using callbacks. The API is accessible
13281cb0ef41Sopenharmony_civia <code>require('node:dns').promises</code> or <code>require('node:dns/promises')</code>.</p>
13291cb0ef41Sopenharmony_ci<h4>Class: <code>dnsPromises.Resolver</code><span><a class="mark" href="#class-dnspromisesresolver" id="class-dnspromisesresolver">#</a></span><a aria-hidden="true" class="legacy" id="dns_class_dnspromises_resolver"></a></h4>
13301cb0ef41Sopenharmony_ci<div class="api_metadata">
13311cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
13321cb0ef41Sopenharmony_ci</div>
13331cb0ef41Sopenharmony_ci<p>An independent resolver for DNS requests.</p>
13341cb0ef41Sopenharmony_ci<p>Creating a new resolver uses the default server settings. Setting
13351cb0ef41Sopenharmony_cithe servers used for a resolver using
13361cb0ef41Sopenharmony_ci<a href="#dnspromisessetserversservers"><code>resolver.setServers()</code></a> does not affect
13371cb0ef41Sopenharmony_ciother resolvers:</p>
13381cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">Resolver</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>).<span class="hljs-property">promises</span>;
13391cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Resolver</span>();
13401cb0ef41Sopenharmony_ciresolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'</span>]);
13411cb0ef41Sopenharmony_ci
13421cb0ef41Sopenharmony_ci<span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global settings.</span>
13431cb0ef41Sopenharmony_ciresolver.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">addresses</span>) =></span> {
13441cb0ef41Sopenharmony_ci  <span class="hljs-comment">// ...</span>
13451cb0ef41Sopenharmony_ci});
13461cb0ef41Sopenharmony_ci
13471cb0ef41Sopenharmony_ci<span class="hljs-comment">// Alternatively, the same code can be written using async-await style.</span>
13481cb0ef41Sopenharmony_ci(<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) {
13491cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> addresses = <span class="hljs-keyword">await</span> resolver.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>);
13501cb0ef41Sopenharmony_ci})();</code> <button class="copy-button">copy</button></pre>
13511cb0ef41Sopenharmony_ci<p>The following methods from the <code>dnsPromises</code> API are available:</p>
13521cb0ef41Sopenharmony_ci<ul>
13531cb0ef41Sopenharmony_ci<li><a href="#dnspromisesgetservers"><code>resolver.getServers()</code></a></li>
13541cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvehostname-rrtype"><code>resolver.resolve()</code></a></li>
13551cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolve4hostname-options"><code>resolver.resolve4()</code></a></li>
13561cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolve6hostname-options"><code>resolver.resolve6()</code></a></li>
13571cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolveanyhostname"><code>resolver.resolveAny()</code></a></li>
13581cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvecaahostname"><code>resolver.resolveCaa()</code></a></li>
13591cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvecnamehostname"><code>resolver.resolveCname()</code></a></li>
13601cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvemxhostname"><code>resolver.resolveMx()</code></a></li>
13611cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvenaptrhostname"><code>resolver.resolveNaptr()</code></a></li>
13621cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvenshostname"><code>resolver.resolveNs()</code></a></li>
13631cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolveptrhostname"><code>resolver.resolvePtr()</code></a></li>
13641cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvesoahostname"><code>resolver.resolveSoa()</code></a></li>
13651cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvesrvhostname"><code>resolver.resolveSrv()</code></a></li>
13661cb0ef41Sopenharmony_ci<li><a href="#dnspromisesresolvetxthostname"><code>resolver.resolveTxt()</code></a></li>
13671cb0ef41Sopenharmony_ci<li><a href="#dnspromisesreverseip"><code>resolver.reverse()</code></a></li>
13681cb0ef41Sopenharmony_ci<li><a href="#dnspromisessetserversservers"><code>resolver.setServers()</code></a></li>
13691cb0ef41Sopenharmony_ci</ul>
13701cb0ef41Sopenharmony_ci<h4><code>resolver.cancel()</code><span><a class="mark" href="#resolvercancel_1" id="resolvercancel_1">#</a></span><a aria-hidden="true" class="legacy" id="dns_resolver_cancel_1"></a></h4>
13711cb0ef41Sopenharmony_ci<div class="api_metadata">
13721cb0ef41Sopenharmony_ci<span>Added in: v15.3.0, v14.17.0</span>
13731cb0ef41Sopenharmony_ci</div>
13741cb0ef41Sopenharmony_ci<p>Cancel all outstanding DNS queries made by this resolver. The corresponding
13751cb0ef41Sopenharmony_cipromises will be rejected with an error with the code <code>ECANCELLED</code>.</p>
13761cb0ef41Sopenharmony_ci<h4><code>dnsPromises.getServers()</code><span><a class="mark" href="#dnspromisesgetservers" id="dnspromisesgetservers">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_getservers"></a></h4>
13771cb0ef41Sopenharmony_ci<div class="api_metadata">
13781cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
13791cb0ef41Sopenharmony_ci</div>
13801cb0ef41Sopenharmony_ci<ul>
13811cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
13821cb0ef41Sopenharmony_ci</ul>
13831cb0ef41Sopenharmony_ci<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
13841cb0ef41Sopenharmony_cithat are currently configured for DNS resolution. A string will include a port
13851cb0ef41Sopenharmony_cisection if a custom port is used.</p>
13861cb0ef41Sopenharmony_ci<!-- eslint-disable semi-->
13871cb0ef41Sopenharmony_ci<pre><code class="language-js">[
13881cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4'</span>,
13891cb0ef41Sopenharmony_ci  <span class="hljs-string">'2001:4860:4860::8888'</span>,
13901cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4:1053'</span>,
13911cb0ef41Sopenharmony_ci  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
13921cb0ef41Sopenharmony_ci]</code> <button class="copy-button">copy</button></pre>
13931cb0ef41Sopenharmony_ci<h4><code>dnsPromises.lookup(hostname[, options])</code><span><a class="mark" href="#dnspromiseslookuphostname-options" id="dnspromiseslookuphostname-options">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_lookup_hostname_options"></a></h4>
13941cb0ef41Sopenharmony_ci<div class="api_metadata">
13951cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
13961cb0ef41Sopenharmony_ci</div>
13971cb0ef41Sopenharmony_ci<ul>
13981cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
13991cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
14001cb0ef41Sopenharmony_ci<ul>
14011cb0ef41Sopenharmony_ci<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. The value
14021cb0ef41Sopenharmony_ci<code>0</code> indicates that IPv4 and IPv6 addresses are both returned. <strong>Default:</strong>
14031cb0ef41Sopenharmony_ci<code>0</code>.</li>
14041cb0ef41Sopenharmony_ci<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> One or more <a href="#supported-getaddrinfo-flags">supported <code>getaddrinfo</code> flags</a>. Multiple
14051cb0ef41Sopenharmony_ciflags may be passed by bitwise <code>OR</code>ing their values.</li>
14061cb0ef41Sopenharmony_ci<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the <code>Promise</code> is resolved with all addresses in
14071cb0ef41Sopenharmony_cian array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
14081cb0ef41Sopenharmony_ci<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the <code>Promise</code> is resolved with IPv4 and
14091cb0ef41Sopenharmony_ciIPv6 addresses in the order the DNS resolver returned them. When <code>false</code>,
14101cb0ef41Sopenharmony_ciIPv4 addresses are placed before IPv6 addresses.
14111cb0ef41Sopenharmony_ci<strong>Default:</strong> currently <code>false</code> (addresses are reordered) but this is
14121cb0ef41Sopenharmony_ciexpected to change in the not too distant future. Default value is
14131cb0ef41Sopenharmony_ciconfigurable using <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> or
14141cb0ef41Sopenharmony_ci<a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>. New code should use <code>{ verbatim: true }</code>.</li>
14151cb0ef41Sopenharmony_ci</ul>
14161cb0ef41Sopenharmony_ci</li>
14171cb0ef41Sopenharmony_ci</ul>
14181cb0ef41Sopenharmony_ci<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or
14191cb0ef41Sopenharmony_ciAAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
14201cb0ef41Sopenharmony_ciinteger, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is not provided, then IPv4
14211cb0ef41Sopenharmony_ciand IPv6 addresses are both returned if found.</p>
14221cb0ef41Sopenharmony_ci<p>With the <code>all</code> option set to <code>true</code>, the <code>Promise</code> is resolved with <code>addresses</code>
14231cb0ef41Sopenharmony_cibeing an array of objects with the properties <code>address</code> and <code>family</code>.</p>
14241cb0ef41Sopenharmony_ci<p>On error, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code>
14251cb0ef41Sopenharmony_ciis the error code.
14261cb0ef41Sopenharmony_ciKeep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when
14271cb0ef41Sopenharmony_cithe host name does not exist but also when the lookup fails in other ways
14281cb0ef41Sopenharmony_cisuch as no available file descriptors.</p>
14291cb0ef41Sopenharmony_ci<p><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a> does not necessarily have anything to do with the DNS
14301cb0ef41Sopenharmony_ciprotocol. The implementation uses an operating system facility that can
14311cb0ef41Sopenharmony_ciassociate names with addresses and vice versa. This implementation can have
14321cb0ef41Sopenharmony_cisubtle but important consequences on the behavior of any Node.js program. Please
14331cb0ef41Sopenharmony_citake some time to consult the <a href="#implementation-considerations">Implementation considerations section</a> before
14341cb0ef41Sopenharmony_ciusing <code>dnsPromises.lookup()</code>.</p>
14351cb0ef41Sopenharmony_ci<p>Example usage:</p>
14361cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>);
14371cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dnsPromises = dns.<span class="hljs-property">promises</span>;
14381cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> options = {
14391cb0ef41Sopenharmony_ci  <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>,
14401cb0ef41Sopenharmony_ci  <span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<span class="hljs-property">V4MAPPED</span>,
14411cb0ef41Sopenharmony_ci};
14421cb0ef41Sopenharmony_ci
14431cb0ef41Sopenharmony_cidnsPromises.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">result</span>) =></span> {
14441cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'address: %j family: IPv%s'</span>, result.<span class="hljs-property">address</span>, result.<span class="hljs-property">family</span>);
14451cb0ef41Sopenharmony_ci  <span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span>
14461cb0ef41Sopenharmony_ci});
14471cb0ef41Sopenharmony_ci
14481cb0ef41Sopenharmony_ci<span class="hljs-comment">// When options.all is true, the result will be an Array.</span>
14491cb0ef41Sopenharmony_cioptions.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>;
14501cb0ef41Sopenharmony_cidnsPromises.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">result</span>) =></span> {
14511cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'addresses: %j'</span>, result);
14521cb0ef41Sopenharmony_ci  <span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]</span>
14531cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
14541cb0ef41Sopenharmony_ci<h4><code>dnsPromises.lookupService(address, port)</code><span><a class="mark" href="#dnspromiseslookupserviceaddress-port" id="dnspromiseslookupserviceaddress-port">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_lookupservice_address_port"></a></h4>
14551cb0ef41Sopenharmony_ci<div class="api_metadata">
14561cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
14571cb0ef41Sopenharmony_ci</div>
14581cb0ef41Sopenharmony_ci<ul>
14591cb0ef41Sopenharmony_ci<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14601cb0ef41Sopenharmony_ci<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
14611cb0ef41Sopenharmony_ci</ul>
14621cb0ef41Sopenharmony_ci<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
14631cb0ef41Sopenharmony_cithe operating system's underlying <code>getnameinfo</code> implementation.</p>
14641cb0ef41Sopenharmony_ci<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
14651cb0ef41Sopenharmony_ciThe <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>
14661cb0ef41Sopenharmony_ciwill be thrown.</p>
14671cb0ef41Sopenharmony_ci<p>On error, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code>
14681cb0ef41Sopenharmony_ciis the error code.</p>
14691cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> dnsPromises = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>).<span class="hljs-property">promises</span>;
14701cb0ef41Sopenharmony_cidnsPromises.<span class="hljs-title function_">lookupService</span>(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-number">22</span>).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">result</span>) =></span> {
14711cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(result.<span class="hljs-property">hostname</span>, result.<span class="hljs-property">service</span>);
14721cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Prints: localhost ssh</span>
14731cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
14741cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolve(hostname[, rrtype])</code><span><a class="mark" href="#dnspromisesresolvehostname-rrtype" id="dnspromisesresolvehostname-rrtype">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolve_hostname_rrtype"></a></h4>
14751cb0ef41Sopenharmony_ci<div class="api_metadata">
14761cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
14771cb0ef41Sopenharmony_ci</div>
14781cb0ef41Sopenharmony_ci<ul>
14791cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
14801cb0ef41Sopenharmony_ci<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Resource record type. <strong>Default:</strong> <code>'A'</code>.</li>
14811cb0ef41Sopenharmony_ci</ul>
14821cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array
14831cb0ef41Sopenharmony_ciof the resource records. When successful, the <code>Promise</code> is resolved with an
14841cb0ef41Sopenharmony_ciarray of resource records. The type and structure of individual results vary
14851cb0ef41Sopenharmony_cibased on <code>rrtype</code>:</p>
14861cb0ef41Sopenharmony_ci
14871cb0ef41Sopenharmony_ci
14881cb0ef41Sopenharmony_ci
14891cb0ef41Sopenharmony_ci
14901cb0ef41Sopenharmony_ci
14911cb0ef41Sopenharmony_ci
14921cb0ef41Sopenharmony_ci
14931cb0ef41Sopenharmony_ci
14941cb0ef41Sopenharmony_ci
14951cb0ef41Sopenharmony_ci
14961cb0ef41Sopenharmony_ci
14971cb0ef41Sopenharmony_ci
14981cb0ef41Sopenharmony_ci
14991cb0ef41Sopenharmony_ci
15001cb0ef41Sopenharmony_ci
15011cb0ef41Sopenharmony_ci
15021cb0ef41Sopenharmony_ci
15031cb0ef41Sopenharmony_ci
15041cb0ef41Sopenharmony_ci
15051cb0ef41Sopenharmony_ci
15061cb0ef41Sopenharmony_ci
15071cb0ef41Sopenharmony_ci
15081cb0ef41Sopenharmony_ci
15091cb0ef41Sopenharmony_ci
15101cb0ef41Sopenharmony_ci
15111cb0ef41Sopenharmony_ci
15121cb0ef41Sopenharmony_ci
15131cb0ef41Sopenharmony_ci
15141cb0ef41Sopenharmony_ci
15151cb0ef41Sopenharmony_ci
15161cb0ef41Sopenharmony_ci
15171cb0ef41Sopenharmony_ci
15181cb0ef41Sopenharmony_ci
15191cb0ef41Sopenharmony_ci
15201cb0ef41Sopenharmony_ci
15211cb0ef41Sopenharmony_ci
15221cb0ef41Sopenharmony_ci
15231cb0ef41Sopenharmony_ci
15241cb0ef41Sopenharmony_ci
15251cb0ef41Sopenharmony_ci
15261cb0ef41Sopenharmony_ci
15271cb0ef41Sopenharmony_ci
15281cb0ef41Sopenharmony_ci
15291cb0ef41Sopenharmony_ci
15301cb0ef41Sopenharmony_ci
15311cb0ef41Sopenharmony_ci
15321cb0ef41Sopenharmony_ci
15331cb0ef41Sopenharmony_ci
15341cb0ef41Sopenharmony_ci
15351cb0ef41Sopenharmony_ci
15361cb0ef41Sopenharmony_ci
15371cb0ef41Sopenharmony_ci
15381cb0ef41Sopenharmony_ci
15391cb0ef41Sopenharmony_ci
15401cb0ef41Sopenharmony_ci
15411cb0ef41Sopenharmony_ci
15421cb0ef41Sopenharmony_ci
15431cb0ef41Sopenharmony_ci
15441cb0ef41Sopenharmony_ci
15451cb0ef41Sopenharmony_ci
15461cb0ef41Sopenharmony_ci
15471cb0ef41Sopenharmony_ci
15481cb0ef41Sopenharmony_ci
15491cb0ef41Sopenharmony_ci
15501cb0ef41Sopenharmony_ci
15511cb0ef41Sopenharmony_ci
15521cb0ef41Sopenharmony_ci
15531cb0ef41Sopenharmony_ci
15541cb0ef41Sopenharmony_ci
15551cb0ef41Sopenharmony_ci
15561cb0ef41Sopenharmony_ci
15571cb0ef41Sopenharmony_ci
15581cb0ef41Sopenharmony_ci
15591cb0ef41Sopenharmony_ci
15601cb0ef41Sopenharmony_ci
15611cb0ef41Sopenharmony_ci
15621cb0ef41Sopenharmony_ci
15631cb0ef41Sopenharmony_ci
15641cb0ef41Sopenharmony_ci
15651cb0ef41Sopenharmony_ci
15661cb0ef41Sopenharmony_ci
15671cb0ef41Sopenharmony_ci
15681cb0ef41Sopenharmony_ci
15691cb0ef41Sopenharmony_ci<table><thead><tr><th><code>rrtype</code></th><th><code>records</code> contains</th><th>Result type</th><th>Shorthand method</th></tr></thead><tbody><tr><td><code>'A'</code></td><td>IPv4 addresses (default)</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4()</code></a></td></tr><tr><td><code>'AAAA'</code></td><td>IPv6 addresses</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6()</code></a></td></tr><tr><td><code>'ANY'</code></td><td>any records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnspromisesresolveanyhostname"><code>dnsPromises.resolveAny()</code></a></td></tr><tr><td><code>'CAA'</code></td><td>CA authorization records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnspromisesresolvecaahostname"><code>dnsPromises.resolveCaa()</code></a></td></tr><tr><td><code>'CNAME'</code></td><td>canonical name records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnspromisesresolvecnamehostname"><code>dnsPromises.resolveCname()</code></a></td></tr><tr><td><code>'MX'</code></td><td>mail exchange records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>name authority pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td>name server records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnspromisesresolvenshostname"><code>dnsPromises.resolveNs()</code></a></td></tr><tr><td><code>'PTR'</code></td><td>pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dnspromisesresolveptrhostname"><code>dnsPromises.resolvePtr()</code></a></td></tr><tr><td><code>'SOA'</code></td><td>start of authority records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>service records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><td>text records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></td><td><a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt()</code></a></td></tr></tbody></table>
15701cb0ef41Sopenharmony_ci<p>On error, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code>
15711cb0ef41Sopenharmony_ciis one of the <a href="#error-codes">DNS error codes</a>.</p>
15721cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolve4(hostname[, options])</code><span><a class="mark" href="#dnspromisesresolve4hostname-options" id="dnspromisesresolve4hostname-options">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolve4_hostname_options"></a></h4>
15731cb0ef41Sopenharmony_ci<div class="api_metadata">
15741cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
15751cb0ef41Sopenharmony_ci</div>
15761cb0ef41Sopenharmony_ci<ul>
15771cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
15781cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
15791cb0ef41Sopenharmony_ci<ul>
15801cb0ef41Sopenharmony_ci<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieve the Time-To-Live value (TTL) of each record.
15811cb0ef41Sopenharmony_ciWhen <code>true</code>, the <code>Promise</code> is resolved with an array of
15821cb0ef41Sopenharmony_ci<code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings,
15831cb0ef41Sopenharmony_ciwith the TTL expressed in seconds.</li>
15841cb0ef41Sopenharmony_ci</ul>
15851cb0ef41Sopenharmony_ci</li>
15861cb0ef41Sopenharmony_ci</ul>
15871cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve IPv4 addresses (<code>A</code> records) for the
15881cb0ef41Sopenharmony_ci<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv4
15891cb0ef41Sopenharmony_ciaddresses (e.g. <code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>
15901cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolve6(hostname[, options])</code><span><a class="mark" href="#dnspromisesresolve6hostname-options" id="dnspromisesresolve6hostname-options">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolve6_hostname_options"></a></h4>
15911cb0ef41Sopenharmony_ci<div class="api_metadata">
15921cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
15931cb0ef41Sopenharmony_ci</div>
15941cb0ef41Sopenharmony_ci<ul>
15951cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
15961cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
15971cb0ef41Sopenharmony_ci<ul>
15981cb0ef41Sopenharmony_ci<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieve the Time-To-Live value (TTL) of each record.
15991cb0ef41Sopenharmony_ciWhen <code>true</code>, the <code>Promise</code> is resolved with an array of
16001cb0ef41Sopenharmony_ci<code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of
16011cb0ef41Sopenharmony_cistrings, with the TTL expressed in seconds.</li>
16021cb0ef41Sopenharmony_ci</ul>
16031cb0ef41Sopenharmony_ci</li>
16041cb0ef41Sopenharmony_ci</ul>
16051cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the
16061cb0ef41Sopenharmony_ci<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv6
16071cb0ef41Sopenharmony_ciaddresses.</p>
16081cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveAny(hostname)</code><span><a class="mark" href="#dnspromisesresolveanyhostname" id="dnspromisesresolveanyhostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolveany_hostname"></a></h4>
16091cb0ef41Sopenharmony_ci<div class="api_metadata">
16101cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
16111cb0ef41Sopenharmony_ci</div>
16121cb0ef41Sopenharmony_ci<ul>
16131cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
16141cb0ef41Sopenharmony_ci</ul>
16151cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).
16161cb0ef41Sopenharmony_ciOn success, the <code>Promise</code> is resolved with an array containing various types of
16171cb0ef41Sopenharmony_cirecords. Each object has a property <code>type</code> that indicates the type of the
16181cb0ef41Sopenharmony_cicurrent record. And depending on the <code>type</code>, additional properties will be
16191cb0ef41Sopenharmony_cipresent on the object:</p>
16201cb0ef41Sopenharmony_ci
16211cb0ef41Sopenharmony_ci
16221cb0ef41Sopenharmony_ci
16231cb0ef41Sopenharmony_ci
16241cb0ef41Sopenharmony_ci
16251cb0ef41Sopenharmony_ci
16261cb0ef41Sopenharmony_ci
16271cb0ef41Sopenharmony_ci
16281cb0ef41Sopenharmony_ci
16291cb0ef41Sopenharmony_ci
16301cb0ef41Sopenharmony_ci
16311cb0ef41Sopenharmony_ci
16321cb0ef41Sopenharmony_ci
16331cb0ef41Sopenharmony_ci
16341cb0ef41Sopenharmony_ci
16351cb0ef41Sopenharmony_ci
16361cb0ef41Sopenharmony_ci
16371cb0ef41Sopenharmony_ci
16381cb0ef41Sopenharmony_ci
16391cb0ef41Sopenharmony_ci
16401cb0ef41Sopenharmony_ci
16411cb0ef41Sopenharmony_ci
16421cb0ef41Sopenharmony_ci
16431cb0ef41Sopenharmony_ci
16441cb0ef41Sopenharmony_ci
16451cb0ef41Sopenharmony_ci
16461cb0ef41Sopenharmony_ci
16471cb0ef41Sopenharmony_ci
16481cb0ef41Sopenharmony_ci
16491cb0ef41Sopenharmony_ci
16501cb0ef41Sopenharmony_ci
16511cb0ef41Sopenharmony_ci
16521cb0ef41Sopenharmony_ci
16531cb0ef41Sopenharmony_ci
16541cb0ef41Sopenharmony_ci
16551cb0ef41Sopenharmony_ci
16561cb0ef41Sopenharmony_ci
16571cb0ef41Sopenharmony_ci
16581cb0ef41Sopenharmony_ci
16591cb0ef41Sopenharmony_ci
16601cb0ef41Sopenharmony_ci
16611cb0ef41Sopenharmony_ci
16621cb0ef41Sopenharmony_ci
16631cb0ef41Sopenharmony_ci
16641cb0ef41Sopenharmony_ci
16651cb0ef41Sopenharmony_ci
16661cb0ef41Sopenharmony_ci
16671cb0ef41Sopenharmony_ci
16681cb0ef41Sopenharmony_ci
16691cb0ef41Sopenharmony_ci<table><thead><tr><th>Type</th><th>Properties</th></tr></thead><tbody><tr><td><code>'A'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'AAAA'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'CNAME'</code></td><td><code>value</code></td></tr><tr><td><code>'MX'</code></td><td>Refer to <a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>Refer to <a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td><code>value</code></td></tr><tr><td><code>'PTR'</code></td><td><code>value</code></td></tr><tr><td><code>'SOA'</code></td><td>Refer to <a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>Refer to <a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><td>This type of record contains an array property called <code>entries</code> which refers to <a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt()</code></a>, e.g. <code>{ entries: ['...'], type: 'TXT' }</code></td></tr></tbody></table>
16701cb0ef41Sopenharmony_ci<p>Here is an example of the result object:</p>
16711cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
16721cb0ef41Sopenharmony_ci<pre><code class="language-js">[ { <span class="hljs-attr">type</span>: <span class="hljs-string">'A'</span>, <span class="hljs-attr">address</span>: <span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-attr">ttl</span>: <span class="hljs-number">299</span> },
16731cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'CNAME'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'example.com'</span> },
16741cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'MX'</span>, <span class="hljs-attr">exchange</span>: <span class="hljs-string">'alt4.aspmx.l.example.com'</span>, <span class="hljs-attr">priority</span>: <span class="hljs-number">50</span> },
16751cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'NS'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'ns1.example.com'</span> },
16761cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'TXT'</span>, <span class="hljs-attr">entries</span>: [ <span class="hljs-string">'v=spf1 include:_spf.example.com ~all'</span> ] },
16771cb0ef41Sopenharmony_ci  { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>,
16781cb0ef41Sopenharmony_ci    <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>,
16791cb0ef41Sopenharmony_ci    <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>,
16801cb0ef41Sopenharmony_ci    <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>,
16811cb0ef41Sopenharmony_ci    <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>,
16821cb0ef41Sopenharmony_ci    <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>,
16831cb0ef41Sopenharmony_ci    <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>,
16841cb0ef41Sopenharmony_ci    <span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code> <button class="copy-button">copy</button></pre>
16851cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveCaa(hostname)</code><span><a class="mark" href="#dnspromisesresolvecaahostname" id="dnspromisesresolvecaahostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvecaa_hostname"></a></h4>
16861cb0ef41Sopenharmony_ci<div class="api_metadata">
16871cb0ef41Sopenharmony_ci<span>Added in: v15.0.0, v14.17.0</span>
16881cb0ef41Sopenharmony_ci</div>
16891cb0ef41Sopenharmony_ci<ul>
16901cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
16911cb0ef41Sopenharmony_ci</ul>
16921cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. On success,
16931cb0ef41Sopenharmony_cithe <code>Promise</code> is resolved with an array of objects containing available
16941cb0ef41Sopenharmony_cicertification authority authorization records available for the <code>hostname</code>
16951cb0ef41Sopenharmony_ci(e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]</code>).</p>
16961cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveCname(hostname)</code><span><a class="mark" href="#dnspromisesresolvecnamehostname" id="dnspromisesresolvecnamehostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvecname_hostname"></a></h4>
16971cb0ef41Sopenharmony_ci<div class="api_metadata">
16981cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
16991cb0ef41Sopenharmony_ci</div>
17001cb0ef41Sopenharmony_ci<ul>
17011cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
17021cb0ef41Sopenharmony_ci</ul>
17031cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. On success,
17041cb0ef41Sopenharmony_cithe <code>Promise</code> is resolved with an array of canonical name records available for
17051cb0ef41Sopenharmony_cithe <code>hostname</code> (e.g. <code>['bar.example.com']</code>).</p>
17061cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveMx(hostname)</code><span><a class="mark" href="#dnspromisesresolvemxhostname" id="dnspromisesresolvemxhostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvemx_hostname"></a></h4>
17071cb0ef41Sopenharmony_ci<div class="api_metadata">
17081cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
17091cb0ef41Sopenharmony_ci</div>
17101cb0ef41Sopenharmony_ci<ul>
17111cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
17121cb0ef41Sopenharmony_ci</ul>
17131cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
17141cb0ef41Sopenharmony_ci<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects
17151cb0ef41Sopenharmony_cicontaining both a <code>priority</code> and <code>exchange</code> property (e.g.
17161cb0ef41Sopenharmony_ci<code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>
17171cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveNaptr(hostname)</code><span><a class="mark" href="#dnspromisesresolvenaptrhostname" id="dnspromisesresolvenaptrhostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvenaptr_hostname"></a></h4>
17181cb0ef41Sopenharmony_ci<div class="api_metadata">
17191cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
17201cb0ef41Sopenharmony_ci</div>
17211cb0ef41Sopenharmony_ci<ul>
17221cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
17231cb0ef41Sopenharmony_ci</ul>
17241cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve regular expression-based records (<code>NAPTR</code>
17251cb0ef41Sopenharmony_cirecords) for the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array
17261cb0ef41Sopenharmony_ciof objects with the following properties:</p>
17271cb0ef41Sopenharmony_ci<ul>
17281cb0ef41Sopenharmony_ci<li><code>flags</code></li>
17291cb0ef41Sopenharmony_ci<li><code>service</code></li>
17301cb0ef41Sopenharmony_ci<li><code>regexp</code></li>
17311cb0ef41Sopenharmony_ci<li><code>replacement</code></li>
17321cb0ef41Sopenharmony_ci<li><code>order</code></li>
17331cb0ef41Sopenharmony_ci<li><code>preference</code></li>
17341cb0ef41Sopenharmony_ci</ul>
17351cb0ef41Sopenharmony_ci<!-- eslint-skip -->
17361cb0ef41Sopenharmony_ci<pre><code class="language-js">{
17371cb0ef41Sopenharmony_ci  <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>,
17381cb0ef41Sopenharmony_ci  <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>,
17391cb0ef41Sopenharmony_ci  <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>,
17401cb0ef41Sopenharmony_ci  <span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</span>,
17411cb0ef41Sopenharmony_ci  <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>,
17421cb0ef41Sopenharmony_ci  <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span>
17431cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
17441cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveNs(hostname)</code><span><a class="mark" href="#dnspromisesresolvenshostname" id="dnspromisesresolvenshostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvens_hostname"></a></h4>
17451cb0ef41Sopenharmony_ci<div class="api_metadata">
17461cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
17471cb0ef41Sopenharmony_ci</div>
17481cb0ef41Sopenharmony_ci<ul>
17491cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
17501cb0ef41Sopenharmony_ci</ul>
17511cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
17521cb0ef41Sopenharmony_ci<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of name server
17531cb0ef41Sopenharmony_cirecords available for <code>hostname</code> (e.g.
17541cb0ef41Sopenharmony_ci<code>['ns1.example.com', 'ns2.example.com']</code>).</p>
17551cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolvePtr(hostname)</code><span><a class="mark" href="#dnspromisesresolveptrhostname" id="dnspromisesresolveptrhostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolveptr_hostname"></a></h4>
17561cb0ef41Sopenharmony_ci<div class="api_metadata">
17571cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
17581cb0ef41Sopenharmony_ci</div>
17591cb0ef41Sopenharmony_ci<ul>
17601cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
17611cb0ef41Sopenharmony_ci</ul>
17621cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
17631cb0ef41Sopenharmony_ci<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of strings
17641cb0ef41Sopenharmony_cicontaining the reply records.</p>
17651cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveSoa(hostname)</code><span><a class="mark" href="#dnspromisesresolvesoahostname" id="dnspromisesresolvesoahostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvesoa_hostname"></a></h4>
17661cb0ef41Sopenharmony_ci<div class="api_metadata">
17671cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
17681cb0ef41Sopenharmony_ci</div>
17691cb0ef41Sopenharmony_ci<ul>
17701cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
17711cb0ef41Sopenharmony_ci</ul>
17721cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
17731cb0ef41Sopenharmony_cithe <code>hostname</code>. On success, the <code>Promise</code> is resolved with an object with the
17741cb0ef41Sopenharmony_cifollowing properties:</p>
17751cb0ef41Sopenharmony_ci<ul>
17761cb0ef41Sopenharmony_ci<li><code>nsname</code></li>
17771cb0ef41Sopenharmony_ci<li><code>hostmaster</code></li>
17781cb0ef41Sopenharmony_ci<li><code>serial</code></li>
17791cb0ef41Sopenharmony_ci<li><code>refresh</code></li>
17801cb0ef41Sopenharmony_ci<li><code>retry</code></li>
17811cb0ef41Sopenharmony_ci<li><code>expire</code></li>
17821cb0ef41Sopenharmony_ci<li><code>minttl</code></li>
17831cb0ef41Sopenharmony_ci</ul>
17841cb0ef41Sopenharmony_ci<!-- eslint-skip -->
17851cb0ef41Sopenharmony_ci<pre><code class="language-js">{
17861cb0ef41Sopenharmony_ci  <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>,
17871cb0ef41Sopenharmony_ci  <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>,
17881cb0ef41Sopenharmony_ci  <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>,
17891cb0ef41Sopenharmony_ci  <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>,
17901cb0ef41Sopenharmony_ci  <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>,
17911cb0ef41Sopenharmony_ci  <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>,
17921cb0ef41Sopenharmony_ci  <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span>
17931cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
17941cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveSrv(hostname)</code><span><a class="mark" href="#dnspromisesresolvesrvhostname" id="dnspromisesresolvesrvhostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvesrv_hostname"></a></h4>
17951cb0ef41Sopenharmony_ci<div class="api_metadata">
17961cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
17971cb0ef41Sopenharmony_ci</div>
17981cb0ef41Sopenharmony_ci<ul>
17991cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
18001cb0ef41Sopenharmony_ci</ul>
18011cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
18021cb0ef41Sopenharmony_ci<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects with
18031cb0ef41Sopenharmony_cithe following properties:</p>
18041cb0ef41Sopenharmony_ci<ul>
18051cb0ef41Sopenharmony_ci<li><code>priority</code></li>
18061cb0ef41Sopenharmony_ci<li><code>weight</code></li>
18071cb0ef41Sopenharmony_ci<li><code>port</code></li>
18081cb0ef41Sopenharmony_ci<li><code>name</code></li>
18091cb0ef41Sopenharmony_ci</ul>
18101cb0ef41Sopenharmony_ci<!-- eslint-skip -->
18111cb0ef41Sopenharmony_ci<pre><code class="language-js">{
18121cb0ef41Sopenharmony_ci  <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>,
18131cb0ef41Sopenharmony_ci  <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>,
18141cb0ef41Sopenharmony_ci  <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>,
18151cb0ef41Sopenharmony_ci  <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span>
18161cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
18171cb0ef41Sopenharmony_ci<h4><code>dnsPromises.resolveTxt(hostname)</code><span><a class="mark" href="#dnspromisesresolvetxthostname" id="dnspromisesresolvetxthostname">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_resolvetxt_hostname"></a></h4>
18181cb0ef41Sopenharmony_ci<div class="api_metadata">
18191cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
18201cb0ef41Sopenharmony_ci</div>
18211cb0ef41Sopenharmony_ci<ul>
18221cb0ef41Sopenharmony_ci<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
18231cb0ef41Sopenharmony_ci</ul>
18241cb0ef41Sopenharmony_ci<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
18251cb0ef41Sopenharmony_ci<code>hostname</code>. On success, the <code>Promise</code> is resolved with a two-dimensional array
18261cb0ef41Sopenharmony_ciof the text records available for <code>hostname</code> (e.g.
18271cb0ef41Sopenharmony_ci<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of
18281cb0ef41Sopenharmony_cione record. Depending on the use case, these could be either joined together or
18291cb0ef41Sopenharmony_citreated separately.</p>
18301cb0ef41Sopenharmony_ci<h4><code>dnsPromises.reverse(ip)</code><span><a class="mark" href="#dnspromisesreverseip" id="dnspromisesreverseip">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_reverse_ip"></a></h4>
18311cb0ef41Sopenharmony_ci<div class="api_metadata">
18321cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
18331cb0ef41Sopenharmony_ci</div>
18341cb0ef41Sopenharmony_ci<ul>
18351cb0ef41Sopenharmony_ci<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
18361cb0ef41Sopenharmony_ci</ul>
18371cb0ef41Sopenharmony_ci<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
18381cb0ef41Sopenharmony_ciarray of host names.</p>
18391cb0ef41Sopenharmony_ci<p>On error, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</code></a> object, where <code>err.code</code>
18401cb0ef41Sopenharmony_ciis one of the <a href="#error-codes">DNS error codes</a>.</p>
18411cb0ef41Sopenharmony_ci<h4><code>dnsPromises.setDefaultResultOrder(order)</code><span><a class="mark" href="#dnspromisessetdefaultresultorderorder" id="dnspromisessetdefaultresultorderorder">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_setdefaultresultorder_order"></a></h4>
18421cb0ef41Sopenharmony_ci<div class="api_metadata">
18431cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
18441cb0ef41Sopenharmony_ci<table>
18451cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
18461cb0ef41Sopenharmony_ci<tr><td>v17.0.0</td>
18471cb0ef41Sopenharmony_ci<td><p>Changed default value to <code>verbatim</code>.</p></td></tr>
18481cb0ef41Sopenharmony_ci<tr><td>v16.4.0, v14.18.0</td>
18491cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.4.0, v14.18.0</span></p></td></tr>
18501cb0ef41Sopenharmony_ci</tbody></table>
18511cb0ef41Sopenharmony_ci</details>
18521cb0ef41Sopenharmony_ci</div>
18531cb0ef41Sopenharmony_ci<ul>
18541cb0ef41Sopenharmony_ci<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> must be <code>'ipv4first'</code> or <code>'verbatim'</code>.</li>
18551cb0ef41Sopenharmony_ci</ul>
18561cb0ef41Sopenharmony_ci<p>Set the default value of <code>verbatim</code> in <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and
18571cb0ef41Sopenharmony_ci<a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
18581cb0ef41Sopenharmony_ci<ul>
18591cb0ef41Sopenharmony_ci<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
18601cb0ef41Sopenharmony_ci<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
18611cb0ef41Sopenharmony_ci</ul>
18621cb0ef41Sopenharmony_ci<p>The default is <code>verbatim</code> and <a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder()</code></a> have
18631cb0ef41Sopenharmony_cihigher priority than <a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>. When using <a href="worker_threads.html">worker threads</a>,
18641cb0ef41Sopenharmony_ci<a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder()</code></a> from the main thread won't affect the
18651cb0ef41Sopenharmony_cidefault dns orders in workers.</p>
18661cb0ef41Sopenharmony_ci<h4><code>dnsPromises.getDefaultResultOrder()</code><span><a class="mark" href="#dnspromisesgetdefaultresultorder" id="dnspromisesgetdefaultresultorder">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_getdefaultresultorder"></a></h4>
18671cb0ef41Sopenharmony_ci<div class="api_metadata">
18681cb0ef41Sopenharmony_ci<span>Added in: v18.17.0</span>
18691cb0ef41Sopenharmony_ci</div>
18701cb0ef41Sopenharmony_ci<p>Get the value of <code>dnsOrder</code>.</p>
18711cb0ef41Sopenharmony_ci<h4><code>dnsPromises.setServers(servers)</code><span><a class="mark" href="#dnspromisessetserversservers" id="dnspromisessetserversservers">#</a></span><a aria-hidden="true" class="legacy" id="dns_dnspromises_setservers_servers"></a></h4>
18721cb0ef41Sopenharmony_ci<div class="api_metadata">
18731cb0ef41Sopenharmony_ci<span>Added in: v10.6.0</span>
18741cb0ef41Sopenharmony_ci</div>
18751cb0ef41Sopenharmony_ci<ul>
18761cb0ef41Sopenharmony_ci<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li>
18771cb0ef41Sopenharmony_ci</ul>
18781cb0ef41Sopenharmony_ci<p>Sets the IP address and port of servers to be used when performing DNS
18791cb0ef41Sopenharmony_ciresolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted
18801cb0ef41Sopenharmony_ciaddresses. If the port is the IANA default DNS port (53) it can be omitted.</p>
18811cb0ef41Sopenharmony_ci<pre><code class="language-js">dnsPromises.<span class="hljs-title function_">setServers</span>([
18821cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4'</span>,
18831cb0ef41Sopenharmony_ci  <span class="hljs-string">'[2001:4860:4860::8888]'</span>,
18841cb0ef41Sopenharmony_ci  <span class="hljs-string">'4.4.4.4:1053'</span>,
18851cb0ef41Sopenharmony_ci  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
18861cb0ef41Sopenharmony_ci]);</code> <button class="copy-button">copy</button></pre>
18871cb0ef41Sopenharmony_ci<p>An error will be thrown if an invalid address is provided.</p>
18881cb0ef41Sopenharmony_ci<p>The <code>dnsPromises.setServers()</code> method must not be called while a DNS query is in
18891cb0ef41Sopenharmony_ciprogress.</p>
18901cb0ef41Sopenharmony_ci<p>This method works much like
18911cb0ef41Sopenharmony_ci<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
18921cb0ef41Sopenharmony_ciThat is, if attempting to resolve with the first server provided results in a
18931cb0ef41Sopenharmony_ci<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with
18941cb0ef41Sopenharmony_cisubsequent servers provided. Fallback DNS servers will only be used if the
18951cb0ef41Sopenharmony_ciearlier ones time out or result in some other error.</p>
18961cb0ef41Sopenharmony_ci</section><section><h3>Error codes<span><a class="mark" href="#error-codes" id="error-codes">#</a></span><a aria-hidden="true" class="legacy" id="dns_error_codes"></a></h3>
18971cb0ef41Sopenharmony_ci<p>Each DNS query can return one of the following error codes:</p>
18981cb0ef41Sopenharmony_ci<ul>
18991cb0ef41Sopenharmony_ci<li><code>dns.NODATA</code>: DNS server returned an answer with no data.</li>
19001cb0ef41Sopenharmony_ci<li><code>dns.FORMERR</code>: DNS server claims query was misformatted.</li>
19011cb0ef41Sopenharmony_ci<li><code>dns.SERVFAIL</code>: DNS server returned general failure.</li>
19021cb0ef41Sopenharmony_ci<li><code>dns.NOTFOUND</code>: Domain name not found.</li>
19031cb0ef41Sopenharmony_ci<li><code>dns.NOTIMP</code>: DNS server does not implement the requested operation.</li>
19041cb0ef41Sopenharmony_ci<li><code>dns.REFUSED</code>: DNS server refused query.</li>
19051cb0ef41Sopenharmony_ci<li><code>dns.BADQUERY</code>: Misformatted DNS query.</li>
19061cb0ef41Sopenharmony_ci<li><code>dns.BADNAME</code>: Misformatted host name.</li>
19071cb0ef41Sopenharmony_ci<li><code>dns.BADFAMILY</code>: Unsupported address family.</li>
19081cb0ef41Sopenharmony_ci<li><code>dns.BADRESP</code>: Misformatted DNS reply.</li>
19091cb0ef41Sopenharmony_ci<li><code>dns.CONNREFUSED</code>: Could not contact DNS servers.</li>
19101cb0ef41Sopenharmony_ci<li><code>dns.TIMEOUT</code>: Timeout while contacting DNS servers.</li>
19111cb0ef41Sopenharmony_ci<li><code>dns.EOF</code>: End of file.</li>
19121cb0ef41Sopenharmony_ci<li><code>dns.FILE</code>: Error reading file.</li>
19131cb0ef41Sopenharmony_ci<li><code>dns.NOMEM</code>: Out of memory.</li>
19141cb0ef41Sopenharmony_ci<li><code>dns.DESTRUCTION</code>: Channel is being destroyed.</li>
19151cb0ef41Sopenharmony_ci<li><code>dns.BADSTR</code>: Misformatted string.</li>
19161cb0ef41Sopenharmony_ci<li><code>dns.BADFLAGS</code>: Illegal flags specified.</li>
19171cb0ef41Sopenharmony_ci<li><code>dns.NONAME</code>: Given host name is not numeric.</li>
19181cb0ef41Sopenharmony_ci<li><code>dns.BADHINTS</code>: Illegal hints flags specified.</li>
19191cb0ef41Sopenharmony_ci<li><code>dns.NOTINITIALIZED</code>: c-ares library initialization not yet performed.</li>
19201cb0ef41Sopenharmony_ci<li><code>dns.LOADIPHLPAPI</code>: Error loading <code>iphlpapi.dll</code>.</li>
19211cb0ef41Sopenharmony_ci<li><code>dns.ADDRGETNETWORKPARAMS</code>: Could not find <code>GetNetworkParams</code> function.</li>
19221cb0ef41Sopenharmony_ci<li><code>dns.CANCELLED</code>: DNS query cancelled.</li>
19231cb0ef41Sopenharmony_ci</ul>
19241cb0ef41Sopenharmony_ci<p>The <code>dnsPromises</code> API also exports the above error codes, e.g., <code>dnsPromises.NODATA</code>.</p>
19251cb0ef41Sopenharmony_ci</section><section><h3>Implementation considerations<span><a class="mark" href="#implementation-considerations" id="implementation-considerations">#</a></span><a aria-hidden="true" class="legacy" id="dns_implementation_considerations"></a></h3>
19261cb0ef41Sopenharmony_ci<p>Although <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and the various <code>dns.resolve*()/dns.reverse()</code>
19271cb0ef41Sopenharmony_cifunctions have the same goal of associating a network name with a network
19281cb0ef41Sopenharmony_ciaddress (or vice versa), their behavior is quite different. These differences
19291cb0ef41Sopenharmony_cican have subtle but significant consequences on the behavior of Node.js
19301cb0ef41Sopenharmony_ciprograms.</p>
19311cb0ef41Sopenharmony_ci<h4><code>dns.lookup()</code><span><a class="mark" href="#dnslookup" id="dnslookup">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_lookup"></a></h4>
19321cb0ef41Sopenharmony_ci<p>Under the hood, <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> uses the same operating system facilities
19331cb0ef41Sopenharmony_cias most other programs. For instance, <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> will almost always
19341cb0ef41Sopenharmony_ciresolve a given name the same way as the <code>ping</code> command. On most POSIX-like
19351cb0ef41Sopenharmony_cioperating systems, the behavior of the <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> function can be
19361cb0ef41Sopenharmony_cimodified by changing settings in <a href="http://man7.org/linux/man-pages/man5/nsswitch.conf.5.html"><code>nsswitch.conf(5)</code></a> and/or <a href="http://man7.org/linux/man-pages/man5/resolv.conf.5.html"><code>resolv.conf(5)</code></a>,
19371cb0ef41Sopenharmony_cibut changing these files will change the behavior of all other
19381cb0ef41Sopenharmony_ciprograms running on the same operating system.</p>
19391cb0ef41Sopenharmony_ci<p>Though the call to <code>dns.lookup()</code> will be asynchronous from JavaScript's
19401cb0ef41Sopenharmony_ciperspective, it is implemented as a synchronous call to <a href="http://man7.org/linux/man-pages/man3/getaddrinfo.3.html"><code>getaddrinfo(3)</code></a> that runs
19411cb0ef41Sopenharmony_cion libuv's threadpool. This can have surprising negative performance
19421cb0ef41Sopenharmony_ciimplications for some applications, see the <a href="cli.html#uv_threadpool_sizesize"><code>UV_THREADPOOL_SIZE</code></a>
19431cb0ef41Sopenharmony_cidocumentation for more information.</p>
19441cb0ef41Sopenharmony_ci<p>Various networking APIs will call <code>dns.lookup()</code> internally to resolve
19451cb0ef41Sopenharmony_cihost names. If that is an issue, consider resolving the host name to an address
19461cb0ef41Sopenharmony_ciusing <code>dns.resolve()</code> and using the address instead of a host name. Also, some
19471cb0ef41Sopenharmony_cinetworking APIs (such as <a href="net.html#socketconnectoptions-connectlistener"><code>socket.connect()</code></a> and <a href="dgram.html#dgramcreatesocketoptions-callback"><code>dgram.createSocket()</code></a>)
19481cb0ef41Sopenharmony_ciallow the default resolver, <code>dns.lookup()</code>, to be replaced.</p>
19491cb0ef41Sopenharmony_ci<h4><code>dns.resolve()</code>, <code>dns.resolve*()</code>, and <code>dns.reverse()</code><span><a class="mark" href="#dnsresolve-dnsresolve-and-dnsreverse" id="dnsresolve-dnsresolve-and-dnsreverse">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns_resolve_dns_resolve_and_dns_reverse"></a></h4>
19501cb0ef41Sopenharmony_ci<p>These functions are implemented quite differently than <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>. They
19511cb0ef41Sopenharmony_cido not use <a href="http://man7.org/linux/man-pages/man3/getaddrinfo.3.html"><code>getaddrinfo(3)</code></a> and they <em>always</em> perform a DNS query on the
19521cb0ef41Sopenharmony_cinetwork. This network communication is always done asynchronously and does not
19531cb0ef41Sopenharmony_ciuse libuv's threadpool.</p>
19541cb0ef41Sopenharmony_ci<p>As a result, these functions cannot have the same negative impact on other
19551cb0ef41Sopenharmony_ciprocessing that happens on libuv's threadpool that <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> can have.</p>
19561cb0ef41Sopenharmony_ci<p>They do not use the same set of configuration files that <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>
19571cb0ef41Sopenharmony_ciuses. For instance, they do not use the configuration from <code>/etc/hosts</code>.</p></section>
19581cb0ef41Sopenharmony_ci        <!-- API END -->
19591cb0ef41Sopenharmony_ci      </div>
19601cb0ef41Sopenharmony_ci    </div>
19611cb0ef41Sopenharmony_ci  </div>
19621cb0ef41Sopenharmony_ci</body>
19631cb0ef41Sopenharmony_ci</html>
1964