Skip to main content

Quickstart

Create a DNS script, test it, publish it, and attach it to a hostname in your zone.
1

Create a DNS Script

In the bunny.net dashboard, go to DNS Scripts and click Add DNS Script.
2

Write your script

The Code editor opens with a starter script that answers every query with a TXT record:
Edit the script to return the response you need, such as an ARecord for IP-based routing. See the entry function below for the query details available to your script.
3

Test it

Use the fields below the editor to simulate a query: set the Type, Hostname, Client IP, EDNS IP, and Location, then click Run.The Response panel shows the DNS response your script returned, so you can try different request parameters and evaluate how your script behaves. Output from console.log appears in the Console tab.
4

Publish the script

Click Save to store your changes, then Publish to make the script live.
5

Attach it to a DNS Zone

A script only answers queries once a record points at it:
  1. Go to DNS and select your DNS Zone
  2. Click Add DNS Record
  3. Enter a Hostname
  4. Select SCR as the Type
  5. Select the script you just published in the Script dropdown
  6. Click Add Record
Queries for that hostname are now answered by your script.

Entry function

The Scriptable DNS pipeline executes through a statically defined function handleQuery. To return a response to the query, you can return one of the DNS response objects as documented in the Query Response Object Types.
console.log is intended for use within the Script Editor only. Please remove all logging statements before saving or publishing, as they may cause your script to fail at runtime.

Query object

The entry function is passed a DnsRequest object parameter called query that contains the information about the request, such as the hostname, country, remote IP, etc.

DnsRequest

DnsQuery

GeoLocation

Type safety

The Scriptable DNS runtime injects its globals (such as ARecord and the other response object types) directly into your script, and does not support import. The @bunny.net/scriptable-dns-types package provides ambient TypeScript declarations for these globals, giving you editor autocomplete and optional type checking without any runtime imports. Install it as a development dependency:
Then reference the types from within your script file with a triple-slash directive:
Or enable them project-wide through tsconfig.json:
Last modified on July 20, 2026