Getting Started with Scriptable DNS

The Scriptable DNS allows you to dynamically respond to DNS queries using JavaScript scripts. The following pages contain sample documentation to help you get started.

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.

export default function handleQuery(query) {
    return new ARecord("111.111.111.111", 30);
}

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:

  • request (DnsQuery) - The DNS query request that contains the details about the query

DnsQuery:

  • hostname (string) - The hostname that is being queried
  • clientIP (string) - The IP of the remote client that sent the DNS query
  • queryType (string) - The query question type (A, AAAA, TXT)
  • ednsIP (string) - The EDNS0 IP of the DNS query that was attached by the client
  • geoLocation (GeoLocation) - The server zone of the DNS server that received the query (DE, UK, SG, etc.)
  • serverZone (string) - The server zone of the DNS server that received the query (DE, UK, SG, etc.)

GeoLocation:

  • latitude (double) - The latitude location of the client
  • longitude (double) - The longitude location of the client
  • country (string) - The detected two letter ISO country code of the client
  • asn (long) - The detected ASN number of the client