Lookup the IP address for a hostname
Uses non-blocking APIs by default
Symbol
Lookup the IP address for a hostname
Uses non-blocking APIs by default
The hostname to lookup
Options for the lookup
const [{ address }] = await Bun.dns.lookup('example.com');
import { dns } from 'bun';
const [{ address }] = await dns.lookup('example.com', {family: 4});
console.log(address); // "123.122.22.126"
import { dns } from 'bun';
const [{ address }] = await dns.lookup('example.com', {family: 6});
console.log(address); // "2001:db8::1"
Bun supports three DNS resolvers:
c-ares
- Uses the c-ares library to perform DNS resolution. This is the default on Linux.system
- Uses the system's non-blocking DNS resolver API if available, falls back to getaddrinfo
. This is the default on macOS and the same as getaddrinfo
on Linux.getaddrinfo
- Uses the posix standard getaddrinfo
function. Will cause performance issues under concurrent loads.To customize the DNS resolver, pass a backend
option to dns.lookup
:
import { dns } from 'bun';
const [{ address }] = await dns.lookup('example.com', {backend: 'getaddrinfo'});
console.log(address); // "19.42.52.62"