{"record":{"id":"088bb72963243947","repo":"denoland/deno","slug":"err-invalid-ip-address","errorCode":"ERR_INVALID_IP_ADDRESS","errorMessage":"Invalid IP address: ${serv}","messagePattern":"Invalid IP address: (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/dns/utils.ts","lineNumber":380,"sourceCode":"      // addr::port\n      const addrSplitMatch = StringPrototypeMatch(serv, addrSplitRE);\n\n      if (addrSplitMatch) {\n        const hostIP = addrSplitMatch[1];\n        const port = addrSplitMatch[2] || `${IANA_DNS_PORT}`;\n\n        ipVersion = isIP(hostIP);\n\n        if (ipVersion !== 0) {\n          return ArrayPrototypePush(newSet, [\n            ipVersion,\n            hostIP,\n            NumberParseInt(port),\n          ]);\n        }\n      }\n\n      throw new ERR_INVALID_IP_ADDRESS(serv);\n    });\n\n    const errorNumber = this._handle.setServers(newSet);\n\n    if (errorNumber !== 0) {\n      // Reset the servers to the old servers, because ares probably unset them.\n      this._handle.setServers(ArrayPrototypeJoin(orig, \",\"));\n      const err = strerror(errorNumber);\n\n      throw new ERR_DNS_SET_SERVERS_FAILED(\n        err,\n        ArrayPrototypeToString(servers),\n      );\n    }\n  }\n\n  /**\n   * The resolver instance will send its requests from the specified IP address.","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/dns/utils.ts#L362-L398","documentation":"Resolver.setServers() parses each entry as an IP literal with an optional port (bracketed [v6]:port form included); the address part must pass isIP(). An entry whose address is not an IP literal throws ERR_INVALID_IP_ADDRESS naming the offending entry - hostnames and URLs are rejected because the resolver needs concrete addresses.","triggerScenarios":"resolver.setServers(['dns.google']) (hostname); ['localhost:53']; ['https://1.1.1.1/dns-query'] (DoH URL); a malformed literal like '192.168.0'.","commonSituations":"Wanting DoH-style resolver names where only IPs work; DNS config scraped from systemd-resolved, docker or k8s templates that contain hostnames; env-var lists with typos.","solutions":["Use IP literals: ['8.8.8.8', '1.1.1.1', '[2001:4860:4860::8888]:53'].","Resolve provider hostnames once at startup and feed the resulting IPs.","Validate every entry (IP literal, port 1-65535) before calling setServers."],"exampleFix":"// before\nresolver.setServers(['dns.google', 'https://1.1.1.1/dns-query']);\n\n// after\nresolver.setServers(['8.8.8.8', '1.1.1.1', '[2001:4860:4860::8888]:53']);","handlingStrategy":"validation","validationCode":"import { isIP } from 'node:net';\n\nfunction looksLikeServer(s) {\n  if (/^\\[[0-9a-fA-F:]+\\](:\\d+)?$/.test(s)) return true;      // [ipv6] or [ipv6]:port\n  if (/^(\\d{1,3}\\.){3}\\d{1,3}(:\\d+)?$/.test(s)) return true; // ipv4 or ipv4:port\n  return isIP(s) !== 0;                                       // bare ipv6\n}\nconst servers = configured.filter(looksLikeServer);\nif (servers.length) resolver.setServers(servers);","typeGuard":null,"tryCatchPattern":"try {\n  resolver.setServers(servers);\n} catch (err) {\n  if (err?.code === 'ERR_INVALID_IP_ADDRESS') {\n    logger.warn('invalid DNS server entry; keeping defaults', err.message);\n  } else {\n    throw err;\n  }\n}","preventionTips":["setServers accepts IP literals only - resolve provider hostnames (dns.google) to IPs at startup.","Bracket IPv6 literals when adding ports: [2001:4860:4860::8888]:53.","Validate DNS server config entries in CI with isIP-based checks."],"tags":["dns","set-servers","ip-address","resolver","configuration"],"backgroundTag":"dns-server-configuration","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}