11cb0ef41Sopenharmony_ci# DNS
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci<!--introduced_in=v0.10.0-->
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci> Stability: 2 - Stable
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci<!-- source_link=lib/dns.js -->
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciThe `node:dns` module enables name resolution. For example, use it to look up IP
101cb0ef41Sopenharmony_ciaddresses of host names.
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciAlthough named for the [Domain Name System (DNS)][], it does not always use the
131cb0ef41Sopenharmony_ciDNS protocol for lookups. [`dns.lookup()`][] uses the operating system
141cb0ef41Sopenharmony_cifacilities to perform name resolution. It may not need to perform any network
151cb0ef41Sopenharmony_cicommunication. To perform name resolution the way other applications on the same
161cb0ef41Sopenharmony_cisystem do, use [`dns.lookup()`][].
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci```js
191cb0ef41Sopenharmony_ciconst dns = require('node:dns');
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cidns.lookup('example.org', (err, address, family) => {
221cb0ef41Sopenharmony_ci  console.log('address: %j family: IPv%s', address, family);
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci// address: "93.184.216.34" family: IPv4
251cb0ef41Sopenharmony_ci```
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciAll other functions in the `node:dns` module connect to an actual DNS server to
281cb0ef41Sopenharmony_ciperform name resolution. They will always use the network to perform DNS
291cb0ef41Sopenharmony_ciqueries. These functions do not use the same set of configuration files used by
301cb0ef41Sopenharmony_ci[`dns.lookup()`][] (e.g. `/etc/hosts`). Use these functions to always perform
311cb0ef41Sopenharmony_ciDNS queries, bypassing other name-resolution facilities.
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci```js
341cb0ef41Sopenharmony_ciconst dns = require('node:dns');
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cidns.resolve4('archive.org', (err, addresses) => {
371cb0ef41Sopenharmony_ci  if (err) throw err;
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  console.log(`addresses: ${JSON.stringify(addresses)}`);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  addresses.forEach((a) => {
421cb0ef41Sopenharmony_ci    dns.reverse(a, (err, hostnames) => {
431cb0ef41Sopenharmony_ci      if (err) {
441cb0ef41Sopenharmony_ci        throw err;
451cb0ef41Sopenharmony_ci      }
461cb0ef41Sopenharmony_ci      console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);
471cb0ef41Sopenharmony_ci    });
481cb0ef41Sopenharmony_ci  });
491cb0ef41Sopenharmony_ci});
501cb0ef41Sopenharmony_ci```
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciSee the [Implementation considerations section][] for more information.
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci## Class: `dns.Resolver`
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci<!-- YAML
571cb0ef41Sopenharmony_ciadded: v8.3.0
581cb0ef41Sopenharmony_ci-->
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciAn independent resolver for DNS requests.
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ciCreating a new resolver uses the default server settings. Setting
631cb0ef41Sopenharmony_cithe servers used for a resolver using
641cb0ef41Sopenharmony_ci[`resolver.setServers()`][`dns.setServers()`] does not affect
651cb0ef41Sopenharmony_ciother resolvers:
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci```js
681cb0ef41Sopenharmony_ciconst { Resolver } = require('node:dns');
691cb0ef41Sopenharmony_ciconst resolver = new Resolver();
701cb0ef41Sopenharmony_ciresolver.setServers(['4.4.4.4']);
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci// This request will use the server at 4.4.4.4, independent of global settings.
731cb0ef41Sopenharmony_ciresolver.resolve4('example.org', (err, addresses) => {
741cb0ef41Sopenharmony_ci  // ...
751cb0ef41Sopenharmony_ci});
761cb0ef41Sopenharmony_ci```
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ciThe following methods from the `node:dns` module are available:
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci* [`resolver.getServers()`][`dns.getServers()`]
811cb0ef41Sopenharmony_ci* [`resolver.resolve()`][`dns.resolve()`]
821cb0ef41Sopenharmony_ci* [`resolver.resolve4()`][`dns.resolve4()`]
831cb0ef41Sopenharmony_ci* [`resolver.resolve6()`][`dns.resolve6()`]
841cb0ef41Sopenharmony_ci* [`resolver.resolveAny()`][`dns.resolveAny()`]
851cb0ef41Sopenharmony_ci* [`resolver.resolveCaa()`][`dns.resolveCaa()`]
861cb0ef41Sopenharmony_ci* [`resolver.resolveCname()`][`dns.resolveCname()`]
871cb0ef41Sopenharmony_ci* [`resolver.resolveMx()`][`dns.resolveMx()`]
881cb0ef41Sopenharmony_ci* [`resolver.resolveNaptr()`][`dns.resolveNaptr()`]
891cb0ef41Sopenharmony_ci* [`resolver.resolveNs()`][`dns.resolveNs()`]
901cb0ef41Sopenharmony_ci* [`resolver.resolvePtr()`][`dns.resolvePtr()`]
911cb0ef41Sopenharmony_ci* [`resolver.resolveSoa()`][`dns.resolveSoa()`]
921cb0ef41Sopenharmony_ci* [`resolver.resolveSrv()`][`dns.resolveSrv()`]
931cb0ef41Sopenharmony_ci* [`resolver.resolveTxt()`][`dns.resolveTxt()`]
941cb0ef41Sopenharmony_ci* [`resolver.reverse()`][`dns.reverse()`]
951cb0ef41Sopenharmony_ci* [`resolver.setServers()`][`dns.setServers()`]
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci### `Resolver([options])`
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci<!-- YAML
1001cb0ef41Sopenharmony_ciadded: v8.3.0
1011cb0ef41Sopenharmony_cichanges:
1021cb0ef41Sopenharmony_ci  - version:
1031cb0ef41Sopenharmony_ci      - v16.7.0
1041cb0ef41Sopenharmony_ci      - v14.18.0
1051cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/39610
1061cb0ef41Sopenharmony_ci    description: The `options` object now accepts a `tries` option.
1071cb0ef41Sopenharmony_ci  - version: v12.18.3
1081cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/33472
1091cb0ef41Sopenharmony_ci    description: The constructor now accepts an `options` object.
1101cb0ef41Sopenharmony_ci                 The single supported option is `timeout`.
1111cb0ef41Sopenharmony_ci-->
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ciCreate a new resolver.
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci* `options` {Object}
1161cb0ef41Sopenharmony_ci  * `timeout` {integer} Query timeout in milliseconds, or `-1` to use the
1171cb0ef41Sopenharmony_ci    default timeout.
1181cb0ef41Sopenharmony_ci  * `tries` {integer} The number of tries the resolver will try contacting
1191cb0ef41Sopenharmony_ci    each name server before giving up. **Default:** `4`
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci### `resolver.cancel()`
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci<!-- YAML
1241cb0ef41Sopenharmony_ciadded: v8.3.0
1251cb0ef41Sopenharmony_ci-->
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_ciCancel all outstanding DNS queries made by this resolver. The corresponding
1281cb0ef41Sopenharmony_cicallbacks will be called with an error with code `ECANCELLED`.
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci### `resolver.setLocalAddress([ipv4][, ipv6])`
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ci<!-- YAML
1331cb0ef41Sopenharmony_ciadded:
1341cb0ef41Sopenharmony_ci  - v15.1.0
1351cb0ef41Sopenharmony_ci  - v14.17.0
1361cb0ef41Sopenharmony_ci-->
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ci* `ipv4` {string} A string representation of an IPv4 address.
1391cb0ef41Sopenharmony_ci  **Default:** `'0.0.0.0'`
1401cb0ef41Sopenharmony_ci* `ipv6` {string} A string representation of an IPv6 address.
1411cb0ef41Sopenharmony_ci  **Default:** `'::0'`
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ciThe resolver instance will send its requests from the specified IP address.
1441cb0ef41Sopenharmony_ciThis allows programs to specify outbound interfaces when used on multi-homed
1451cb0ef41Sopenharmony_cisystems.
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ciIf a v4 or v6 address is not specified, it is set to the default and the
1481cb0ef41Sopenharmony_cioperating system will choose a local address automatically.
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ciThe resolver will use the v4 local address when making requests to IPv4 DNS
1511cb0ef41Sopenharmony_ciservers, and the v6 local address when making requests to IPv6 DNS servers.
1521cb0ef41Sopenharmony_ciThe `rrtype` of resolution requests has no impact on the local address used.
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci## `dns.getServers()`
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_ci<!-- YAML
1571cb0ef41Sopenharmony_ciadded: v0.11.3
1581cb0ef41Sopenharmony_ci-->
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_ci* Returns: {string\[]}
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ciReturns an array of IP address strings, formatted according to [RFC 5952][],
1631cb0ef41Sopenharmony_cithat are currently configured for DNS resolution. A string will include a port
1641cb0ef41Sopenharmony_cisection if a custom port is used.
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ci<!-- eslint-disable semi-->
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ci```js
1691cb0ef41Sopenharmony_ci[
1701cb0ef41Sopenharmony_ci  '4.4.4.4',
1711cb0ef41Sopenharmony_ci  '2001:4860:4860::8888',
1721cb0ef41Sopenharmony_ci  '4.4.4.4:1053',
1731cb0ef41Sopenharmony_ci  '[2001:4860:4860::8888]:1053',
1741cb0ef41Sopenharmony_ci]
1751cb0ef41Sopenharmony_ci```
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ci## `dns.lookup(hostname[, options], callback)`
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_ci<!-- YAML
1801cb0ef41Sopenharmony_ciadded: v0.1.90
1811cb0ef41Sopenharmony_cichanges:
1821cb0ef41Sopenharmony_ci  - version: v18.4.0
1831cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/43054
1841cb0ef41Sopenharmony_ci    description: For compatibility with `node:net`, when passing an option
1851cb0ef41Sopenharmony_ci                 object the `family` option can be the string `'IPv4'` or the
1861cb0ef41Sopenharmony_ci                 string `'IPv6'`.
1871cb0ef41Sopenharmony_ci  - version: v18.0.0
1881cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
1891cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
1901cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
1911cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
1921cb0ef41Sopenharmony_ci  - version: v17.0.0
1931cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/39987
1941cb0ef41Sopenharmony_ci    description: The `verbatim` options defaults to `true` now.
1951cb0ef41Sopenharmony_ci  - version: v8.5.0
1961cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/14731
1971cb0ef41Sopenharmony_ci    description: The `verbatim` option is supported now.
1981cb0ef41Sopenharmony_ci  - version: v1.2.0
1991cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/744
2001cb0ef41Sopenharmony_ci    description: The `all` option is supported now.
2011cb0ef41Sopenharmony_ci-->
2021cb0ef41Sopenharmony_ci
2031cb0ef41Sopenharmony_ci* `hostname` {string}
2041cb0ef41Sopenharmony_ci* `options` {integer | Object}
2051cb0ef41Sopenharmony_ci  * `family` {integer|string} The record family. Must be `4`, `6`, or `0`. For
2061cb0ef41Sopenharmony_ci    backward compatibility reasons,`'IPv4'` and `'IPv6'` are interpreted as `4`
2071cb0ef41Sopenharmony_ci    and `6` respectively. The value `0` indicates that IPv4 and IPv6 addresses
2081cb0ef41Sopenharmony_ci    are both returned. **Default:** `0`.
2091cb0ef41Sopenharmony_ci  * `hints` {number} One or more [supported `getaddrinfo` flags][]. Multiple
2101cb0ef41Sopenharmony_ci    flags may be passed by bitwise `OR`ing their values.
2111cb0ef41Sopenharmony_ci  * `all` {boolean} When `true`, the callback returns all resolved addresses in
2121cb0ef41Sopenharmony_ci    an array. Otherwise, returns a single address. **Default:** `false`.
2131cb0ef41Sopenharmony_ci  * `verbatim` {boolean} When `true`, the callback receives IPv4 and IPv6
2141cb0ef41Sopenharmony_ci    addresses in the order the DNS resolver returned them. When `false`,
2151cb0ef41Sopenharmony_ci    IPv4 addresses are placed before IPv6 addresses.
2161cb0ef41Sopenharmony_ci    **Default:** `true` (addresses are not reordered). Default value is
2171cb0ef41Sopenharmony_ci    configurable using [`dns.setDefaultResultOrder()`][] or
2181cb0ef41Sopenharmony_ci    [`--dns-result-order`][].
2191cb0ef41Sopenharmony_ci* `callback` {Function}
2201cb0ef41Sopenharmony_ci  * `err` {Error}
2211cb0ef41Sopenharmony_ci  * `address` {string} A string representation of an IPv4 or IPv6 address.
2221cb0ef41Sopenharmony_ci  * `family` {integer} `4` or `6`, denoting the family of `address`, or `0` if
2231cb0ef41Sopenharmony_ci    the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a
2241cb0ef41Sopenharmony_ci    bug in the name resolution service used by the operating system.
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ciResolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
2271cb0ef41Sopenharmony_ciAAAA (IPv6) record. All `option` properties are optional. If `options` is an
2281cb0ef41Sopenharmony_ciinteger, then it must be `4` or `6` – if `options` is `0` or not provided, then
2291cb0ef41Sopenharmony_ciIPv4 and IPv6 addresses are both returned if found.
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ciWith the `all` option set to `true`, the arguments for `callback` change to
2321cb0ef41Sopenharmony_ci`(err, addresses)`, with `addresses` being an array of objects with the
2331cb0ef41Sopenharmony_ciproperties `address` and `family`.
2341cb0ef41Sopenharmony_ci
2351cb0ef41Sopenharmony_ciOn error, `err` is an [`Error`][] object, where `err.code` is the error code.
2361cb0ef41Sopenharmony_ciKeep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
2371cb0ef41Sopenharmony_cithe host name does not exist but also when the lookup fails in other ways
2381cb0ef41Sopenharmony_cisuch as no available file descriptors.
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ci`dns.lookup()` does not necessarily have anything to do with the DNS protocol.
2411cb0ef41Sopenharmony_ciThe implementation uses an operating system facility that can associate names
2421cb0ef41Sopenharmony_ciwith addresses and vice versa. This implementation can have subtle but
2431cb0ef41Sopenharmony_ciimportant consequences on the behavior of any Node.js program. Please take some
2441cb0ef41Sopenharmony_citime to consult the [Implementation considerations section][] before using
2451cb0ef41Sopenharmony_ci`dns.lookup()`.
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_ciExample usage:
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci```js
2501cb0ef41Sopenharmony_ciconst dns = require('node:dns');
2511cb0ef41Sopenharmony_ciconst options = {
2521cb0ef41Sopenharmony_ci  family: 6,
2531cb0ef41Sopenharmony_ci  hints: dns.ADDRCONFIG | dns.V4MAPPED,
2541cb0ef41Sopenharmony_ci};
2551cb0ef41Sopenharmony_cidns.lookup('example.com', options, (err, address, family) =>
2561cb0ef41Sopenharmony_ci  console.log('address: %j family: IPv%s', address, family));
2571cb0ef41Sopenharmony_ci// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci// When options.all is true, the result will be an Array.
2601cb0ef41Sopenharmony_cioptions.all = true;
2611cb0ef41Sopenharmony_cidns.lookup('example.com', options, (err, addresses) =>
2621cb0ef41Sopenharmony_ci  console.log('addresses: %j', addresses));
2631cb0ef41Sopenharmony_ci// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
2641cb0ef41Sopenharmony_ci```
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ciIf this method is invoked as its [`util.promisify()`][]ed version, and `all`
2671cb0ef41Sopenharmony_ciis not set to `true`, it returns a `Promise` for an `Object` with `address` and
2681cb0ef41Sopenharmony_ci`family` properties.
2691cb0ef41Sopenharmony_ci
2701cb0ef41Sopenharmony_ci### Supported getaddrinfo flags
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci<!-- YAML
2731cb0ef41Sopenharmony_cichanges:
2741cb0ef41Sopenharmony_ci  - version:
2751cb0ef41Sopenharmony_ci     - v13.13.0
2761cb0ef41Sopenharmony_ci     - v12.17.0
2771cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/32183
2781cb0ef41Sopenharmony_ci    description: Added support for the `dns.ALL` flag.
2791cb0ef41Sopenharmony_ci-->
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ciThe following flags can be passed as hints to [`dns.lookup()`][].
2821cb0ef41Sopenharmony_ci
2831cb0ef41Sopenharmony_ci* `dns.ADDRCONFIG`: Limits returned address types to the types of non-loopback
2841cb0ef41Sopenharmony_ci  addresses configured on the system. For example, IPv4 addresses are only
2851cb0ef41Sopenharmony_ci  returned if the current system has at least one IPv4 address configured.
2861cb0ef41Sopenharmony_ci* `dns.V4MAPPED`: If the IPv6 family was specified, but no IPv6 addresses were
2871cb0ef41Sopenharmony_ci  found, then return IPv4 mapped IPv6 addresses. It is not supported
2881cb0ef41Sopenharmony_ci  on some operating systems (e.g. FreeBSD 10.1).
2891cb0ef41Sopenharmony_ci* `dns.ALL`: If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as
2901cb0ef41Sopenharmony_ci  well as IPv4 mapped IPv6 addresses.
2911cb0ef41Sopenharmony_ci
2921cb0ef41Sopenharmony_ci## `dns.lookupService(address, port, callback)`
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ci<!-- YAML
2951cb0ef41Sopenharmony_ciadded: v0.11.14
2961cb0ef41Sopenharmony_cichanges:
2971cb0ef41Sopenharmony_ci  - version: v18.0.0
2981cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
2991cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
3001cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
3011cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
3021cb0ef41Sopenharmony_ci-->
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ci* `address` {string}
3051cb0ef41Sopenharmony_ci* `port` {number}
3061cb0ef41Sopenharmony_ci* `callback` {Function}
3071cb0ef41Sopenharmony_ci  * `err` {Error}
3081cb0ef41Sopenharmony_ci  * `hostname` {string} e.g. `example.com`
3091cb0ef41Sopenharmony_ci  * `service` {string} e.g. `http`
3101cb0ef41Sopenharmony_ci
3111cb0ef41Sopenharmony_ciResolves the given `address` and `port` into a host name and service using
3121cb0ef41Sopenharmony_cithe operating system's underlying `getnameinfo` implementation.
3131cb0ef41Sopenharmony_ci
3141cb0ef41Sopenharmony_ciIf `address` is not a valid IP address, a `TypeError` will be thrown.
3151cb0ef41Sopenharmony_ciThe `port` will be coerced to a number. If it is not a legal port, a `TypeError`
3161cb0ef41Sopenharmony_ciwill be thrown.
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ciOn an error, `err` is an [`Error`][] object, where `err.code` is the error code.
3191cb0ef41Sopenharmony_ci
3201cb0ef41Sopenharmony_ci```js
3211cb0ef41Sopenharmony_ciconst dns = require('node:dns');
3221cb0ef41Sopenharmony_cidns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
3231cb0ef41Sopenharmony_ci  console.log(hostname, service);
3241cb0ef41Sopenharmony_ci  // Prints: localhost ssh
3251cb0ef41Sopenharmony_ci});
3261cb0ef41Sopenharmony_ci```
3271cb0ef41Sopenharmony_ci
3281cb0ef41Sopenharmony_ciIf this method is invoked as its [`util.promisify()`][]ed version, it returns a
3291cb0ef41Sopenharmony_ci`Promise` for an `Object` with `hostname` and `service` properties.
3301cb0ef41Sopenharmony_ci
3311cb0ef41Sopenharmony_ci## `dns.resolve(hostname[, rrtype], callback)`
3321cb0ef41Sopenharmony_ci
3331cb0ef41Sopenharmony_ci<!-- YAML
3341cb0ef41Sopenharmony_ciadded: v0.1.27
3351cb0ef41Sopenharmony_cichanges:
3361cb0ef41Sopenharmony_ci  - version: v18.0.0
3371cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
3381cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
3391cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
3401cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
3411cb0ef41Sopenharmony_ci-->
3421cb0ef41Sopenharmony_ci
3431cb0ef41Sopenharmony_ci* `hostname` {string} Host name to resolve.
3441cb0ef41Sopenharmony_ci* `rrtype` {string} Resource record type. **Default:** `'A'`.
3451cb0ef41Sopenharmony_ci* `callback` {Function}
3461cb0ef41Sopenharmony_ci  * `err` {Error}
3471cb0ef41Sopenharmony_ci  * `records` {string\[] | Object\[] | Object}
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_ciUses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
3501cb0ef41Sopenharmony_ciof the resource records. The `callback` function has arguments
3511cb0ef41Sopenharmony_ci`(err, records)`. When successful, `records` will be an array of resource
3521cb0ef41Sopenharmony_cirecords. The type and structure of individual results varies based on `rrtype`:
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci| `rrtype`  | `records` contains             | Result type | Shorthand method         |
3551cb0ef41Sopenharmony_ci| --------- | ------------------------------ | ----------- | ------------------------ |
3561cb0ef41Sopenharmony_ci| `'A'`     | IPv4 addresses (default)       | {string}    | [`dns.resolve4()`][]     |
3571cb0ef41Sopenharmony_ci| `'AAAA'`  | IPv6 addresses                 | {string}    | [`dns.resolve6()`][]     |
3581cb0ef41Sopenharmony_ci| `'ANY'`   | any records                    | {Object}    | [`dns.resolveAny()`][]   |
3591cb0ef41Sopenharmony_ci| `'CAA'`   | CA authorization records       | {Object}    | [`dns.resolveCaa()`][]   |
3601cb0ef41Sopenharmony_ci| `'CNAME'` | canonical name records         | {string}    | [`dns.resolveCname()`][] |
3611cb0ef41Sopenharmony_ci| `'MX'`    | mail exchange records          | {Object}    | [`dns.resolveMx()`][]    |
3621cb0ef41Sopenharmony_ci| `'NAPTR'` | name authority pointer records | {Object}    | [`dns.resolveNaptr()`][] |
3631cb0ef41Sopenharmony_ci| `'NS'`    | name server records            | {string}    | [`dns.resolveNs()`][]    |
3641cb0ef41Sopenharmony_ci| `'PTR'`   | pointer records                | {string}    | [`dns.resolvePtr()`][]   |
3651cb0ef41Sopenharmony_ci| `'SOA'`   | start of authority records     | {Object}    | [`dns.resolveSoa()`][]   |
3661cb0ef41Sopenharmony_ci| `'SRV'`   | service records                | {Object}    | [`dns.resolveSrv()`][]   |
3671cb0ef41Sopenharmony_ci| `'TXT'`   | text records                   | {string\[]} | [`dns.resolveTxt()`][]   |
3681cb0ef41Sopenharmony_ci
3691cb0ef41Sopenharmony_ciOn error, `err` is an [`Error`][] object, where `err.code` is one of the
3701cb0ef41Sopenharmony_ci[DNS error codes][].
3711cb0ef41Sopenharmony_ci
3721cb0ef41Sopenharmony_ci## `dns.resolve4(hostname[, options], callback)`
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci<!-- YAML
3751cb0ef41Sopenharmony_ciadded: v0.1.16
3761cb0ef41Sopenharmony_cichanges:
3771cb0ef41Sopenharmony_ci  - version: v18.0.0
3781cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
3791cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
3801cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
3811cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
3821cb0ef41Sopenharmony_ci  - version: v7.2.0
3831cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/9296
3841cb0ef41Sopenharmony_ci    description: This method now supports passing `options`,
3851cb0ef41Sopenharmony_ci                 specifically `options.ttl`.
3861cb0ef41Sopenharmony_ci-->
3871cb0ef41Sopenharmony_ci
3881cb0ef41Sopenharmony_ci* `hostname` {string} Host name to resolve.
3891cb0ef41Sopenharmony_ci* `options` {Object}
3901cb0ef41Sopenharmony_ci  * `ttl` {boolean} Retrieves the Time-To-Live value (TTL) of each record.
3911cb0ef41Sopenharmony_ci    When `true`, the callback receives an array of
3921cb0ef41Sopenharmony_ci    `{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings,
3931cb0ef41Sopenharmony_ci    with the TTL expressed in seconds.
3941cb0ef41Sopenharmony_ci* `callback` {Function}
3951cb0ef41Sopenharmony_ci  * `err` {Error}
3961cb0ef41Sopenharmony_ci  * `addresses` {string\[] | Object\[]}
3971cb0ef41Sopenharmony_ci
3981cb0ef41Sopenharmony_ciUses the DNS protocol to resolve a IPv4 addresses (`A` records) for the
3991cb0ef41Sopenharmony_ci`hostname`. The `addresses` argument passed to the `callback` function
4001cb0ef41Sopenharmony_ciwill contain an array of IPv4 addresses (e.g.
4011cb0ef41Sopenharmony_ci`['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
4021cb0ef41Sopenharmony_ci
4031cb0ef41Sopenharmony_ci## `dns.resolve6(hostname[, options], callback)`
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci<!-- YAML
4061cb0ef41Sopenharmony_ciadded: v0.1.16
4071cb0ef41Sopenharmony_cichanges:
4081cb0ef41Sopenharmony_ci  - version: v18.0.0
4091cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
4101cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
4111cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
4121cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
4131cb0ef41Sopenharmony_ci  - version: v7.2.0
4141cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/9296
4151cb0ef41Sopenharmony_ci    description: This method now supports passing `options`,
4161cb0ef41Sopenharmony_ci                 specifically `options.ttl`.
4171cb0ef41Sopenharmony_ci-->
4181cb0ef41Sopenharmony_ci
4191cb0ef41Sopenharmony_ci* `hostname` {string} Host name to resolve.
4201cb0ef41Sopenharmony_ci* `options` {Object}
4211cb0ef41Sopenharmony_ci  * `ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record.
4221cb0ef41Sopenharmony_ci    When `true`, the callback receives an array of
4231cb0ef41Sopenharmony_ci    `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of
4241cb0ef41Sopenharmony_ci    strings, with the TTL expressed in seconds.
4251cb0ef41Sopenharmony_ci* `callback` {Function}
4261cb0ef41Sopenharmony_ci  * `err` {Error}
4271cb0ef41Sopenharmony_ci  * `addresses` {string\[] | Object\[]}
4281cb0ef41Sopenharmony_ci
4291cb0ef41Sopenharmony_ciUses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the
4301cb0ef41Sopenharmony_ci`hostname`. The `addresses` argument passed to the `callback` function
4311cb0ef41Sopenharmony_ciwill contain an array of IPv6 addresses.
4321cb0ef41Sopenharmony_ci
4331cb0ef41Sopenharmony_ci## `dns.resolveAny(hostname, callback)`
4341cb0ef41Sopenharmony_ci
4351cb0ef41Sopenharmony_ci<!-- YAML
4361cb0ef41Sopenharmony_cichanges:
4371cb0ef41Sopenharmony_ci  - version: v18.0.0
4381cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
4391cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
4401cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
4411cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
4421cb0ef41Sopenharmony_ci-->
4431cb0ef41Sopenharmony_ci
4441cb0ef41Sopenharmony_ci* `hostname` {string}
4451cb0ef41Sopenharmony_ci* `callback` {Function}
4461cb0ef41Sopenharmony_ci  * `err` {Error}
4471cb0ef41Sopenharmony_ci  * `ret` {Object\[]}
4481cb0ef41Sopenharmony_ci
4491cb0ef41Sopenharmony_ciUses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
4501cb0ef41Sopenharmony_ciThe `ret` argument passed to the `callback` function will be an array containing
4511cb0ef41Sopenharmony_civarious types of records. Each object has a property `type` that indicates the
4521cb0ef41Sopenharmony_citype of the current record. And depending on the `type`, additional properties
4531cb0ef41Sopenharmony_ciwill be present on the object:
4541cb0ef41Sopenharmony_ci
4551cb0ef41Sopenharmony_ci| Type      | Properties                                                                                                                                       |
4561cb0ef41Sopenharmony_ci| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
4571cb0ef41Sopenharmony_ci| `'A'`     | `address`/`ttl`                                                                                                                                  |
4581cb0ef41Sopenharmony_ci| `'AAAA'`  | `address`/`ttl`                                                                                                                                  |
4591cb0ef41Sopenharmony_ci| `'CNAME'` | `value`                                                                                                                                          |
4601cb0ef41Sopenharmony_ci| `'MX'`    | Refer to [`dns.resolveMx()`][]                                                                                                                   |
4611cb0ef41Sopenharmony_ci| `'NAPTR'` | Refer to [`dns.resolveNaptr()`][]                                                                                                                |
4621cb0ef41Sopenharmony_ci| `'NS'`    | `value`                                                                                                                                          |
4631cb0ef41Sopenharmony_ci| `'PTR'`   | `value`                                                                                                                                          |
4641cb0ef41Sopenharmony_ci| `'SOA'`   | Refer to [`dns.resolveSoa()`][]                                                                                                                  |
4651cb0ef41Sopenharmony_ci| `'SRV'`   | Refer to [`dns.resolveSrv()`][]                                                                                                                  |
4661cb0ef41Sopenharmony_ci| `'TXT'`   | This type of record contains an array property called `entries` which refers to [`dns.resolveTxt()`][], e.g. `{ entries: ['...'], type: 'TXT' }` |
4671cb0ef41Sopenharmony_ci
4681cb0ef41Sopenharmony_ciHere is an example of the `ret` object passed to the callback:
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
4711cb0ef41Sopenharmony_ci
4721cb0ef41Sopenharmony_ci```js
4731cb0ef41Sopenharmony_ci[ { type: 'A', address: '127.0.0.1', ttl: 299 },
4741cb0ef41Sopenharmony_ci  { type: 'CNAME', value: 'example.com' },
4751cb0ef41Sopenharmony_ci  { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
4761cb0ef41Sopenharmony_ci  { type: 'NS', value: 'ns1.example.com' },
4771cb0ef41Sopenharmony_ci  { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
4781cb0ef41Sopenharmony_ci  { type: 'SOA',
4791cb0ef41Sopenharmony_ci    nsname: 'ns1.example.com',
4801cb0ef41Sopenharmony_ci    hostmaster: 'admin.example.com',
4811cb0ef41Sopenharmony_ci    serial: 156696742,
4821cb0ef41Sopenharmony_ci    refresh: 900,
4831cb0ef41Sopenharmony_ci    retry: 900,
4841cb0ef41Sopenharmony_ci    expire: 1800,
4851cb0ef41Sopenharmony_ci    minttl: 60 } ]
4861cb0ef41Sopenharmony_ci```
4871cb0ef41Sopenharmony_ci
4881cb0ef41Sopenharmony_ciDNS server operators may choose not to respond to `ANY`
4891cb0ef41Sopenharmony_ciqueries. It may be better to call individual methods like [`dns.resolve4()`][],
4901cb0ef41Sopenharmony_ci[`dns.resolveMx()`][], and so on. For more details, see [RFC 8482][].
4911cb0ef41Sopenharmony_ci
4921cb0ef41Sopenharmony_ci## `dns.resolveCname(hostname, callback)`
4931cb0ef41Sopenharmony_ci
4941cb0ef41Sopenharmony_ci<!-- YAML
4951cb0ef41Sopenharmony_ciadded: v0.3.2
4961cb0ef41Sopenharmony_cichanges:
4971cb0ef41Sopenharmony_ci  - version: v18.0.0
4981cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
4991cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
5001cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
5011cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
5021cb0ef41Sopenharmony_ci-->
5031cb0ef41Sopenharmony_ci
5041cb0ef41Sopenharmony_ci* `hostname` {string}
5051cb0ef41Sopenharmony_ci* `callback` {Function}
5061cb0ef41Sopenharmony_ci  * `err` {Error}
5071cb0ef41Sopenharmony_ci  * `addresses` {string\[]}
5081cb0ef41Sopenharmony_ci
5091cb0ef41Sopenharmony_ciUses the DNS protocol to resolve `CNAME` records for the `hostname`. The
5101cb0ef41Sopenharmony_ci`addresses` argument passed to the `callback` function
5111cb0ef41Sopenharmony_ciwill contain an array of canonical name records available for the `hostname`
5121cb0ef41Sopenharmony_ci(e.g. `['bar.example.com']`).
5131cb0ef41Sopenharmony_ci
5141cb0ef41Sopenharmony_ci## `dns.resolveCaa(hostname, callback)`
5151cb0ef41Sopenharmony_ci
5161cb0ef41Sopenharmony_ci<!-- YAML
5171cb0ef41Sopenharmony_ciadded:
5181cb0ef41Sopenharmony_ci  - v15.0.0
5191cb0ef41Sopenharmony_ci  - v14.17.0
5201cb0ef41Sopenharmony_cichanges:
5211cb0ef41Sopenharmony_ci  - version: v18.0.0
5221cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
5231cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
5241cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
5251cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
5261cb0ef41Sopenharmony_ci-->
5271cb0ef41Sopenharmony_ci
5281cb0ef41Sopenharmony_ci* `hostname` {string}
5291cb0ef41Sopenharmony_ci* `callback` {Function}
5301cb0ef41Sopenharmony_ci  * `err` {Error}
5311cb0ef41Sopenharmony_ci  * `records` {Object\[]}
5321cb0ef41Sopenharmony_ci
5331cb0ef41Sopenharmony_ciUses the DNS protocol to resolve `CAA` records for the `hostname`. The
5341cb0ef41Sopenharmony_ci`addresses` argument passed to the `callback` function
5351cb0ef41Sopenharmony_ciwill contain an array of certification authority authorization records
5361cb0ef41Sopenharmony_ciavailable for the `hostname` (e.g. `[{critical: 0, iodef:
5371cb0ef41Sopenharmony_ci'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]`).
5381cb0ef41Sopenharmony_ci
5391cb0ef41Sopenharmony_ci## `dns.resolveMx(hostname, callback)`
5401cb0ef41Sopenharmony_ci
5411cb0ef41Sopenharmony_ci<!-- YAML
5421cb0ef41Sopenharmony_ciadded: v0.1.27
5431cb0ef41Sopenharmony_cichanges:
5441cb0ef41Sopenharmony_ci  - version: v18.0.0
5451cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
5461cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
5471cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
5481cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
5491cb0ef41Sopenharmony_ci-->
5501cb0ef41Sopenharmony_ci
5511cb0ef41Sopenharmony_ci* `hostname` {string}
5521cb0ef41Sopenharmony_ci* `callback` {Function}
5531cb0ef41Sopenharmony_ci  * `err` {Error}
5541cb0ef41Sopenharmony_ci  * `addresses` {Object\[]}
5551cb0ef41Sopenharmony_ci
5561cb0ef41Sopenharmony_ciUses the DNS protocol to resolve mail exchange records (`MX` records) for the
5571cb0ef41Sopenharmony_ci`hostname`. The `addresses` argument passed to the `callback` function will
5581cb0ef41Sopenharmony_cicontain an array of objects containing both a `priority` and `exchange`
5591cb0ef41Sopenharmony_ciproperty (e.g. `[{priority: 10, exchange: 'mx.example.com'}, ...]`).
5601cb0ef41Sopenharmony_ci
5611cb0ef41Sopenharmony_ci## `dns.resolveNaptr(hostname, callback)`
5621cb0ef41Sopenharmony_ci
5631cb0ef41Sopenharmony_ci<!-- YAML
5641cb0ef41Sopenharmony_ciadded: v0.9.12
5651cb0ef41Sopenharmony_cichanges:
5661cb0ef41Sopenharmony_ci  - version: v18.0.0
5671cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
5681cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
5691cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
5701cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
5711cb0ef41Sopenharmony_ci-->
5721cb0ef41Sopenharmony_ci
5731cb0ef41Sopenharmony_ci* `hostname` {string}
5741cb0ef41Sopenharmony_ci* `callback` {Function}
5751cb0ef41Sopenharmony_ci  * `err` {Error}
5761cb0ef41Sopenharmony_ci  * `addresses` {Object\[]}
5771cb0ef41Sopenharmony_ci
5781cb0ef41Sopenharmony_ciUses the DNS protocol to resolve regular expression-based records (`NAPTR`
5791cb0ef41Sopenharmony_cirecords) for the `hostname`. The `addresses` argument passed to the `callback`
5801cb0ef41Sopenharmony_cifunction will contain an array of objects with the following properties:
5811cb0ef41Sopenharmony_ci
5821cb0ef41Sopenharmony_ci* `flags`
5831cb0ef41Sopenharmony_ci* `service`
5841cb0ef41Sopenharmony_ci* `regexp`
5851cb0ef41Sopenharmony_ci* `replacement`
5861cb0ef41Sopenharmony_ci* `order`
5871cb0ef41Sopenharmony_ci* `preference`
5881cb0ef41Sopenharmony_ci
5891cb0ef41Sopenharmony_ci<!-- eslint-skip -->
5901cb0ef41Sopenharmony_ci
5911cb0ef41Sopenharmony_ci```js
5921cb0ef41Sopenharmony_ci{
5931cb0ef41Sopenharmony_ci  flags: 's',
5941cb0ef41Sopenharmony_ci  service: 'SIP+D2U',
5951cb0ef41Sopenharmony_ci  regexp: '',
5961cb0ef41Sopenharmony_ci  replacement: '_sip._udp.example.com',
5971cb0ef41Sopenharmony_ci  order: 30,
5981cb0ef41Sopenharmony_ci  preference: 100
5991cb0ef41Sopenharmony_ci}
6001cb0ef41Sopenharmony_ci```
6011cb0ef41Sopenharmony_ci
6021cb0ef41Sopenharmony_ci## `dns.resolveNs(hostname, callback)`
6031cb0ef41Sopenharmony_ci
6041cb0ef41Sopenharmony_ci<!-- YAML
6051cb0ef41Sopenharmony_ciadded: v0.1.90
6061cb0ef41Sopenharmony_cichanges:
6071cb0ef41Sopenharmony_ci  - version: v18.0.0
6081cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
6091cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
6101cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
6111cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
6121cb0ef41Sopenharmony_ci-->
6131cb0ef41Sopenharmony_ci
6141cb0ef41Sopenharmony_ci* `hostname` {string}
6151cb0ef41Sopenharmony_ci* `callback` {Function}
6161cb0ef41Sopenharmony_ci  * `err` {Error}
6171cb0ef41Sopenharmony_ci  * `addresses` {string\[]}
6181cb0ef41Sopenharmony_ci
6191cb0ef41Sopenharmony_ciUses the DNS protocol to resolve name server records (`NS` records) for the
6201cb0ef41Sopenharmony_ci`hostname`. The `addresses` argument passed to the `callback` function will
6211cb0ef41Sopenharmony_cicontain an array of name server records available for `hostname`
6221cb0ef41Sopenharmony_ci(e.g. `['ns1.example.com', 'ns2.example.com']`).
6231cb0ef41Sopenharmony_ci
6241cb0ef41Sopenharmony_ci## `dns.resolvePtr(hostname, callback)`
6251cb0ef41Sopenharmony_ci
6261cb0ef41Sopenharmony_ci<!-- YAML
6271cb0ef41Sopenharmony_ciadded: v6.0.0
6281cb0ef41Sopenharmony_cichanges:
6291cb0ef41Sopenharmony_ci  - version: v18.0.0
6301cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
6311cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
6321cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
6331cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
6341cb0ef41Sopenharmony_ci-->
6351cb0ef41Sopenharmony_ci
6361cb0ef41Sopenharmony_ci* `hostname` {string}
6371cb0ef41Sopenharmony_ci* `callback` {Function}
6381cb0ef41Sopenharmony_ci  * `err` {Error}
6391cb0ef41Sopenharmony_ci  * `addresses` {string\[]}
6401cb0ef41Sopenharmony_ci
6411cb0ef41Sopenharmony_ciUses the DNS protocol to resolve pointer records (`PTR` records) for the
6421cb0ef41Sopenharmony_ci`hostname`. The `addresses` argument passed to the `callback` function will
6431cb0ef41Sopenharmony_cibe an array of strings containing the reply records.
6441cb0ef41Sopenharmony_ci
6451cb0ef41Sopenharmony_ci## `dns.resolveSoa(hostname, callback)`
6461cb0ef41Sopenharmony_ci
6471cb0ef41Sopenharmony_ci<!-- YAML
6481cb0ef41Sopenharmony_ciadded: v0.11.10
6491cb0ef41Sopenharmony_cichanges:
6501cb0ef41Sopenharmony_ci  - version: v18.0.0
6511cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
6521cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
6531cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
6541cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
6551cb0ef41Sopenharmony_ci-->
6561cb0ef41Sopenharmony_ci
6571cb0ef41Sopenharmony_ci* `hostname` {string}
6581cb0ef41Sopenharmony_ci* `callback` {Function}
6591cb0ef41Sopenharmony_ci  * `err` {Error}
6601cb0ef41Sopenharmony_ci  * `address` {Object}
6611cb0ef41Sopenharmony_ci
6621cb0ef41Sopenharmony_ciUses the DNS protocol to resolve a start of authority record (`SOA` record) for
6631cb0ef41Sopenharmony_cithe `hostname`. The `address` argument passed to the `callback` function will
6641cb0ef41Sopenharmony_cibe an object with the following properties:
6651cb0ef41Sopenharmony_ci
6661cb0ef41Sopenharmony_ci* `nsname`
6671cb0ef41Sopenharmony_ci* `hostmaster`
6681cb0ef41Sopenharmony_ci* `serial`
6691cb0ef41Sopenharmony_ci* `refresh`
6701cb0ef41Sopenharmony_ci* `retry`
6711cb0ef41Sopenharmony_ci* `expire`
6721cb0ef41Sopenharmony_ci* `minttl`
6731cb0ef41Sopenharmony_ci
6741cb0ef41Sopenharmony_ci<!-- eslint-skip -->
6751cb0ef41Sopenharmony_ci
6761cb0ef41Sopenharmony_ci```js
6771cb0ef41Sopenharmony_ci{
6781cb0ef41Sopenharmony_ci  nsname: 'ns.example.com',
6791cb0ef41Sopenharmony_ci  hostmaster: 'root.example.com',
6801cb0ef41Sopenharmony_ci  serial: 2013101809,
6811cb0ef41Sopenharmony_ci  refresh: 10000,
6821cb0ef41Sopenharmony_ci  retry: 2400,
6831cb0ef41Sopenharmony_ci  expire: 604800,
6841cb0ef41Sopenharmony_ci  minttl: 3600
6851cb0ef41Sopenharmony_ci}
6861cb0ef41Sopenharmony_ci```
6871cb0ef41Sopenharmony_ci
6881cb0ef41Sopenharmony_ci## `dns.resolveSrv(hostname, callback)`
6891cb0ef41Sopenharmony_ci
6901cb0ef41Sopenharmony_ci<!-- YAML
6911cb0ef41Sopenharmony_ciadded: v0.1.27
6921cb0ef41Sopenharmony_cichanges:
6931cb0ef41Sopenharmony_ci  - version: v18.0.0
6941cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
6951cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
6961cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
6971cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
6981cb0ef41Sopenharmony_ci-->
6991cb0ef41Sopenharmony_ci
7001cb0ef41Sopenharmony_ci* `hostname` {string}
7011cb0ef41Sopenharmony_ci* `callback` {Function}
7021cb0ef41Sopenharmony_ci  * `err` {Error}
7031cb0ef41Sopenharmony_ci  * `addresses` {Object\[]}
7041cb0ef41Sopenharmony_ci
7051cb0ef41Sopenharmony_ciUses the DNS protocol to resolve service records (`SRV` records) for the
7061cb0ef41Sopenharmony_ci`hostname`. The `addresses` argument passed to the `callback` function will
7071cb0ef41Sopenharmony_cibe an array of objects with the following properties:
7081cb0ef41Sopenharmony_ci
7091cb0ef41Sopenharmony_ci* `priority`
7101cb0ef41Sopenharmony_ci* `weight`
7111cb0ef41Sopenharmony_ci* `port`
7121cb0ef41Sopenharmony_ci* `name`
7131cb0ef41Sopenharmony_ci
7141cb0ef41Sopenharmony_ci<!-- eslint-skip -->
7151cb0ef41Sopenharmony_ci
7161cb0ef41Sopenharmony_ci```js
7171cb0ef41Sopenharmony_ci{
7181cb0ef41Sopenharmony_ci  priority: 10,
7191cb0ef41Sopenharmony_ci  weight: 5,
7201cb0ef41Sopenharmony_ci  port: 21223,
7211cb0ef41Sopenharmony_ci  name: 'service.example.com'
7221cb0ef41Sopenharmony_ci}
7231cb0ef41Sopenharmony_ci```
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ci## `dns.resolveTxt(hostname, callback)`
7261cb0ef41Sopenharmony_ci
7271cb0ef41Sopenharmony_ci<!-- YAML
7281cb0ef41Sopenharmony_ciadded: v0.1.27
7291cb0ef41Sopenharmony_cichanges:
7301cb0ef41Sopenharmony_ci  - version: v18.0.0
7311cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/41678
7321cb0ef41Sopenharmony_ci    description: Passing an invalid callback to the `callback` argument
7331cb0ef41Sopenharmony_ci                 now throws `ERR_INVALID_ARG_TYPE` instead of
7341cb0ef41Sopenharmony_ci                 `ERR_INVALID_CALLBACK`.
7351cb0ef41Sopenharmony_ci-->
7361cb0ef41Sopenharmony_ci
7371cb0ef41Sopenharmony_ci<!--lint disable no-undefined-references list-item-bullet-indent-->
7381cb0ef41Sopenharmony_ci
7391cb0ef41Sopenharmony_ci* `hostname` {string}
7401cb0ef41Sopenharmony_ci* `callback` {Function}
7411cb0ef41Sopenharmony_ci  * `err` {Error}
7421cb0ef41Sopenharmony_ci  * `records` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">\<string\[]\[]></a>
7431cb0ef41Sopenharmony_ci
7441cb0ef41Sopenharmony_ci<!--lint enable no-undefined-references list-item-bullet-indent-->
7451cb0ef41Sopenharmony_ci
7461cb0ef41Sopenharmony_ciUses the DNS protocol to resolve text queries (`TXT` records) for the
7471cb0ef41Sopenharmony_ci`hostname`. The `records` argument passed to the `callback` function is a
7481cb0ef41Sopenharmony_citwo-dimensional array of the text records available for `hostname` (e.g.
7491cb0ef41Sopenharmony_ci`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
7501cb0ef41Sopenharmony_cione record. Depending on the use case, these could be either joined together or
7511cb0ef41Sopenharmony_citreated separately.
7521cb0ef41Sopenharmony_ci
7531cb0ef41Sopenharmony_ci## `dns.reverse(ip, callback)`
7541cb0ef41Sopenharmony_ci
7551cb0ef41Sopenharmony_ci<!-- YAML
7561cb0ef41Sopenharmony_ciadded: v0.1.16
7571cb0ef41Sopenharmony_ci-->
7581cb0ef41Sopenharmony_ci
7591cb0ef41Sopenharmony_ci* `ip` {string}
7601cb0ef41Sopenharmony_ci* `callback` {Function}
7611cb0ef41Sopenharmony_ci  * `err` {Error}
7621cb0ef41Sopenharmony_ci  * `hostnames` {string\[]}
7631cb0ef41Sopenharmony_ci
7641cb0ef41Sopenharmony_ciPerforms a reverse DNS query that resolves an IPv4 or IPv6 address to an
7651cb0ef41Sopenharmony_ciarray of host names.
7661cb0ef41Sopenharmony_ci
7671cb0ef41Sopenharmony_ciOn error, `err` is an [`Error`][] object, where `err.code` is
7681cb0ef41Sopenharmony_cione of the [DNS error codes][].
7691cb0ef41Sopenharmony_ci
7701cb0ef41Sopenharmony_ci## `dns.setDefaultResultOrder(order)`
7711cb0ef41Sopenharmony_ci
7721cb0ef41Sopenharmony_ci<!-- YAML
7731cb0ef41Sopenharmony_ciadded:
7741cb0ef41Sopenharmony_ci  - v16.4.0
7751cb0ef41Sopenharmony_ci  - v14.18.0
7761cb0ef41Sopenharmony_cichanges:
7771cb0ef41Sopenharmony_ci  - version: v17.0.0
7781cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/39987
7791cb0ef41Sopenharmony_ci    description: Changed default value to `verbatim`.
7801cb0ef41Sopenharmony_ci-->
7811cb0ef41Sopenharmony_ci
7821cb0ef41Sopenharmony_ci* `order` {string} must be `'ipv4first'` or `'verbatim'`.
7831cb0ef41Sopenharmony_ci
7841cb0ef41Sopenharmony_ciSet the default value of `verbatim` in [`dns.lookup()`][] and
7851cb0ef41Sopenharmony_ci[`dnsPromises.lookup()`][]. The value could be:
7861cb0ef41Sopenharmony_ci
7871cb0ef41Sopenharmony_ci* `ipv4first`: sets default `verbatim` `false`.
7881cb0ef41Sopenharmony_ci* `verbatim`: sets default `verbatim` `true`.
7891cb0ef41Sopenharmony_ci
7901cb0ef41Sopenharmony_ciThe default is `verbatim` and [`dns.setDefaultResultOrder()`][] have higher
7911cb0ef41Sopenharmony_cipriority than [`--dns-result-order`][]. When using [worker threads][],
7921cb0ef41Sopenharmony_ci[`dns.setDefaultResultOrder()`][] from the main thread won't affect the default
7931cb0ef41Sopenharmony_cidns orders in workers.
7941cb0ef41Sopenharmony_ci
7951cb0ef41Sopenharmony_ci## `dns.getDefaultResultOrder()`
7961cb0ef41Sopenharmony_ci
7971cb0ef41Sopenharmony_ci<!-- YAML
7981cb0ef41Sopenharmony_ciadded: v18.17.0
7991cb0ef41Sopenharmony_ci-->
8001cb0ef41Sopenharmony_ci
8011cb0ef41Sopenharmony_ciGet the default value for `verbatim` in [`dns.lookup()`][] and
8021cb0ef41Sopenharmony_ci[`dnsPromises.lookup()`][]. The value could be:
8031cb0ef41Sopenharmony_ci
8041cb0ef41Sopenharmony_ci* `ipv4first`: for `verbatim` defaulting to `false`.
8051cb0ef41Sopenharmony_ci* `verbatim`: for `verbatim` defaulting to `true`.
8061cb0ef41Sopenharmony_ci
8071cb0ef41Sopenharmony_ci## `dns.setServers(servers)`
8081cb0ef41Sopenharmony_ci
8091cb0ef41Sopenharmony_ci<!-- YAML
8101cb0ef41Sopenharmony_ciadded: v0.11.3
8111cb0ef41Sopenharmony_ci-->
8121cb0ef41Sopenharmony_ci
8131cb0ef41Sopenharmony_ci* `servers` {string\[]} array of [RFC 5952][] formatted addresses
8141cb0ef41Sopenharmony_ci
8151cb0ef41Sopenharmony_ciSets the IP address and port of servers to be used when performing DNS
8161cb0ef41Sopenharmony_ciresolution. The `servers` argument is an array of [RFC 5952][] formatted
8171cb0ef41Sopenharmony_ciaddresses. If the port is the IANA default DNS port (53) it can be omitted.
8181cb0ef41Sopenharmony_ci
8191cb0ef41Sopenharmony_ci```js
8201cb0ef41Sopenharmony_cidns.setServers([
8211cb0ef41Sopenharmony_ci  '4.4.4.4',
8221cb0ef41Sopenharmony_ci  '[2001:4860:4860::8888]',
8231cb0ef41Sopenharmony_ci  '4.4.4.4:1053',
8241cb0ef41Sopenharmony_ci  '[2001:4860:4860::8888]:1053',
8251cb0ef41Sopenharmony_ci]);
8261cb0ef41Sopenharmony_ci```
8271cb0ef41Sopenharmony_ci
8281cb0ef41Sopenharmony_ciAn error will be thrown if an invalid address is provided.
8291cb0ef41Sopenharmony_ci
8301cb0ef41Sopenharmony_ciThe `dns.setServers()` method must not be called while a DNS query is in
8311cb0ef41Sopenharmony_ciprogress.
8321cb0ef41Sopenharmony_ci
8331cb0ef41Sopenharmony_ciThe [`dns.setServers()`][] method affects only [`dns.resolve()`][],
8341cb0ef41Sopenharmony_ci`dns.resolve*()` and [`dns.reverse()`][] (and specifically _not_
8351cb0ef41Sopenharmony_ci[`dns.lookup()`][]).
8361cb0ef41Sopenharmony_ci
8371cb0ef41Sopenharmony_ciThis method works much like
8381cb0ef41Sopenharmony_ci[resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
8391cb0ef41Sopenharmony_ciThat is, if attempting to resolve with the first server provided results in a
8401cb0ef41Sopenharmony_ci`NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with
8411cb0ef41Sopenharmony_cisubsequent servers provided. Fallback DNS servers will only be used if the
8421cb0ef41Sopenharmony_ciearlier ones time out or result in some other error.
8431cb0ef41Sopenharmony_ci
8441cb0ef41Sopenharmony_ci## DNS promises API
8451cb0ef41Sopenharmony_ci
8461cb0ef41Sopenharmony_ci<!-- YAML
8471cb0ef41Sopenharmony_ciadded: v10.6.0
8481cb0ef41Sopenharmony_cichanges:
8491cb0ef41Sopenharmony_ci  - version: v15.0.0
8501cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/32953
8511cb0ef41Sopenharmony_ci    description: Exposed as `require('dns/promises')`.
8521cb0ef41Sopenharmony_ci  - version:
8531cb0ef41Sopenharmony_ci    - v11.14.0
8541cb0ef41Sopenharmony_ci    - v10.17.0
8551cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/26592
8561cb0ef41Sopenharmony_ci    description: This API is no longer experimental.
8571cb0ef41Sopenharmony_ci-->
8581cb0ef41Sopenharmony_ci
8591cb0ef41Sopenharmony_ciThe `dns.promises` API provides an alternative set of asynchronous DNS methods
8601cb0ef41Sopenharmony_cithat return `Promise` objects rather than using callbacks. The API is accessible
8611cb0ef41Sopenharmony_civia `require('node:dns').promises` or `require('node:dns/promises')`.
8621cb0ef41Sopenharmony_ci
8631cb0ef41Sopenharmony_ci### Class: `dnsPromises.Resolver`
8641cb0ef41Sopenharmony_ci
8651cb0ef41Sopenharmony_ci<!-- YAML
8661cb0ef41Sopenharmony_ciadded: v10.6.0
8671cb0ef41Sopenharmony_ci-->
8681cb0ef41Sopenharmony_ci
8691cb0ef41Sopenharmony_ciAn independent resolver for DNS requests.
8701cb0ef41Sopenharmony_ci
8711cb0ef41Sopenharmony_ciCreating a new resolver uses the default server settings. Setting
8721cb0ef41Sopenharmony_cithe servers used for a resolver using
8731cb0ef41Sopenharmony_ci[`resolver.setServers()`][`dnsPromises.setServers()`] does not affect
8741cb0ef41Sopenharmony_ciother resolvers:
8751cb0ef41Sopenharmony_ci
8761cb0ef41Sopenharmony_ci```js
8771cb0ef41Sopenharmony_ciconst { Resolver } = require('node:dns').promises;
8781cb0ef41Sopenharmony_ciconst resolver = new Resolver();
8791cb0ef41Sopenharmony_ciresolver.setServers(['4.4.4.4']);
8801cb0ef41Sopenharmony_ci
8811cb0ef41Sopenharmony_ci// This request will use the server at 4.4.4.4, independent of global settings.
8821cb0ef41Sopenharmony_ciresolver.resolve4('example.org').then((addresses) => {
8831cb0ef41Sopenharmony_ci  // ...
8841cb0ef41Sopenharmony_ci});
8851cb0ef41Sopenharmony_ci
8861cb0ef41Sopenharmony_ci// Alternatively, the same code can be written using async-await style.
8871cb0ef41Sopenharmony_ci(async function() {
8881cb0ef41Sopenharmony_ci  const addresses = await resolver.resolve4('example.org');
8891cb0ef41Sopenharmony_ci})();
8901cb0ef41Sopenharmony_ci```
8911cb0ef41Sopenharmony_ci
8921cb0ef41Sopenharmony_ciThe following methods from the `dnsPromises` API are available:
8931cb0ef41Sopenharmony_ci
8941cb0ef41Sopenharmony_ci* [`resolver.getServers()`][`dnsPromises.getServers()`]
8951cb0ef41Sopenharmony_ci* [`resolver.resolve()`][`dnsPromises.resolve()`]
8961cb0ef41Sopenharmony_ci* [`resolver.resolve4()`][`dnsPromises.resolve4()`]
8971cb0ef41Sopenharmony_ci* [`resolver.resolve6()`][`dnsPromises.resolve6()`]
8981cb0ef41Sopenharmony_ci* [`resolver.resolveAny()`][`dnsPromises.resolveAny()`]
8991cb0ef41Sopenharmony_ci* [`resolver.resolveCaa()`][`dnsPromises.resolveCaa()`]
9001cb0ef41Sopenharmony_ci* [`resolver.resolveCname()`][`dnsPromises.resolveCname()`]
9011cb0ef41Sopenharmony_ci* [`resolver.resolveMx()`][`dnsPromises.resolveMx()`]
9021cb0ef41Sopenharmony_ci* [`resolver.resolveNaptr()`][`dnsPromises.resolveNaptr()`]
9031cb0ef41Sopenharmony_ci* [`resolver.resolveNs()`][`dnsPromises.resolveNs()`]
9041cb0ef41Sopenharmony_ci* [`resolver.resolvePtr()`][`dnsPromises.resolvePtr()`]
9051cb0ef41Sopenharmony_ci* [`resolver.resolveSoa()`][`dnsPromises.resolveSoa()`]
9061cb0ef41Sopenharmony_ci* [`resolver.resolveSrv()`][`dnsPromises.resolveSrv()`]
9071cb0ef41Sopenharmony_ci* [`resolver.resolveTxt()`][`dnsPromises.resolveTxt()`]
9081cb0ef41Sopenharmony_ci* [`resolver.reverse()`][`dnsPromises.reverse()`]
9091cb0ef41Sopenharmony_ci* [`resolver.setServers()`][`dnsPromises.setServers()`]
9101cb0ef41Sopenharmony_ci
9111cb0ef41Sopenharmony_ci### `resolver.cancel()`
9121cb0ef41Sopenharmony_ci
9131cb0ef41Sopenharmony_ci<!-- YAML
9141cb0ef41Sopenharmony_ciadded:
9151cb0ef41Sopenharmony_ci  - v15.3.0
9161cb0ef41Sopenharmony_ci  - v14.17.0
9171cb0ef41Sopenharmony_ci-->
9181cb0ef41Sopenharmony_ci
9191cb0ef41Sopenharmony_ciCancel all outstanding DNS queries made by this resolver. The corresponding
9201cb0ef41Sopenharmony_cipromises will be rejected with an error with the code `ECANCELLED`.
9211cb0ef41Sopenharmony_ci
9221cb0ef41Sopenharmony_ci### `dnsPromises.getServers()`
9231cb0ef41Sopenharmony_ci
9241cb0ef41Sopenharmony_ci<!-- YAML
9251cb0ef41Sopenharmony_ciadded: v10.6.0
9261cb0ef41Sopenharmony_ci-->
9271cb0ef41Sopenharmony_ci
9281cb0ef41Sopenharmony_ci* Returns: {string\[]}
9291cb0ef41Sopenharmony_ci
9301cb0ef41Sopenharmony_ciReturns an array of IP address strings, formatted according to [RFC 5952][],
9311cb0ef41Sopenharmony_cithat are currently configured for DNS resolution. A string will include a port
9321cb0ef41Sopenharmony_cisection if a custom port is used.
9331cb0ef41Sopenharmony_ci
9341cb0ef41Sopenharmony_ci<!-- eslint-disable semi-->
9351cb0ef41Sopenharmony_ci
9361cb0ef41Sopenharmony_ci```js
9371cb0ef41Sopenharmony_ci[
9381cb0ef41Sopenharmony_ci  '4.4.4.4',
9391cb0ef41Sopenharmony_ci  '2001:4860:4860::8888',
9401cb0ef41Sopenharmony_ci  '4.4.4.4:1053',
9411cb0ef41Sopenharmony_ci  '[2001:4860:4860::8888]:1053',
9421cb0ef41Sopenharmony_ci]
9431cb0ef41Sopenharmony_ci```
9441cb0ef41Sopenharmony_ci
9451cb0ef41Sopenharmony_ci### `dnsPromises.lookup(hostname[, options])`
9461cb0ef41Sopenharmony_ci
9471cb0ef41Sopenharmony_ci<!-- YAML
9481cb0ef41Sopenharmony_ciadded: v10.6.0
9491cb0ef41Sopenharmony_ci-->
9501cb0ef41Sopenharmony_ci
9511cb0ef41Sopenharmony_ci* `hostname` {string}
9521cb0ef41Sopenharmony_ci* `options` {integer | Object}
9531cb0ef41Sopenharmony_ci  * `family` {integer} The record family. Must be `4`, `6`, or `0`. The value
9541cb0ef41Sopenharmony_ci    `0` indicates that IPv4 and IPv6 addresses are both returned. **Default:**
9551cb0ef41Sopenharmony_ci    `0`.
9561cb0ef41Sopenharmony_ci  * `hints` {number} One or more [supported `getaddrinfo` flags][]. Multiple
9571cb0ef41Sopenharmony_ci    flags may be passed by bitwise `OR`ing their values.
9581cb0ef41Sopenharmony_ci  * `all` {boolean} When `true`, the `Promise` is resolved with all addresses in
9591cb0ef41Sopenharmony_ci    an array. Otherwise, returns a single address. **Default:** `false`.
9601cb0ef41Sopenharmony_ci  * `verbatim` {boolean} When `true`, the `Promise` is resolved with IPv4 and
9611cb0ef41Sopenharmony_ci    IPv6 addresses in the order the DNS resolver returned them. When `false`,
9621cb0ef41Sopenharmony_ci    IPv4 addresses are placed before IPv6 addresses.
9631cb0ef41Sopenharmony_ci    **Default:** currently `false` (addresses are reordered) but this is
9641cb0ef41Sopenharmony_ci    expected to change in the not too distant future. Default value is
9651cb0ef41Sopenharmony_ci    configurable using [`dns.setDefaultResultOrder()`][] or
9661cb0ef41Sopenharmony_ci    [`--dns-result-order`][]. New code should use `{ verbatim: true }`.
9671cb0ef41Sopenharmony_ci
9681cb0ef41Sopenharmony_ciResolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
9691cb0ef41Sopenharmony_ciAAAA (IPv6) record. All `option` properties are optional. If `options` is an
9701cb0ef41Sopenharmony_ciinteger, then it must be `4` or `6` – if `options` is not provided, then IPv4
9711cb0ef41Sopenharmony_ciand IPv6 addresses are both returned if found.
9721cb0ef41Sopenharmony_ci
9731cb0ef41Sopenharmony_ciWith the `all` option set to `true`, the `Promise` is resolved with `addresses`
9741cb0ef41Sopenharmony_cibeing an array of objects with the properties `address` and `family`.
9751cb0ef41Sopenharmony_ci
9761cb0ef41Sopenharmony_ciOn error, the `Promise` is rejected with an [`Error`][] object, where `err.code`
9771cb0ef41Sopenharmony_ciis the error code.
9781cb0ef41Sopenharmony_ciKeep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
9791cb0ef41Sopenharmony_cithe host name does not exist but also when the lookup fails in other ways
9801cb0ef41Sopenharmony_cisuch as no available file descriptors.
9811cb0ef41Sopenharmony_ci
9821cb0ef41Sopenharmony_ci[`dnsPromises.lookup()`][] does not necessarily have anything to do with the DNS
9831cb0ef41Sopenharmony_ciprotocol. The implementation uses an operating system facility that can
9841cb0ef41Sopenharmony_ciassociate names with addresses and vice versa. This implementation can have
9851cb0ef41Sopenharmony_cisubtle but important consequences on the behavior of any Node.js program. Please
9861cb0ef41Sopenharmony_citake some time to consult the [Implementation considerations section][] before
9871cb0ef41Sopenharmony_ciusing `dnsPromises.lookup()`.
9881cb0ef41Sopenharmony_ci
9891cb0ef41Sopenharmony_ciExample usage:
9901cb0ef41Sopenharmony_ci
9911cb0ef41Sopenharmony_ci```js
9921cb0ef41Sopenharmony_ciconst dns = require('node:dns');
9931cb0ef41Sopenharmony_ciconst dnsPromises = dns.promises;
9941cb0ef41Sopenharmony_ciconst options = {
9951cb0ef41Sopenharmony_ci  family: 6,
9961cb0ef41Sopenharmony_ci  hints: dns.ADDRCONFIG | dns.V4MAPPED,
9971cb0ef41Sopenharmony_ci};
9981cb0ef41Sopenharmony_ci
9991cb0ef41Sopenharmony_cidnsPromises.lookup('example.com', options).then((result) => {
10001cb0ef41Sopenharmony_ci  console.log('address: %j family: IPv%s', result.address, result.family);
10011cb0ef41Sopenharmony_ci  // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
10021cb0ef41Sopenharmony_ci});
10031cb0ef41Sopenharmony_ci
10041cb0ef41Sopenharmony_ci// When options.all is true, the result will be an Array.
10051cb0ef41Sopenharmony_cioptions.all = true;
10061cb0ef41Sopenharmony_cidnsPromises.lookup('example.com', options).then((result) => {
10071cb0ef41Sopenharmony_ci  console.log('addresses: %j', result);
10081cb0ef41Sopenharmony_ci  // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
10091cb0ef41Sopenharmony_ci});
10101cb0ef41Sopenharmony_ci```
10111cb0ef41Sopenharmony_ci
10121cb0ef41Sopenharmony_ci### `dnsPromises.lookupService(address, port)`
10131cb0ef41Sopenharmony_ci
10141cb0ef41Sopenharmony_ci<!-- YAML
10151cb0ef41Sopenharmony_ciadded: v10.6.0
10161cb0ef41Sopenharmony_ci-->
10171cb0ef41Sopenharmony_ci
10181cb0ef41Sopenharmony_ci* `address` {string}
10191cb0ef41Sopenharmony_ci* `port` {number}
10201cb0ef41Sopenharmony_ci
10211cb0ef41Sopenharmony_ciResolves the given `address` and `port` into a host name and service using
10221cb0ef41Sopenharmony_cithe operating system's underlying `getnameinfo` implementation.
10231cb0ef41Sopenharmony_ci
10241cb0ef41Sopenharmony_ciIf `address` is not a valid IP address, a `TypeError` will be thrown.
10251cb0ef41Sopenharmony_ciThe `port` will be coerced to a number. If it is not a legal port, a `TypeError`
10261cb0ef41Sopenharmony_ciwill be thrown.
10271cb0ef41Sopenharmony_ci
10281cb0ef41Sopenharmony_ciOn error, the `Promise` is rejected with an [`Error`][] object, where `err.code`
10291cb0ef41Sopenharmony_ciis the error code.
10301cb0ef41Sopenharmony_ci
10311cb0ef41Sopenharmony_ci```js
10321cb0ef41Sopenharmony_ciconst dnsPromises = require('node:dns').promises;
10331cb0ef41Sopenharmony_cidnsPromises.lookupService('127.0.0.1', 22).then((result) => {
10341cb0ef41Sopenharmony_ci  console.log(result.hostname, result.service);
10351cb0ef41Sopenharmony_ci  // Prints: localhost ssh
10361cb0ef41Sopenharmony_ci});
10371cb0ef41Sopenharmony_ci```
10381cb0ef41Sopenharmony_ci
10391cb0ef41Sopenharmony_ci### `dnsPromises.resolve(hostname[, rrtype])`
10401cb0ef41Sopenharmony_ci
10411cb0ef41Sopenharmony_ci<!-- YAML
10421cb0ef41Sopenharmony_ciadded: v10.6.0
10431cb0ef41Sopenharmony_ci-->
10441cb0ef41Sopenharmony_ci
10451cb0ef41Sopenharmony_ci* `hostname` {string} Host name to resolve.
10461cb0ef41Sopenharmony_ci* `rrtype` {string} Resource record type. **Default:** `'A'`.
10471cb0ef41Sopenharmony_ci
10481cb0ef41Sopenharmony_ciUses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
10491cb0ef41Sopenharmony_ciof the resource records. When successful, the `Promise` is resolved with an
10501cb0ef41Sopenharmony_ciarray of resource records. The type and structure of individual results vary
10511cb0ef41Sopenharmony_cibased on `rrtype`:
10521cb0ef41Sopenharmony_ci
10531cb0ef41Sopenharmony_ci| `rrtype`  | `records` contains             | Result type | Shorthand method                 |
10541cb0ef41Sopenharmony_ci| --------- | ------------------------------ | ----------- | -------------------------------- |
10551cb0ef41Sopenharmony_ci| `'A'`     | IPv4 addresses (default)       | {string}    | [`dnsPromises.resolve4()`][]     |
10561cb0ef41Sopenharmony_ci| `'AAAA'`  | IPv6 addresses                 | {string}    | [`dnsPromises.resolve6()`][]     |
10571cb0ef41Sopenharmony_ci| `'ANY'`   | any records                    | {Object}    | [`dnsPromises.resolveAny()`][]   |
10581cb0ef41Sopenharmony_ci| `'CAA'`   | CA authorization records       | {Object}    | [`dnsPromises.resolveCaa()`][]   |
10591cb0ef41Sopenharmony_ci| `'CNAME'` | canonical name records         | {string}    | [`dnsPromises.resolveCname()`][] |
10601cb0ef41Sopenharmony_ci| `'MX'`    | mail exchange records          | {Object}    | [`dnsPromises.resolveMx()`][]    |
10611cb0ef41Sopenharmony_ci| `'NAPTR'` | name authority pointer records | {Object}    | [`dnsPromises.resolveNaptr()`][] |
10621cb0ef41Sopenharmony_ci| `'NS'`    | name server records            | {string}    | [`dnsPromises.resolveNs()`][]    |
10631cb0ef41Sopenharmony_ci| `'PTR'`   | pointer records                | {string}    | [`dnsPromises.resolvePtr()`][]   |
10641cb0ef41Sopenharmony_ci| `'SOA'`   | start of authority records     | {Object}    | [`dnsPromises.resolveSoa()`][]   |
10651cb0ef41Sopenharmony_ci| `'SRV'`   | service records                | {Object}    | [`dnsPromises.resolveSrv()`][]   |
10661cb0ef41Sopenharmony_ci| `'TXT'`   | text records                   | {string\[]} | [`dnsPromises.resolveTxt()`][]   |
10671cb0ef41Sopenharmony_ci
10681cb0ef41Sopenharmony_ciOn error, the `Promise` is rejected with an [`Error`][] object, where `err.code`
10691cb0ef41Sopenharmony_ciis one of the [DNS error codes][].
10701cb0ef41Sopenharmony_ci
10711cb0ef41Sopenharmony_ci### `dnsPromises.resolve4(hostname[, options])`
10721cb0ef41Sopenharmony_ci
10731cb0ef41Sopenharmony_ci<!-- YAML
10741cb0ef41Sopenharmony_ciadded: v10.6.0
10751cb0ef41Sopenharmony_ci-->
10761cb0ef41Sopenharmony_ci
10771cb0ef41Sopenharmony_ci* `hostname` {string} Host name to resolve.
10781cb0ef41Sopenharmony_ci* `options` {Object}
10791cb0ef41Sopenharmony_ci  * `ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record.
10801cb0ef41Sopenharmony_ci    When `true`, the `Promise` is resolved with an array of
10811cb0ef41Sopenharmony_ci    `{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings,
10821cb0ef41Sopenharmony_ci    with the TTL expressed in seconds.
10831cb0ef41Sopenharmony_ci
10841cb0ef41Sopenharmony_ciUses the DNS protocol to resolve IPv4 addresses (`A` records) for the
10851cb0ef41Sopenharmony_ci`hostname`. On success, the `Promise` is resolved with an array of IPv4
10861cb0ef41Sopenharmony_ciaddresses (e.g. `['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
10871cb0ef41Sopenharmony_ci
10881cb0ef41Sopenharmony_ci### `dnsPromises.resolve6(hostname[, options])`
10891cb0ef41Sopenharmony_ci
10901cb0ef41Sopenharmony_ci<!-- YAML
10911cb0ef41Sopenharmony_ciadded: v10.6.0
10921cb0ef41Sopenharmony_ci-->
10931cb0ef41Sopenharmony_ci
10941cb0ef41Sopenharmony_ci* `hostname` {string} Host name to resolve.
10951cb0ef41Sopenharmony_ci* `options` {Object}
10961cb0ef41Sopenharmony_ci  * `ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record.
10971cb0ef41Sopenharmony_ci    When `true`, the `Promise` is resolved with an array of
10981cb0ef41Sopenharmony_ci    `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of
10991cb0ef41Sopenharmony_ci    strings, with the TTL expressed in seconds.
11001cb0ef41Sopenharmony_ci
11011cb0ef41Sopenharmony_ciUses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the
11021cb0ef41Sopenharmony_ci`hostname`. On success, the `Promise` is resolved with an array of IPv6
11031cb0ef41Sopenharmony_ciaddresses.
11041cb0ef41Sopenharmony_ci
11051cb0ef41Sopenharmony_ci### `dnsPromises.resolveAny(hostname)`
11061cb0ef41Sopenharmony_ci
11071cb0ef41Sopenharmony_ci<!-- YAML
11081cb0ef41Sopenharmony_ciadded: v10.6.0
11091cb0ef41Sopenharmony_ci-->
11101cb0ef41Sopenharmony_ci
11111cb0ef41Sopenharmony_ci* `hostname` {string}
11121cb0ef41Sopenharmony_ci
11131cb0ef41Sopenharmony_ciUses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
11141cb0ef41Sopenharmony_ciOn success, the `Promise` is resolved with an array containing various types of
11151cb0ef41Sopenharmony_cirecords. Each object has a property `type` that indicates the type of the
11161cb0ef41Sopenharmony_cicurrent record. And depending on the `type`, additional properties will be
11171cb0ef41Sopenharmony_cipresent on the object:
11181cb0ef41Sopenharmony_ci
11191cb0ef41Sopenharmony_ci| Type      | Properties                                                                                                                                               |
11201cb0ef41Sopenharmony_ci| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
11211cb0ef41Sopenharmony_ci| `'A'`     | `address`/`ttl`                                                                                                                                          |
11221cb0ef41Sopenharmony_ci| `'AAAA'`  | `address`/`ttl`                                                                                                                                          |
11231cb0ef41Sopenharmony_ci| `'CNAME'` | `value`                                                                                                                                                  |
11241cb0ef41Sopenharmony_ci| `'MX'`    | Refer to [`dnsPromises.resolveMx()`][]                                                                                                                   |
11251cb0ef41Sopenharmony_ci| `'NAPTR'` | Refer to [`dnsPromises.resolveNaptr()`][]                                                                                                                |
11261cb0ef41Sopenharmony_ci| `'NS'`    | `value`                                                                                                                                                  |
11271cb0ef41Sopenharmony_ci| `'PTR'`   | `value`                                                                                                                                                  |
11281cb0ef41Sopenharmony_ci| `'SOA'`   | Refer to [`dnsPromises.resolveSoa()`][]                                                                                                                  |
11291cb0ef41Sopenharmony_ci| `'SRV'`   | Refer to [`dnsPromises.resolveSrv()`][]                                                                                                                  |
11301cb0ef41Sopenharmony_ci| `'TXT'`   | This type of record contains an array property called `entries` which refers to [`dnsPromises.resolveTxt()`][], e.g. `{ entries: ['...'], type: 'TXT' }` |
11311cb0ef41Sopenharmony_ci
11321cb0ef41Sopenharmony_ciHere is an example of the result object:
11331cb0ef41Sopenharmony_ci
11341cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
11351cb0ef41Sopenharmony_ci
11361cb0ef41Sopenharmony_ci```js
11371cb0ef41Sopenharmony_ci[ { type: 'A', address: '127.0.0.1', ttl: 299 },
11381cb0ef41Sopenharmony_ci  { type: 'CNAME', value: 'example.com' },
11391cb0ef41Sopenharmony_ci  { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
11401cb0ef41Sopenharmony_ci  { type: 'NS', value: 'ns1.example.com' },
11411cb0ef41Sopenharmony_ci  { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
11421cb0ef41Sopenharmony_ci  { type: 'SOA',
11431cb0ef41Sopenharmony_ci    nsname: 'ns1.example.com',
11441cb0ef41Sopenharmony_ci    hostmaster: 'admin.example.com',
11451cb0ef41Sopenharmony_ci    serial: 156696742,
11461cb0ef41Sopenharmony_ci    refresh: 900,
11471cb0ef41Sopenharmony_ci    retry: 900,
11481cb0ef41Sopenharmony_ci    expire: 1800,
11491cb0ef41Sopenharmony_ci    minttl: 60 } ]
11501cb0ef41Sopenharmony_ci```
11511cb0ef41Sopenharmony_ci
11521cb0ef41Sopenharmony_ci### `dnsPromises.resolveCaa(hostname)`
11531cb0ef41Sopenharmony_ci
11541cb0ef41Sopenharmony_ci<!-- YAML
11551cb0ef41Sopenharmony_ciadded:
11561cb0ef41Sopenharmony_ci  - v15.0.0
11571cb0ef41Sopenharmony_ci  - v14.17.0
11581cb0ef41Sopenharmony_ci-->
11591cb0ef41Sopenharmony_ci
11601cb0ef41Sopenharmony_ci* `hostname` {string}
11611cb0ef41Sopenharmony_ci
11621cb0ef41Sopenharmony_ciUses the DNS protocol to resolve `CAA` records for the `hostname`. On success,
11631cb0ef41Sopenharmony_cithe `Promise` is resolved with an array of objects containing available
11641cb0ef41Sopenharmony_cicertification authority authorization records available for the `hostname`
11651cb0ef41Sopenharmony_ci(e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue:
11661cb0ef41Sopenharmony_ci'pki.example.com'}]`).
11671cb0ef41Sopenharmony_ci
11681cb0ef41Sopenharmony_ci### `dnsPromises.resolveCname(hostname)`
11691cb0ef41Sopenharmony_ci
11701cb0ef41Sopenharmony_ci<!-- YAML
11711cb0ef41Sopenharmony_ciadded: v10.6.0
11721cb0ef41Sopenharmony_ci-->
11731cb0ef41Sopenharmony_ci
11741cb0ef41Sopenharmony_ci* `hostname` {string}
11751cb0ef41Sopenharmony_ci
11761cb0ef41Sopenharmony_ciUses the DNS protocol to resolve `CNAME` records for the `hostname`. On success,
11771cb0ef41Sopenharmony_cithe `Promise` is resolved with an array of canonical name records available for
11781cb0ef41Sopenharmony_cithe `hostname` (e.g. `['bar.example.com']`).
11791cb0ef41Sopenharmony_ci
11801cb0ef41Sopenharmony_ci### `dnsPromises.resolveMx(hostname)`
11811cb0ef41Sopenharmony_ci
11821cb0ef41Sopenharmony_ci<!-- YAML
11831cb0ef41Sopenharmony_ciadded: v10.6.0
11841cb0ef41Sopenharmony_ci-->
11851cb0ef41Sopenharmony_ci
11861cb0ef41Sopenharmony_ci* `hostname` {string}
11871cb0ef41Sopenharmony_ci
11881cb0ef41Sopenharmony_ciUses the DNS protocol to resolve mail exchange records (`MX` records) for the
11891cb0ef41Sopenharmony_ci`hostname`. On success, the `Promise` is resolved with an array of objects
11901cb0ef41Sopenharmony_cicontaining both a `priority` and `exchange` property (e.g.
11911cb0ef41Sopenharmony_ci`[{priority: 10, exchange: 'mx.example.com'}, ...]`).
11921cb0ef41Sopenharmony_ci
11931cb0ef41Sopenharmony_ci### `dnsPromises.resolveNaptr(hostname)`
11941cb0ef41Sopenharmony_ci
11951cb0ef41Sopenharmony_ci<!-- YAML
11961cb0ef41Sopenharmony_ciadded: v10.6.0
11971cb0ef41Sopenharmony_ci-->
11981cb0ef41Sopenharmony_ci
11991cb0ef41Sopenharmony_ci* `hostname` {string}
12001cb0ef41Sopenharmony_ci
12011cb0ef41Sopenharmony_ciUses the DNS protocol to resolve regular expression-based records (`NAPTR`
12021cb0ef41Sopenharmony_cirecords) for the `hostname`. On success, the `Promise` is resolved with an array
12031cb0ef41Sopenharmony_ciof objects with the following properties:
12041cb0ef41Sopenharmony_ci
12051cb0ef41Sopenharmony_ci* `flags`
12061cb0ef41Sopenharmony_ci* `service`
12071cb0ef41Sopenharmony_ci* `regexp`
12081cb0ef41Sopenharmony_ci* `replacement`
12091cb0ef41Sopenharmony_ci* `order`
12101cb0ef41Sopenharmony_ci* `preference`
12111cb0ef41Sopenharmony_ci
12121cb0ef41Sopenharmony_ci<!-- eslint-skip -->
12131cb0ef41Sopenharmony_ci
12141cb0ef41Sopenharmony_ci```js
12151cb0ef41Sopenharmony_ci{
12161cb0ef41Sopenharmony_ci  flags: 's',
12171cb0ef41Sopenharmony_ci  service: 'SIP+D2U',
12181cb0ef41Sopenharmony_ci  regexp: '',
12191cb0ef41Sopenharmony_ci  replacement: '_sip._udp.example.com',
12201cb0ef41Sopenharmony_ci  order: 30,
12211cb0ef41Sopenharmony_ci  preference: 100
12221cb0ef41Sopenharmony_ci}
12231cb0ef41Sopenharmony_ci```
12241cb0ef41Sopenharmony_ci
12251cb0ef41Sopenharmony_ci### `dnsPromises.resolveNs(hostname)`
12261cb0ef41Sopenharmony_ci
12271cb0ef41Sopenharmony_ci<!-- YAML
12281cb0ef41Sopenharmony_ciadded: v10.6.0
12291cb0ef41Sopenharmony_ci-->
12301cb0ef41Sopenharmony_ci
12311cb0ef41Sopenharmony_ci* `hostname` {string}
12321cb0ef41Sopenharmony_ci
12331cb0ef41Sopenharmony_ciUses the DNS protocol to resolve name server records (`NS` records) for the
12341cb0ef41Sopenharmony_ci`hostname`. On success, the `Promise` is resolved with an array of name server
12351cb0ef41Sopenharmony_cirecords available for `hostname` (e.g.
12361cb0ef41Sopenharmony_ci`['ns1.example.com', 'ns2.example.com']`).
12371cb0ef41Sopenharmony_ci
12381cb0ef41Sopenharmony_ci### `dnsPromises.resolvePtr(hostname)`
12391cb0ef41Sopenharmony_ci
12401cb0ef41Sopenharmony_ci<!-- YAML
12411cb0ef41Sopenharmony_ciadded: v10.6.0
12421cb0ef41Sopenharmony_ci-->
12431cb0ef41Sopenharmony_ci
12441cb0ef41Sopenharmony_ci* `hostname` {string}
12451cb0ef41Sopenharmony_ci
12461cb0ef41Sopenharmony_ciUses the DNS protocol to resolve pointer records (`PTR` records) for the
12471cb0ef41Sopenharmony_ci`hostname`. On success, the `Promise` is resolved with an array of strings
12481cb0ef41Sopenharmony_cicontaining the reply records.
12491cb0ef41Sopenharmony_ci
12501cb0ef41Sopenharmony_ci### `dnsPromises.resolveSoa(hostname)`
12511cb0ef41Sopenharmony_ci
12521cb0ef41Sopenharmony_ci<!-- YAML
12531cb0ef41Sopenharmony_ciadded: v10.6.0
12541cb0ef41Sopenharmony_ci-->
12551cb0ef41Sopenharmony_ci
12561cb0ef41Sopenharmony_ci* `hostname` {string}
12571cb0ef41Sopenharmony_ci
12581cb0ef41Sopenharmony_ciUses the DNS protocol to resolve a start of authority record (`SOA` record) for
12591cb0ef41Sopenharmony_cithe `hostname`. On success, the `Promise` is resolved with an object with the
12601cb0ef41Sopenharmony_cifollowing properties:
12611cb0ef41Sopenharmony_ci
12621cb0ef41Sopenharmony_ci* `nsname`
12631cb0ef41Sopenharmony_ci* `hostmaster`
12641cb0ef41Sopenharmony_ci* `serial`
12651cb0ef41Sopenharmony_ci* `refresh`
12661cb0ef41Sopenharmony_ci* `retry`
12671cb0ef41Sopenharmony_ci* `expire`
12681cb0ef41Sopenharmony_ci* `minttl`
12691cb0ef41Sopenharmony_ci
12701cb0ef41Sopenharmony_ci<!-- eslint-skip -->
12711cb0ef41Sopenharmony_ci
12721cb0ef41Sopenharmony_ci```js
12731cb0ef41Sopenharmony_ci{
12741cb0ef41Sopenharmony_ci  nsname: 'ns.example.com',
12751cb0ef41Sopenharmony_ci  hostmaster: 'root.example.com',
12761cb0ef41Sopenharmony_ci  serial: 2013101809,
12771cb0ef41Sopenharmony_ci  refresh: 10000,
12781cb0ef41Sopenharmony_ci  retry: 2400,
12791cb0ef41Sopenharmony_ci  expire: 604800,
12801cb0ef41Sopenharmony_ci  minttl: 3600
12811cb0ef41Sopenharmony_ci}
12821cb0ef41Sopenharmony_ci```
12831cb0ef41Sopenharmony_ci
12841cb0ef41Sopenharmony_ci### `dnsPromises.resolveSrv(hostname)`
12851cb0ef41Sopenharmony_ci
12861cb0ef41Sopenharmony_ci<!-- YAML
12871cb0ef41Sopenharmony_ciadded: v10.6.0
12881cb0ef41Sopenharmony_ci-->
12891cb0ef41Sopenharmony_ci
12901cb0ef41Sopenharmony_ci* `hostname` {string}
12911cb0ef41Sopenharmony_ci
12921cb0ef41Sopenharmony_ciUses the DNS protocol to resolve service records (`SRV` records) for the
12931cb0ef41Sopenharmony_ci`hostname`. On success, the `Promise` is resolved with an array of objects with
12941cb0ef41Sopenharmony_cithe following properties:
12951cb0ef41Sopenharmony_ci
12961cb0ef41Sopenharmony_ci* `priority`
12971cb0ef41Sopenharmony_ci* `weight`
12981cb0ef41Sopenharmony_ci* `port`
12991cb0ef41Sopenharmony_ci* `name`
13001cb0ef41Sopenharmony_ci
13011cb0ef41Sopenharmony_ci<!-- eslint-skip -->
13021cb0ef41Sopenharmony_ci
13031cb0ef41Sopenharmony_ci```js
13041cb0ef41Sopenharmony_ci{
13051cb0ef41Sopenharmony_ci  priority: 10,
13061cb0ef41Sopenharmony_ci  weight: 5,
13071cb0ef41Sopenharmony_ci  port: 21223,
13081cb0ef41Sopenharmony_ci  name: 'service.example.com'
13091cb0ef41Sopenharmony_ci}
13101cb0ef41Sopenharmony_ci```
13111cb0ef41Sopenharmony_ci
13121cb0ef41Sopenharmony_ci### `dnsPromises.resolveTxt(hostname)`
13131cb0ef41Sopenharmony_ci
13141cb0ef41Sopenharmony_ci<!-- YAML
13151cb0ef41Sopenharmony_ciadded: v10.6.0
13161cb0ef41Sopenharmony_ci-->
13171cb0ef41Sopenharmony_ci
13181cb0ef41Sopenharmony_ci* `hostname` {string}
13191cb0ef41Sopenharmony_ci
13201cb0ef41Sopenharmony_ciUses the DNS protocol to resolve text queries (`TXT` records) for the
13211cb0ef41Sopenharmony_ci`hostname`. On success, the `Promise` is resolved with a two-dimensional array
13221cb0ef41Sopenharmony_ciof the text records available for `hostname` (e.g.
13231cb0ef41Sopenharmony_ci`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
13241cb0ef41Sopenharmony_cione record. Depending on the use case, these could be either joined together or
13251cb0ef41Sopenharmony_citreated separately.
13261cb0ef41Sopenharmony_ci
13271cb0ef41Sopenharmony_ci### `dnsPromises.reverse(ip)`
13281cb0ef41Sopenharmony_ci
13291cb0ef41Sopenharmony_ci<!-- YAML
13301cb0ef41Sopenharmony_ciadded: v10.6.0
13311cb0ef41Sopenharmony_ci-->
13321cb0ef41Sopenharmony_ci
13331cb0ef41Sopenharmony_ci* `ip` {string}
13341cb0ef41Sopenharmony_ci
13351cb0ef41Sopenharmony_ciPerforms a reverse DNS query that resolves an IPv4 or IPv6 address to an
13361cb0ef41Sopenharmony_ciarray of host names.
13371cb0ef41Sopenharmony_ci
13381cb0ef41Sopenharmony_ciOn error, the `Promise` is rejected with an [`Error`][] object, where `err.code`
13391cb0ef41Sopenharmony_ciis one of the [DNS error codes][].
13401cb0ef41Sopenharmony_ci
13411cb0ef41Sopenharmony_ci### `dnsPromises.setDefaultResultOrder(order)`
13421cb0ef41Sopenharmony_ci
13431cb0ef41Sopenharmony_ci<!-- YAML
13441cb0ef41Sopenharmony_ciadded:
13451cb0ef41Sopenharmony_ci  - v16.4.0
13461cb0ef41Sopenharmony_ci  - v14.18.0
13471cb0ef41Sopenharmony_cichanges:
13481cb0ef41Sopenharmony_ci  - version: v17.0.0
13491cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/39987
13501cb0ef41Sopenharmony_ci    description: Changed default value to `verbatim`.
13511cb0ef41Sopenharmony_ci-->
13521cb0ef41Sopenharmony_ci
13531cb0ef41Sopenharmony_ci* `order` {string} must be `'ipv4first'` or `'verbatim'`.
13541cb0ef41Sopenharmony_ci
13551cb0ef41Sopenharmony_ciSet the default value of `verbatim` in [`dns.lookup()`][] and
13561cb0ef41Sopenharmony_ci[`dnsPromises.lookup()`][]. The value could be:
13571cb0ef41Sopenharmony_ci
13581cb0ef41Sopenharmony_ci* `ipv4first`: sets default `verbatim` `false`.
13591cb0ef41Sopenharmony_ci* `verbatim`: sets default `verbatim` `true`.
13601cb0ef41Sopenharmony_ci
13611cb0ef41Sopenharmony_ciThe default is `verbatim` and [`dnsPromises.setDefaultResultOrder()`][] have
13621cb0ef41Sopenharmony_cihigher priority than [`--dns-result-order`][]. When using [worker threads][],
13631cb0ef41Sopenharmony_ci[`dnsPromises.setDefaultResultOrder()`][] from the main thread won't affect the
13641cb0ef41Sopenharmony_cidefault dns orders in workers.
13651cb0ef41Sopenharmony_ci
13661cb0ef41Sopenharmony_ci### `dnsPromises.getDefaultResultOrder()`
13671cb0ef41Sopenharmony_ci
13681cb0ef41Sopenharmony_ci<!-- YAML
13691cb0ef41Sopenharmony_ciadded: v18.17.0
13701cb0ef41Sopenharmony_ci-->
13711cb0ef41Sopenharmony_ci
13721cb0ef41Sopenharmony_ciGet the value of `dnsOrder`.
13731cb0ef41Sopenharmony_ci
13741cb0ef41Sopenharmony_ci### `dnsPromises.setServers(servers)`
13751cb0ef41Sopenharmony_ci
13761cb0ef41Sopenharmony_ci<!-- YAML
13771cb0ef41Sopenharmony_ciadded: v10.6.0
13781cb0ef41Sopenharmony_ci-->
13791cb0ef41Sopenharmony_ci
13801cb0ef41Sopenharmony_ci* `servers` {string\[]} array of [RFC 5952][] formatted addresses
13811cb0ef41Sopenharmony_ci
13821cb0ef41Sopenharmony_ciSets the IP address and port of servers to be used when performing DNS
13831cb0ef41Sopenharmony_ciresolution. The `servers` argument is an array of [RFC 5952][] formatted
13841cb0ef41Sopenharmony_ciaddresses. If the port is the IANA default DNS port (53) it can be omitted.
13851cb0ef41Sopenharmony_ci
13861cb0ef41Sopenharmony_ci```js
13871cb0ef41Sopenharmony_cidnsPromises.setServers([
13881cb0ef41Sopenharmony_ci  '4.4.4.4',
13891cb0ef41Sopenharmony_ci  '[2001:4860:4860::8888]',
13901cb0ef41Sopenharmony_ci  '4.4.4.4:1053',
13911cb0ef41Sopenharmony_ci  '[2001:4860:4860::8888]:1053',
13921cb0ef41Sopenharmony_ci]);
13931cb0ef41Sopenharmony_ci```
13941cb0ef41Sopenharmony_ci
13951cb0ef41Sopenharmony_ciAn error will be thrown if an invalid address is provided.
13961cb0ef41Sopenharmony_ci
13971cb0ef41Sopenharmony_ciThe `dnsPromises.setServers()` method must not be called while a DNS query is in
13981cb0ef41Sopenharmony_ciprogress.
13991cb0ef41Sopenharmony_ci
14001cb0ef41Sopenharmony_ciThis method works much like
14011cb0ef41Sopenharmony_ci[resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
14021cb0ef41Sopenharmony_ciThat is, if attempting to resolve with the first server provided results in a
14031cb0ef41Sopenharmony_ci`NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with
14041cb0ef41Sopenharmony_cisubsequent servers provided. Fallback DNS servers will only be used if the
14051cb0ef41Sopenharmony_ciearlier ones time out or result in some other error.
14061cb0ef41Sopenharmony_ci
14071cb0ef41Sopenharmony_ci## Error codes
14081cb0ef41Sopenharmony_ci
14091cb0ef41Sopenharmony_ciEach DNS query can return one of the following error codes:
14101cb0ef41Sopenharmony_ci
14111cb0ef41Sopenharmony_ci* `dns.NODATA`: DNS server returned an answer with no data.
14121cb0ef41Sopenharmony_ci* `dns.FORMERR`: DNS server claims query was misformatted.
14131cb0ef41Sopenharmony_ci* `dns.SERVFAIL`: DNS server returned general failure.
14141cb0ef41Sopenharmony_ci* `dns.NOTFOUND`: Domain name not found.
14151cb0ef41Sopenharmony_ci* `dns.NOTIMP`: DNS server does not implement the requested operation.
14161cb0ef41Sopenharmony_ci* `dns.REFUSED`: DNS server refused query.
14171cb0ef41Sopenharmony_ci* `dns.BADQUERY`: Misformatted DNS query.
14181cb0ef41Sopenharmony_ci* `dns.BADNAME`: Misformatted host name.
14191cb0ef41Sopenharmony_ci* `dns.BADFAMILY`: Unsupported address family.
14201cb0ef41Sopenharmony_ci* `dns.BADRESP`: Misformatted DNS reply.
14211cb0ef41Sopenharmony_ci* `dns.CONNREFUSED`: Could not contact DNS servers.
14221cb0ef41Sopenharmony_ci* `dns.TIMEOUT`: Timeout while contacting DNS servers.
14231cb0ef41Sopenharmony_ci* `dns.EOF`: End of file.
14241cb0ef41Sopenharmony_ci* `dns.FILE`: Error reading file.
14251cb0ef41Sopenharmony_ci* `dns.NOMEM`: Out of memory.
14261cb0ef41Sopenharmony_ci* `dns.DESTRUCTION`: Channel is being destroyed.
14271cb0ef41Sopenharmony_ci* `dns.BADSTR`: Misformatted string.
14281cb0ef41Sopenharmony_ci* `dns.BADFLAGS`: Illegal flags specified.
14291cb0ef41Sopenharmony_ci* `dns.NONAME`: Given host name is not numeric.
14301cb0ef41Sopenharmony_ci* `dns.BADHINTS`: Illegal hints flags specified.
14311cb0ef41Sopenharmony_ci* `dns.NOTINITIALIZED`: c-ares library initialization not yet performed.
14321cb0ef41Sopenharmony_ci* `dns.LOADIPHLPAPI`: Error loading `iphlpapi.dll`.
14331cb0ef41Sopenharmony_ci* `dns.ADDRGETNETWORKPARAMS`: Could not find `GetNetworkParams` function.
14341cb0ef41Sopenharmony_ci* `dns.CANCELLED`: DNS query cancelled.
14351cb0ef41Sopenharmony_ci
14361cb0ef41Sopenharmony_ciThe `dnsPromises` API also exports the above error codes, e.g., `dnsPromises.NODATA`.
14371cb0ef41Sopenharmony_ci
14381cb0ef41Sopenharmony_ci## Implementation considerations
14391cb0ef41Sopenharmony_ci
14401cb0ef41Sopenharmony_ciAlthough [`dns.lookup()`][] and the various `dns.resolve*()/dns.reverse()`
14411cb0ef41Sopenharmony_cifunctions have the same goal of associating a network name with a network
14421cb0ef41Sopenharmony_ciaddress (or vice versa), their behavior is quite different. These differences
14431cb0ef41Sopenharmony_cican have subtle but significant consequences on the behavior of Node.js
14441cb0ef41Sopenharmony_ciprograms.
14451cb0ef41Sopenharmony_ci
14461cb0ef41Sopenharmony_ci### `dns.lookup()`
14471cb0ef41Sopenharmony_ci
14481cb0ef41Sopenharmony_ciUnder the hood, [`dns.lookup()`][] uses the same operating system facilities
14491cb0ef41Sopenharmony_cias most other programs. For instance, [`dns.lookup()`][] will almost always
14501cb0ef41Sopenharmony_ciresolve a given name the same way as the `ping` command. On most POSIX-like
14511cb0ef41Sopenharmony_cioperating systems, the behavior of the [`dns.lookup()`][] function can be
14521cb0ef41Sopenharmony_cimodified by changing settings in nsswitch.conf(5) and/or resolv.conf(5),
14531cb0ef41Sopenharmony_cibut changing these files will change the behavior of all other
14541cb0ef41Sopenharmony_ciprograms running on the same operating system.
14551cb0ef41Sopenharmony_ci
14561cb0ef41Sopenharmony_ciThough the call to `dns.lookup()` will be asynchronous from JavaScript's
14571cb0ef41Sopenharmony_ciperspective, it is implemented as a synchronous call to getaddrinfo(3) that runs
14581cb0ef41Sopenharmony_cion libuv's threadpool. This can have surprising negative performance
14591cb0ef41Sopenharmony_ciimplications for some applications, see the [`UV_THREADPOOL_SIZE`][]
14601cb0ef41Sopenharmony_cidocumentation for more information.
14611cb0ef41Sopenharmony_ci
14621cb0ef41Sopenharmony_ciVarious networking APIs will call `dns.lookup()` internally to resolve
14631cb0ef41Sopenharmony_cihost names. If that is an issue, consider resolving the host name to an address
14641cb0ef41Sopenharmony_ciusing `dns.resolve()` and using the address instead of a host name. Also, some
14651cb0ef41Sopenharmony_cinetworking APIs (such as [`socket.connect()`][] and [`dgram.createSocket()`][])
14661cb0ef41Sopenharmony_ciallow the default resolver, `dns.lookup()`, to be replaced.
14671cb0ef41Sopenharmony_ci
14681cb0ef41Sopenharmony_ci### `dns.resolve()`, `dns.resolve*()`, and `dns.reverse()`
14691cb0ef41Sopenharmony_ci
14701cb0ef41Sopenharmony_ciThese functions are implemented quite differently than [`dns.lookup()`][]. They
14711cb0ef41Sopenharmony_cido not use getaddrinfo(3) and they _always_ perform a DNS query on the
14721cb0ef41Sopenharmony_cinetwork. This network communication is always done asynchronously and does not
14731cb0ef41Sopenharmony_ciuse libuv's threadpool.
14741cb0ef41Sopenharmony_ci
14751cb0ef41Sopenharmony_ciAs a result, these functions cannot have the same negative impact on other
14761cb0ef41Sopenharmony_ciprocessing that happens on libuv's threadpool that [`dns.lookup()`][] can have.
14771cb0ef41Sopenharmony_ci
14781cb0ef41Sopenharmony_ciThey do not use the same set of configuration files that [`dns.lookup()`][]
14791cb0ef41Sopenharmony_ciuses. For instance, they do not use the configuration from `/etc/hosts`.
14801cb0ef41Sopenharmony_ci
14811cb0ef41Sopenharmony_ci[DNS error codes]: #error-codes
14821cb0ef41Sopenharmony_ci[Domain Name System (DNS)]: https://en.wikipedia.org/wiki/Domain_Name_System
14831cb0ef41Sopenharmony_ci[Implementation considerations section]: #implementation-considerations
14841cb0ef41Sopenharmony_ci[RFC 5952]: https://tools.ietf.org/html/rfc5952#section-6
14851cb0ef41Sopenharmony_ci[RFC 8482]: https://tools.ietf.org/html/rfc8482
14861cb0ef41Sopenharmony_ci[`--dns-result-order`]: cli.md#--dns-result-orderorder
14871cb0ef41Sopenharmony_ci[`Error`]: errors.md#class-error
14881cb0ef41Sopenharmony_ci[`UV_THREADPOOL_SIZE`]: cli.md#uv_threadpool_sizesize
14891cb0ef41Sopenharmony_ci[`dgram.createSocket()`]: dgram.md#dgramcreatesocketoptions-callback
14901cb0ef41Sopenharmony_ci[`dns.getServers()`]: #dnsgetservers
14911cb0ef41Sopenharmony_ci[`dns.lookup()`]: #dnslookuphostname-options-callback
14921cb0ef41Sopenharmony_ci[`dns.resolve()`]: #dnsresolvehostname-rrtype-callback
14931cb0ef41Sopenharmony_ci[`dns.resolve4()`]: #dnsresolve4hostname-options-callback
14941cb0ef41Sopenharmony_ci[`dns.resolve6()`]: #dnsresolve6hostname-options-callback
14951cb0ef41Sopenharmony_ci[`dns.resolveAny()`]: #dnsresolveanyhostname-callback
14961cb0ef41Sopenharmony_ci[`dns.resolveCaa()`]: #dnsresolvecaahostname-callback
14971cb0ef41Sopenharmony_ci[`dns.resolveCname()`]: #dnsresolvecnamehostname-callback
14981cb0ef41Sopenharmony_ci[`dns.resolveMx()`]: #dnsresolvemxhostname-callback
14991cb0ef41Sopenharmony_ci[`dns.resolveNaptr()`]: #dnsresolvenaptrhostname-callback
15001cb0ef41Sopenharmony_ci[`dns.resolveNs()`]: #dnsresolvenshostname-callback
15011cb0ef41Sopenharmony_ci[`dns.resolvePtr()`]: #dnsresolveptrhostname-callback
15021cb0ef41Sopenharmony_ci[`dns.resolveSoa()`]: #dnsresolvesoahostname-callback
15031cb0ef41Sopenharmony_ci[`dns.resolveSrv()`]: #dnsresolvesrvhostname-callback
15041cb0ef41Sopenharmony_ci[`dns.resolveTxt()`]: #dnsresolvetxthostname-callback
15051cb0ef41Sopenharmony_ci[`dns.reverse()`]: #dnsreverseip-callback
15061cb0ef41Sopenharmony_ci[`dns.setDefaultResultOrder()`]: #dnssetdefaultresultorderorder
15071cb0ef41Sopenharmony_ci[`dns.setServers()`]: #dnssetserversservers
15081cb0ef41Sopenharmony_ci[`dnsPromises.getServers()`]: #dnspromisesgetservers
15091cb0ef41Sopenharmony_ci[`dnsPromises.lookup()`]: #dnspromiseslookuphostname-options
15101cb0ef41Sopenharmony_ci[`dnsPromises.resolve()`]: #dnspromisesresolvehostname-rrtype
15111cb0ef41Sopenharmony_ci[`dnsPromises.resolve4()`]: #dnspromisesresolve4hostname-options
15121cb0ef41Sopenharmony_ci[`dnsPromises.resolve6()`]: #dnspromisesresolve6hostname-options
15131cb0ef41Sopenharmony_ci[`dnsPromises.resolveAny()`]: #dnspromisesresolveanyhostname
15141cb0ef41Sopenharmony_ci[`dnsPromises.resolveCaa()`]: #dnspromisesresolvecaahostname
15151cb0ef41Sopenharmony_ci[`dnsPromises.resolveCname()`]: #dnspromisesresolvecnamehostname
15161cb0ef41Sopenharmony_ci[`dnsPromises.resolveMx()`]: #dnspromisesresolvemxhostname
15171cb0ef41Sopenharmony_ci[`dnsPromises.resolveNaptr()`]: #dnspromisesresolvenaptrhostname
15181cb0ef41Sopenharmony_ci[`dnsPromises.resolveNs()`]: #dnspromisesresolvenshostname
15191cb0ef41Sopenharmony_ci[`dnsPromises.resolvePtr()`]: #dnspromisesresolveptrhostname
15201cb0ef41Sopenharmony_ci[`dnsPromises.resolveSoa()`]: #dnspromisesresolvesoahostname
15211cb0ef41Sopenharmony_ci[`dnsPromises.resolveSrv()`]: #dnspromisesresolvesrvhostname
15221cb0ef41Sopenharmony_ci[`dnsPromises.resolveTxt()`]: #dnspromisesresolvetxthostname
15231cb0ef41Sopenharmony_ci[`dnsPromises.reverse()`]: #dnspromisesreverseip
15241cb0ef41Sopenharmony_ci[`dnsPromises.setDefaultResultOrder()`]: #dnspromisessetdefaultresultorderorder
15251cb0ef41Sopenharmony_ci[`dnsPromises.setServers()`]: #dnspromisessetserversservers
15261cb0ef41Sopenharmony_ci[`socket.connect()`]: net.md#socketconnectoptions-connectlistener
15271cb0ef41Sopenharmony_ci[`util.promisify()`]: util.md#utilpromisifyoriginal
15281cb0ef41Sopenharmony_ci[supported `getaddrinfo` flags]: #supported-getaddrinfo-flags
15291cb0ef41Sopenharmony_ci[worker threads]: worker_threads.md
1530