Skip to main content
setServers - node__dns.d.ts - Node documentation
function setServers

Usage in Deno

```typescript import { setServers } from "node:node__dns.d.ts"; ```
setServers(servers: readonly string[]): void
Sets the IP address and port of servers to be used when performing DNS resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted addresses. If the port is the IANA default DNS port (53) it can be omitted. ```js dns.setServers([ '4.4.4.4', '[2001:4860:4860::8888]', '4.4.4.4:1053', '[2001:4860:4860::8888]:1053', ]); ``` An error will be thrown if an invalid address is provided. The `dns.setServers()` method must not be called while a DNS query is in progress. The [setServers](../.././node__dns.d.ts/~/setServers) method affects only [resolve](../.././node__dns.d.ts/~/resolve), `dns.resolve*()` and [reverse](../.././node__dns.d.ts/~/reverse) (and specifically _not_ [lookup](../.././node__dns.d.ts/~/lookup)). This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html). That is, if attempting to resolve with the first server provided results in a `NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with subsequent servers provided. Fallback DNS servers will only be used if the earlier ones time out or result in some other error.

Parameters

servers: readonly string[]
array of [RFC 5952](https://datatracker.ietf.org/doc/html/rfc5952#section-6) formatted addresses

Return Type

void