Bun implements its own dns module and the node:dns module.
import * as dns from "node:dns";const addrs = await dns.promises.resolve4("bun.com", { ttl: true });console.log(addrs);// => [{ address: "172.67.161.226", ttl: 0 }, ...]
import { dns } from "bun";dns.prefetch("bun.com", 443);
Choosing a resolver backend
Bun.dns.lookup() accepts a backend option that selects the resolver implementation:
"c-ares": the c-ares asynchronous resolver. It reads /etc/resolv.conf directly, so it does not consult NSS modules such as systemd-resolved. This backend is the default for Bun.dns.lookup() on Linux.
"system": the platform’s own resolver (the non-blocking system API on macOS, getaddrinfo on a thread pool everywhere else). This backend is the default on macOS, Windows, and Android.
"getaddrinfo" (alias "libc"): the POSIX getaddrinfo(3) function on a thread pool.
import { dns } from "bun";const [{ address }] = await dns.lookup("example.com", { backend: "system" });
node:dns.lookup() always uses the "system" backend to match Node.js, whose dns.lookup() is documented as calling getaddrinfo(3). The node:dns.resolve*() functions use c-ares, as they do in Node.js.
DNS caching in Bun
Bun caches DNS lookups, which makes repeated connections to the same hosts faster.The cache holds up to 256 entries for a maximum of 30 seconds each. If a connection to a host fails, Bun removes that host’s entry from the cache. Simultaneous connections to the same host share one DNS lookup.Bun uses this cache automatically in:
bun install
fetch()
node:http (client)
Bun.connect
node:net
node:tls
When should I prefetch a DNS entry?
Web browsers expose <link rel="dns-prefetch"> to resolve a hostname before it’s needed. In Bun, dns.prefetch does the same thing: use it when you know you’ll connect to a host soon and want to avoid the initial DNS lookup.
import { dns } from "bun";dns.prefetch("my.database-host.com", 5432);
A database driver is a good example: prefetch the database host’s DNS entry when your application starts. By the time the rest of the application has loaded, the lookup may already be complete.
dns.prefetch
This API is experimental and may change in the future.
dns.prefetch resolves a hostname before you need it.
import { dns } from "bun";dns.prefetch("bun.com", 443);//// ... sometime later ...await fetch("https://bun.com");
dns.getCacheStats()
This API is experimental and may change in the future.
dns.getCacheStats() returns the current cache stats as an object with the following properties:
{ cacheHitsCompleted: number; // Cache hits completed cacheHitsInflight: number; // Cache hits in flight cacheMisses: number; // Cache misses size: number; // Number of items in the DNS cache errors: number; // Number of times a connection failed totalCount: number; // Number of times a connection was requested at all (including cache hits and misses)}
Bun caches DNS entries for 30 seconds by default. To change the TTL, set the $BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS environment variable. For example, to set it to 5 seconds:
BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS=5 bun run my-script.ts
Why is 30 seconds the default?
The system API underneath (getaddrinfo) does not expose the TTL of a DNS entry, so Bun has to pick a number. We chose 30 seconds because it’s long enough to see the benefits of caching and short enough to be unlikely to cause issues if a DNS entry changes. Amazon Web Services recommends 5 seconds for the Java Virtual Machine, though the JVM’s default is to cache indefinitely.
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Bun","colors":{"primary":"#ff73a8","light":"#ff73a8","dark":"#ff73a8"},"logo":{"light":"https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/logo/logo-with-wordmark-dark.svg?fit=max\u0026auto=format\u0026n=JUhaF6Mf68z_zHyy\u0026q=85\u0026s=3f55cd23822028e40658b192c927f3e4","dark":"https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/logo/logo-with-wordmark-light.svg?fit=max\u0026auto=format\u0026n=JUhaF6Mf68z_zHyy\u0026q=85\u0026s=8a0c5928d9dc3631f0d33e17c257e2ec"},"favicon":"https://mintcdn.com/bun-1dd33a4e/fU8ET1hSpIaJ6oEr/logo/bun.png?fit=max\u0026auto=format\u0026n=fU8ET1hSpIaJ6oEr\u0026q=85\u0026s=b8c01fba72c22f3094a710265a468e33","appearance":{"default":"system"},"background":{"decoration":"gradient"},"navbar":{"links":[{"icon":"download","href":"https://www.bun.com/docs/installation","label":"Install Bun"}]},"footer":{"socials":{"x":"https://x.com/bunjavascript","github":"https://github.com/oven-sh/bun","discord":"https://bun.com/discord","youtube":"https://www.youtube.com/@bunjs"}},"seo":{"metatags":{"canonical":"https://bun.com/docs"}},"fonts":{"heading":{"family":"Inter Display Bold","source":"https://mintlify-assets.b-cdn.net/fonts/InterDisplay-Bold.woff2","format":"woff2"}},"icons":{"library":"lucide"},"styling":{"codeblocks":{"theme":{"light":"github-light","dark":"dracula"}},"latex":false},"contextual":{"options":["copy","view","claude","mcp","vscode"],"display":"header"},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"bun-1dd33a4e","hasAudioNarration":false,"actualSubdomain":"bun-1dd33a4e","customDomains":["bun.com","bun.sh","bunjs.panticore.space"],"gitSource":{"type":"github","owner":"oven-sh","repo":"bun","deployBranch":"main","contentDirectory":"docs","isPrivate":false,"mountPath":"","label":""},"feedback":{"thumbs":true,"edits":true,"issues":true},"entitlements":{},"buildId":"6ae93e9e453bdad3d9d54b1b:success","clientVersion":"0.0.4270","searchFilterCounts":[{"language":"default","tag":"Guides","count":191},{"language":"default","tag":"Runtime","count":74},{"language":"default","tag":"Package Manager","count":44},{"language":"default","tag":"Test Runner","count":32},{"language":"default","tag":"Utilities","count":30},{"language":"default","tag":"Ecosystem \u0026 Frameworks","count":27},{"language":"default","tag":"Binary Data","count":22},{"language":"default","tag":"File System","count":21},{"language":"default","tag":"Bundler","count":13},{"language":"default","tag":"HTTP \u0026 Networking","count":13}]},"assistantConfig":{"askAiOnCodeBlock":false,"enableAskAiButton":false,"enableStarterQuestions":true,"enableAskAiSearchBar":true,"deflection":{"enabled":true,"email":"support@bun.com","showHelpButton":true}},"basePath":"/docs","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[{"_id":"68f7ce8d31e26413793acc35","deploymentId":"68a6511d649c76055d336e23","questionText":"How do I create a single-file executable with Bun?","status":"active","generatedBy":"manual","createdAt":"2025-10-21T18:18:53.168Z","updatedAt":"2025-10-21T18:18:53.168Z","__v":0},{"_id":"68f7cd1b31e26413793a5690","deploymentId":"68a6511d649c76055d336e23","questionText":"Does Bun's package manager support monorepos?","status":"active","generatedBy":"manual","createdAt":"2025-10-21T18:12:43.686Z","updatedAt":"2025-10-21T18:18:34.032Z","__v":0},{"_id":"68f7ccf531e26413793a4b79","deploymentId":"68a6511d649c76055d336e23","questionText":"How do I create an HTTP server with Bun?","status":"active","generatedBy":"manual","createdAt":"2025-10-21T18:12:05.087Z","updatedAt":"2025-10-21T18:12:05.087Z","__v":0}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":".steps{margin-top:0}div[data-component-part=\"card-icon\"]>svg{mask-size:80%}.font-mono{font-weight:700!important}.nav-tabs .nav-tabs-item{font-size:0.8rem!important}.mdx-content>span[data-as=\"p\"]{margin-bottom:2rem!important}.dark\\:bg-white\\/5:is(.dark *){background-color:rgb(155 155 155 / 5%)}ul#sidebar-group>li>a{font-size:0.825rem;line-height:1rem;font-weight:500}pre.shiki{line-height:1.4rem;font-size:0.8rem}.dark\\:ring-white\\/\\[0\\.14\\]:is(.dark *){border:1px solid rgb(255 255 255/0.14)!important;--tw-ring-color: transparent}.ring-transparent{border:1px solid transparent!important}.code-block:has([data-component-part=\"code-block-header\"]) div[data-component-part=\"code-block-root\"]{border-top-right-radius:0px!important;border-top-left-radius:0px!important}.code-group:has([data-component-part=\"code-group-tab-bar\"]) div[data-component-part=\"code-block-root\"]{border-top-right-radius:0px!important;border-top-left-radius:0px!important}img.code-block-icon{background:transparent!important}div[data-component-part=\"card-icon\"] img{background:transparent!important}html.dark .card-group .card:not(:hover){border:1px solid rgb(255 255 255/0.1)!important}html:not(.dark) .card-group .card{border:1px solid rgb(var(--gray-200))!important}.dark div[data-component-part=\"card-content-container\"]{background:rgb(255 255 255/0.03)}.card:hover{border-color:rgb(var(--gray-400) / var(--tw-border-opacity))!important}html.dark .shiki,html.dark .shiki span{background-color:transparent!important}.prose :where(hr):not(:where([class~=\"not-prose\"],[class~=\"not-prose\"] *)){margin-top:2rem!important;margin-bottom:2rem!important}footer#footer a[href*=\"mintlify.com\"]{display:none}.nav-tabs{width:100%!important}a[href=\"/guides\"],a[href=\"/docs/guides\"]{margin-left:auto!important}div[data-component-part=\"card-content-container\"]{height:100%!important}div#guides-list div[data-component-part=\"card-content-container\"]>*:nth-child(2){height:100%;display:flex;flex-direction:column;justify-content:space-between!important}.code-block+.code-block[language=\"text\"]{margin-top:-32px;z-index:-1;border-top-right-radius:0px;border-top-left-radius:0px;border-top:none}.code-block+.code-block[language=\"text\"],.code-block+.code-block[language=\"text\"] div[data-component-part=\"code-block-root\"]{background-color:rgb(var(--gray-50))!important}html.dark .code-block+.code-block[language=\"text\"],html.dark .code-block+.code-block[language=\"text\"] div[data-component-part=\"code-block-root\"]{background-color:#16171e!important}.code-block+.code-block[language=\"text\"] div.absolute.top-3{display:none}.code-block:has(+.code-block[language=\"text\"]){border-bottom-right-radius:0px;border-bottom-left-radius:0px}.code-block:has(+.code-block[language=\"text\"]) div[data-component-part=\"code-block-root\"]{border-bottom-right-radius:0px;border-bottom-left-radius:0px}div.callout .code-block{margin-bottom:0px}[language=\"shellscript\"] code span.line:not(:empty):has(span)::before{content:\"$ \";color:#6272a4;user-select:none}[language=\"shellscript\"] code span.line:has(>span:first-child[style*=\"color: rgb(98, 114, 164)\"])::before,[language=\"shellscript\"] code span.line:has(>span:first-child[style*=\"#6272A4\"])::before{content:\"\"}[language=\"powershell\"] code span.line:not(:empty):has(span)::before{content:\"> \";color:#6272a4;user-select:none}[language=\"powershell\"] code span.line:has(>span:first-child[style*=\"color: rgb(98, 114, 164)\"])::before,[language=\"powershell\"] code span.line:has(>span:first-child[style*=\"#6272A4\"])::before{content:\"\"}.dark [data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight,.dark [data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight:after,.dark [data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight:before{background:rgb(219 219 219 / 20%)!important}.dark[data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight:before{border-color:white}[data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight,[data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight:after,[data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight:before{background:rgb(var(--gray-200) / 0.5)!important}[data-component-part=\"code-block-root\"]:not(.has-line-numbers) .line-highlight:before{border-color:rgb(172, 172, 172)}"}]}
{"page":{"pagePath":"runtime/networking/dns","slug":"/runtime/networking/dns","pageMetadata":{"title":"DNS","description":"Use Bun's DNS module to resolve DNS records","href":"/runtime/networking/dns"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Use Bun’s DNS module to resolve DNS records\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,hr:`hr`,li:`li`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Bun implements its own `,_jsx(_components.code,{children:`dns`}),` module and the `,_jsx(_components.code,{children:`node:dns`}),` module.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`import`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#BD93F9`},children:` *`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:` as`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` dns `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`from`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:` \"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`node:dns`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`const`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#F8F8F2`},children:` addrs`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:` =`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:` await`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` dns.promises.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`resolve4`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun.com`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`, { ttl`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#FF79C6`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#BD93F9`},children:` true`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` });`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`console.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`log`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(addrs);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// => [{ address: \"172.67.161.226\", ttl: 0 }, ...]`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` { dns } `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`from`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:` \"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`dns.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`prefetch`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun.com`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`, `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#BD93F9`},children:`443`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`choosing-a-resolver-backend`,children:`Choosing a resolver backend`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`Bun.dns.lookup()`}),` accepts a `,_jsx(_components.code,{children:`backend`}),` option that selects the resolver implementation:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`\"c-ares\"`}),`: the `,_jsx(_components.a,{href:`https://c-ares.org/`,children:`c-ares`}),` asynchronous resolver. It reads `,_jsx(_components.code,{children:`/etc/resolv.conf`}),` directly, so it does not consult NSS modules such as `,_jsx(_components.code,{children:`systemd-resolved`}),`. This backend is the default for `,_jsx(_components.code,{children:`Bun.dns.lookup()`}),` on Linux.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`\"system\"`}),`: the platform’s own resolver (the non-blocking system API on macOS, `,_jsx(_components.code,{children:`getaddrinfo`}),` on a thread pool everywhere else). This backend is the default on macOS, Windows, and Android.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`\"getaddrinfo\"`}),` (alias `,_jsx(_components.code,{children:`\"libc\"`}),`): the POSIX `,_jsx(_components.code,{children:`getaddrinfo(3)`}),` function on a thread pool.`]}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` { dns } `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`from`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:` \"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`const`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` [{ `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#F8F8F2`},children:`address`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` }] `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`=`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:` await`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` dns.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`lookup`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`example.com`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`, { backend`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#FF79C6`},children:`:`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:` \"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`system`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` });`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`node:dns.lookup()`}),` always uses the `,_jsx(_components.code,{children:`\"system\"`}),` backend to match Node.js, whose `,_jsx(_components.code,{children:`dns.lookup()`}),` is documented as calling `,_jsx(_components.code,{children:`getaddrinfo(3)`}),`. The `,_jsx(_components.code,{children:`node:dns.resolve*()`}),` functions use c-ares, as they do in Node.js.`]}),`\n`,_jsx(Heading,{level:`2`,id:`dns-caching-in-bun`,children:`DNS caching in Bun`}),`\n`,_jsx(_components.p,{children:`Bun caches DNS lookups, which makes repeated connections to the same hosts faster.`}),`\n`,_jsx(_components.p,{children:`The cache holds up to 256 entries for a maximum of 30 seconds each. If a connection to a host fails, Bun removes that host’s entry from the cache. Simultaneous connections to the same host share one DNS lookup.`}),`\n`,_jsx(_components.p,{children:`Bun uses this cache automatically in:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.code,{children:`bun install`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.code,{children:`fetch()`})}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`node:http`}),` (client)`]}),`\n`,_jsx(_components.li,{children:_jsx(_components.code,{children:`Bun.connect`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.code,{children:`node:net`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.code,{children:`node:tls`})}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`when-should-i-prefetch-a-dns-entry`,children:`When should I prefetch a DNS entry?`}),`\n`,_jsxs(_components.p,{children:[`Web browsers expose `,_jsx(_components.a,{href:`https://developer.mozilla.org/en-US/docs/Web/Performance/dns-prefetch`,children:_jsx(_components.code,{children:`\u003clink rel=\"dns-prefetch\">`})}),` to resolve a hostname before it’s needed. In Bun, `,_jsx(_components.code,{children:`dns.prefetch`}),` does the same thing: use it when you know you’ll connect to a host soon and want to avoid the initial DNS lookup.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` { dns } `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`from`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:` \"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`dns.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`prefetch`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`my.database-host.com`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`, `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#BD93F9`},children:`5432`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`A database driver is a good example: prefetch the database host’s DNS entry when your application starts. By the time the rest of the application has loaded, the lookup may already be complete.`}),`\n`,_jsx(Heading,{level:`3`,id:`dns-prefetch`,children:_jsx(_components.code,{children:`dns.prefetch`})}),`\n`,_jsx(Warning,{children:`This API is experimental and may change in the future.`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`dns.prefetch`}),` resolves a hostname before you need it.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`dns.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`prefetch`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(hostname: string, port`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`?:`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` number): `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`void`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Here’s an example:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` { dns } `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`from`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:` \"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`dns.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`prefetch`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun.com`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`, `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#BD93F9`},children:`443`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`//`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// ... sometime later ...`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`await`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:` fetch`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`https://bun.com`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`dns-getcachestats`,children:_jsx(_components.code,{children:`dns.getCacheStats()`})}),`\n`,_jsx(Warning,{children:`This API is experimental and may change in the future.`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`dns.getCacheStats()`}),` returns the current cache stats as an object with the following properties:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`8`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#F8F8F2`},children:` cacheHitsCompleted`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`: number; `}),_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// Cache hits completed`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#F8F8F2`},children:` cacheHitsInflight`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`: number; `}),_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// Cache hits in flight`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#F8F8F2`},children:` cacheMisses`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`: number; `}),_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// Cache misses`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#F8F8F2`},children:` size`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`: number; `}),_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// Number of items in the DNS cache`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#F8F8F2`},children:` errors`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`: number; `}),_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// Number of times a connection failed`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#F8F8F2`},children:` totalCount`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`: number; `}),_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// Number of times a connection was requested at all (including cache hits and misses)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`}`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Example:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` { dns } `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`from`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:` \"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`bun`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`const`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#F8F8F2`},children:` stats`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:` =`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` dns.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`getCacheStats`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`console.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`log`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(stats);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6272A4`},children:`// => { cacheHitsCompleted: 0, cacheHitsInflight: 0, cacheMisses: 0, size: 0, errors: 0, totalCount: 0 }`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`configuring-dns-cache-ttl`,children:`Configuring DNS cache TTL`}),`\n`,_jsxs(_components.p,{children:[`Bun caches DNS entries for 30 seconds by default. To change the TTL, set the `,_jsx(_components.code,{children:`$BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS`}),` environment variable. For example, to set it to 5 seconds:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#BD93F9`},children:`BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`=`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`5`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:` bun`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:` run`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:` my-script.ts`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`4`,id:`why-is-30-seconds-the-default`,children:`Why is 30 seconds the default?`}),`\n`,_jsxs(_components.p,{children:[`The system API underneath (`,_jsx(_components.code,{children:`getaddrinfo`}),`) does not expose the TTL of a DNS entry, so Bun has to pick a number. We chose 30 seconds because it’s long enough to see the benefits of caching and short enough to be unlikely to cause issues if a DNS entry changes. `,_jsx(_components.a,{href:`https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/jvm-ttl-dns.html`,children:`Amazon Web Services recommends 5 seconds`}),` for the Java Virtual Machine, though the JVM’s default is to cache indefinitely.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"github-light","dark":"dracula"}},"config":{},"pageMetadata":{"title":"DNS","description":"Use Bun's DNS module to resolve DNS records","href":"/runtime/networking/dns"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Choosing a resolver backend","slug":"choosing-a-resolver-backend","depth":2,"children":[]},{"title":"DNS caching in Bun","slug":"dns-caching-in-bun","depth":2,"children":[{"title":"When should I prefetch a DNS entry?","slug":"when-should-i-prefetch-a-dns-entry","depth":3,"children":[]},{"title":"dns.prefetch","slug":"dns-prefetch","depth":3,"children":[]},{"title":"dns.getCacheStats()","slug":"dns-getcachestats","depth":3,"children":[]},{"title":"Configuring DNS cache TTL","slug":"configuring-dns-cache-ttl","depth":3,"children":[]},{"title":"Why is 30 seconds the default?","slug":"why-is-30-seconds-the-default","depth":4,"children":[]}]}],"codeExamples":{}},"jsLinks":["/docs/_mintlify/custom/bun-1dd33a4e/71a8c2a91b354e86/normalize-internal-links.js"],"subdomain":"bun-1dd33a4e","siteName":"Bun","title":"DNS - Bun","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-08-15T00:25:27.898Z","originalFileLocation":"runtime/networking/dns.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Use Bun\u0026#x27;s DNS module to resolve DNS records\">\u003cmeta data-mint-head name=\"application-name\" content=\"Bun\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"DNS - Bun\">\u003cmeta data-mint-head property=\"og:description\" content=\"Use Bun\u0026#x27;s DNS module to resolve DNS records\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Bun\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://bun.com/docs/runtime/networking/dns\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://bun-1dd33a4e.mintlify.site/docs/_mintlify/api/og/v2?division=Networking\u0026amp;title=DNS\u0026amp;description=Use+Bun%27s+DNS+module+to+resolve+DNS+records\u0026amp;theme=8ab97d844146c836dfe47641\u0026amp;signature=7eedff47e4e45396d4aed94067fee873fa9c399c80d3f4cb4717548c049e3b57\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"DNS - Bun\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Use Bun\u0026#x27;s DNS module to resolve DNS records\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://bun-1dd33a4e.mintlify.site/docs/_mintlify/api/og/v2?division=Networking\u0026amp;title=DNS\u0026amp;description=Use+Bun%27s+DNS+module+to+resolve+DNS+records\u0026amp;theme=8ab97d844146c836dfe47641\u0026amp;signature=7eedff47e4e45396d4aed94067fee873fa9c399c80d3f4cb4717548c049e3b57\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/docs/mintlify-assets/_mintlify/favicons/bun-1dd33a4e/EVjBxeJFWkPSAqAJ/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Bun\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#ff73a8\">\u003clink data-mint-head rel=\"canonical\" href=\"https://bun.com/docs/runtime/networking/dns\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/runtime/networking/dns.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://bun.com/#organization\",\"name\":\"Bun\",\"url\":\"https://bun.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/logo/logo-with-wordmark-dark.svg?fit=max\u0026auto=format\u0026n=JUhaF6Mf68z_zHyy\u0026q=85\u0026s=3f55cd23822028e40658b192c927f3e4\"}},{\"@type\":\"WebSite\",\"@id\":\"https://bun.com/docs#website\",\"name\":\"Bun\",\"url\":\"https://bun.com/docs\",\"publisher\":{\"@id\":\"https://bun.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://bun.com/docs/runtime/networking/dns#webpage\",\"url\":\"https://bun.com/docs/runtime/networking/dns\",\"name\":\"DNS\",\"description\":\"Use Bun's DNS module to resolve DNS records\",\"dateModified\":\"2026-08-15T00:25:27.898Z\",\"isPartOf\":{\"@id\":\"https://bun.com/docs#website\"},\"breadcrumb\":{\"@id\":\"https://bun.com/docs/runtime/networking/dns#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://bun.com/docs/runtime/networking/dns#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Networking\",\"item\":\"https://bun.com/docs/runtime/networking/fetch\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DNS\",\"item\":\"https://bun.com/docs/runtime/networking/dns\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://bun.com/docs/runtime/networking/dns#article\",\"headline\":\"DNS\",\"name\":\"DNS\",\"description\":\"Use Bun's DNS module to resolve DNS records\",\"url\":\"https://bun.com/docs/runtime/networking/dns\",\"mainEntityOfPage\":{\"@id\":\"https://bun.com/docs/runtime/networking/dns#webpage\"},\"dateModified\":\"2026-08-15T00:25:27.898Z\",\"publisher\":{\"@id\":\"https://bun.com/#organization\"},\"isPartOf\":{\"@id\":\"https://bun.com/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Bun\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Bun\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/docs/runtime/networking/dns.md","siteName":"Bun","nav":{"global":null,"tabs":[{"tab":"Runtime","icon":"cog","groups":[{"group":"Get Started","icon":"terminal","pages":[{"title":"Welcome to Bun","mode":"center","href":""},{"title":"Installation","href":"/installation"},{"title":"Quickstart","href":"/quickstart"},{"title":"TypeScript","href":"/typescript"},{"title":"TypeScript 6 and 7","href":"/typescript-6"},{"title":"bun init","href":"/runtime/templating/init"},{"title":"bun create","href":"/runtime/templating/create"}]},{"group":"Core Runtime","icon":"cog","pages":[{"title":"Bun Runtime","href":"/runtime/index"},{"title":"Watch Mode","href":"/runtime/watch-mode"},{"title":"Debugging","href":"/runtime/debugger"},{"title":"REPL","href":"/runtime/repl"},{"title":"bunfig.toml","href":"/runtime/bunfig"}]},{"group":"File \u0026 Module System","icon":"file","pages":[{"title":"File Types","href":"/runtime/file-types"},{"title":"Module Resolution","href":"/runtime/module-resolution"},{"title":"JSX","href":"/runtime/jsx"},{"title":"Auto-install","href":"/runtime/auto-install"},{"title":"Plugins","href":"/runtime/plugins"},{"title":"File System Router","href":"/runtime/file-system-router"}]},{"group":"HTTP server","icon":"server","pages":[{"title":"Server","href":"/runtime/http/server"},{"title":"Routing","href":"/runtime/http/routing"},{"title":"Cookies","href":"/runtime/http/cookies"},{"title":"TLS","href":"/runtime/http/tls"},{"title":"Error Handling","href":"/runtime/http/error-handling"},{"title":"Metrics","href":"/runtime/http/metrics"}]},{"group":"Networking","icon":"globe","expanded":true,"pages":[{"title":"Fetch","href":"/runtime/networking/fetch"},{"title":"WebSockets","href":"/runtime/http/websockets"},{"title":"TCP","href":"/runtime/networking/tcp"},{"title":"UDP","description":"Use Bun's UDP API to implement services with advanced real-time requirements, such as voice chat.","href":"/runtime/networking/udp"},{"title":"DNS","href":"/runtime/networking/dns"}]},{"group":"Data \u0026 Storage","icon":"database","pages":[{"title":"Cookies","description":"Use Bun's native APIs for working with HTTP cookies","href":"/runtime/cookies"},{"title":"File I/O","href":"/runtime/file-io"},{"title":"Streams","href":"/runtime/streams"},{"title":"Binary Data","href":"/runtime/binary-data"},{"title":"Archive","href":"/runtime/archive"},{"title":"SQL","href":"/runtime/sql"},{"title":"SQLite","href":"/runtime/sqlite"},{"title":"S3","href":"/runtime/s3"},{"title":"Redis","href":"/runtime/redis"}]},{"group":"Concurrency","icon":"split","pages":[{"title":"Workers","href":"/runtime/workers"}]},{"group":"Process \u0026 System","icon":"computer","pages":[{"title":"Environment Variables","href":"/runtime/environment-variables"},{"title":"Shell","href":"/runtime/shell"},{"title":"Spawn","href":"/runtime/child-process"},{"title":"WebView","href":"/runtime/webview"},{"title":"Cron","href":"/runtime/cron"}]},{"group":"Interop \u0026 Tooling","icon":"puzzle","pages":[{"title":"Node-API","href":"/runtime/node-api"},{"title":"FFI","href":"/runtime/ffi"},{"title":"C Compiler","href":"/runtime/c-compiler"},{"title":"Transpiler","href":"/runtime/transpiler"}]},{"group":"Utilities","icon":"wrench","pages":[{"title":"CSRF Protection","href":"/runtime/csrf"},{"title":"Secrets","href":"/runtime/secrets"},{"title":"Console","href":"/runtime/console"},{"title":"TOML","href":"/runtime/toml"},{"title":"YAML","href":"/runtime/yaml"},{"title":"Markdown","href":"/runtime/markdown"},{"title":"JSON5","href":"/runtime/json5"},{"title":"XML","href":"/runtime/xml"},{"title":"JSONL","href":"/runtime/jsonl"},{"title":"HTMLRewriter","href":"/runtime/html-rewriter"},{"title":"Image","href":"/runtime/image"},{"title":"Hashing","href":"/runtime/hashing"},{"title":"Glob","href":"/runtime/glob"},{"title":"Semver","href":"/runtime/semver"},{"title":"Color","href":"/runtime/color"},{"title":"Utils","href":"/runtime/utils"}]},{"group":"Standards \u0026 Compatibility","icon":"badge-check","pages":[{"title":"Globals","href":"/runtime/globals"},{"title":"Bun APIs","mode":"center","href":"/runtime/bun-apis"},{"title":"Web APIs","mode":"center","href":"/runtime/web-apis"},{"title":"Node.js Compatibility","href":"/runtime/nodejs-compat"}]},{"group":"Contributing","icon":"heart","pages":[{"title":"Roadmap","href":"/project/roadmap"},{"title":"Benchmarking","href":"/project/benchmarking"},{"title":"Contributing","href":"/project/contributing"},{"title":"Building Windows","href":"/project/building-windows"},{"title":"Bindgen","href":"/project/bindgen"},{"title":"License","href":"/project/license"}]}]},{"tab":"Package Manager","icon":"box","pages":[{"title":"Package Manager","href":"/pm/cli/install"}]},{"tab":"Bundler","icon":"combine","pages":[{"title":"Bundler","href":"/bundler"}]},{"tab":"Test Runner","icon":"flask-conical","pages":[{"title":"Test Runner","href":"/test"}]},{"tab":"Guides","icon":"map","pages":[{"title":"Guides","href":"/guides"}]},{"tab":"Reference","icon":"book","href":"https://bun.com/reference"},{"tab":"Blog","icon":"newspaper","href":"https://bun.com/blog"},{"tab":"Feedback","icon":"lightbulb","pages":[{"title":"Feedback","href":"/feedback"}]}]},"basePath":"","title":"DNS - Bun","deploymentId":"dpl_53YqbBPsHdrqSGqXiWPGU7csRVod","buildId":"dpl_53YqbBPsHdrqSGqXiWPGU7csRVod","dynamics":[],"chunks":[]}