Quickstart
Create a DNS script, test it, publish it, and attach it to a hostname in your zone.- Dashboard
- CLI
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:
- Go to DNS and select your DNS Zone
- Click Add DNS Record
- Enter a Hostname
- Select SCR as the Type
- Select the script you just published in the Script dropdown
- Click Add Record
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.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 asARecord 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:
tsconfig.json: