Present JSON-data over DNS.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


json-dns provides a simple mechanism for querying some JSON-data via DNS lookups.

It is common for a number of related servers to need to lookup data about other hosts in the same cluster, for example:

  • The hostname of the database server.
  • The upload-location for some shared storage.

There are traditionally two ways to handle the discovery of this configuration data: Hardwire the details in a configuration file, or to allow local queries to be made against a remote store.

Many existing solutions allow queries via HTTP-fetches, but I was curious to see what it would be like to present the same data over DNS queries - because this allows fast local caching, and DNS has proven itself to be a nice robust solution in the past.


When the server is launched it will load the file json-dns.json from the current-working-directory.

This file is assumed to contain the data that you'll present to your clients, and if it is updated while the server is running this will be noticed, this repository contains a sample which is used in the example below.


Because our data is assumed to be nested-hashes there are two things you can lookup:

  • The data in a specific key, for example "db.user".
  • The hash of data beneath a specific key, for example "db".

In both cases the suffix of the query must be ".json", and the lookup must be of the record-type "TXT".

Queries could be made against the same data like so:

   $ dig  -t txt db.user.json @ -p 5555   +short

   $ dig  -t txt db.pass.json @ -p 5555   +short

   $ dig  -t txt db.json @ -p 5555   +short

Notice the third query resulted in something that looks like JSON? If you convert # to a quote it will parse as JSON successfully, the use of the hash-sign (#) is solely due to DNS-restrictions.


This code relies upon two perl Modules:

  • JSON * For encoding/decoding JSON data. * apt-get install libjson-perl.
  • Net::DNS::Nameserver * For serving DNS. * apt-get install libnet-dns-perl.


Steve Kemp