<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="tinydns">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>tinydns</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">djbwares</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>tinydns</refname>
<refpurpose>a general-purpose content DNS server using the UDP protocol</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>tinydns</command>
</cmdsynopsis>
</refsynopsisdiv>

<refsection>
<title>Description</title>

<para>
<command>tinydns</command> is a content DNS server that speaks the DNS/UDP protocol.
It accepts DNS queries from hosts around the Internet, and responds with locally configured information from a static database.
It runs in a system-secured environment and requires no privileges nor any filesystem access other than read access to its static database.
It logs a record of its operation simply to its standard error.
</para>

<para>
<command>tinydns</command> respects a location code system encoded in its database and differentiates amongst requesting clients according to their locations, determined by their IP addresses.
It is designed to be Internet-facing; and its normal use is for answering Internet DNS queries from hosts around the Internet.
It can also be employed locally on a LAN, or even locally within a single machine, for providing information to hosts on an intranet.
</para>

<para>
It is possible to run multiple entirely isolated instances on a single machine, each with their own static databases and listening on particular IP addresses for different purposes.
It is conversely possible to run multiple instances on a single machine, each listening on particular IP addresses, all sharing a single database.
</para>

<para>
Normally <command>tinydns</command> is run via a server program such as <command>udp-socket-listen</command> to listen for DNS/UDP queries.
It understands the <envar>LISTEN_PID</envar> and <envar>LISTEN_FDS</envar> environment variable convention for having an already-listening socket passed to it by such a program, and uses the last open file descriptor in the list that refers to a UDP/IPv4 socket.
If no such open file descriptor is provided it falls back to opening its own UDP/IPv4 socket, bound to port 53 of the IP address given by the value of the <envar>IP</envar> environment variable. 
It does not handle DNS/TCP.
</para>

<para>
<command>tinydns</command> rejects (sending a reply with an error code) zone-transfer requests, inverse queries, and packets that contain anything other than a single query.
It does not answer (single) non-Internet-class queries, or truncated packets.
</para>

<refsection>
<title>Answers</title>

<para>
<command>tinydns</command> answers queries as specified by <filename>data.cdb</filename>, a binary file in its root directory created by <citerefentry><refentrytitle>tinydns-data</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
It does not write to this file, or attempt to create it.
</para>

<para>
<command>tinydns</command> supports clients that negotiate large DNS/UDP response packet sizes with EDNS0.
When it has to truncate responses, when the conventional/EDNS0-negotiated response size is not large enough, it truncates all answer, authority, and additional section resource records.
</para>

<para>
<command>tinydns</command> includes <code>NS</code> records with answers to most queries. 
This increases DNS packet sizes, but it draws queries away from parent servers, and reduces the frequency of long DNS delays. 
With the default cache times, a client that uses a normal record at least once every day will always have the corresponding <code>NS</code> records cached and will never have to talk to parent servers.
</para>

<para>
If a record set has ending time ("time to die") for the information; <command>tinydns</command> dynamically adjusts the TTLs that it publishes so that the records are not cached for more than a few seconds past the ending time.
</para>

<para>
SOA resource records inform <command>tinydns</command> what requests to answer.
It will only answer at all for domain names where there is a <code>SOA</code> resource record at or above that domain name in the namespace.
</para>

<para>
There can be many <code>SOA</code> resource records for a domain, as the result of many <code>.</code> lines in the source data file.
<command>tinydns</command> will return only one <code>SOA</code> record per domain when the request is actually for a domain's <code>SOA</code> resource record set. 
</para>

<para>
<code>NS</code> resource records inform <command>tinydns</command> about delegation points (when they are not accompanied by <code>SOA</code> resource records).
It will always answer with a delegation response for domain names at or below a delegation point in the namespace.
</para>

<para>
<command>tinydns</command> returns IP addresses (i.e. <code>A</code> or <code>AAAA</code> records generated from <code>+</code> or <code>=</code> or <code>@</code> or <code>.</code> or <code>&#x26;</code> lines in the source data file) in a random order in the answer section. 
If there are more than 8 records, it returns a random list of 8.
(People used to use this as a mechanism for spreading server load across multiple machines; albeit that <ulink url="http://jdebp.uk./FGA/dns-round-robin-is-useless.html">this was highly flawed, for several reasons</ulink>.)
</para>

</refsection>

<refsection>
<title>Wildcards</title>

<para>
<command>tinydns</command> supports wildcards of the form <filename>*.<replaceable>fqdn</replaceable></filename>. 
Information for <filename>*.<replaceable>fqdn</replaceable></filename> is provided for every domain name ending with <filename>.<replaceable>fqdn</replaceable></filename>, except names that have their own records and names that are covered by more specific wildcards. 
</para>

<informalexample>
<para>
For example, the lines (as written in the original database source file)
</para>
<programlisting>+pink.floyd.u.heaven.af.example:203.0.113.4
+*.u.heaven.af.example:203.0.113.200</programlisting>
<para>
have the same effect as
</para>
<programlisting>+pink.floyd.u.heaven.af.example:203.0.113.4
+joe.u.heaven.af.example:203.0.113.200
+bill.u.heaven.af.example:203.0.113.200
+floyd.u.heaven.af.example:203.0.113.200
+ishtar.u.heaven.af.example:203.0.113.200
+joe.bob.u.heaven.af.example:203.0.113.200
+sally.floyd.u.heaven.af.example:203.0.113.200
+post.pink.floyd.u.heaven.af.example:203.0.113.200</programlisting>
<para>
and so on. 
</para>
</informalexample>

<informalexample>
<para>
As another example, the lines
</para>
<programlisting>+pink.floyd.u.heaven.af.example:203.0.113.4
@*.u.heaven.af.example::mail.heaven.af.example</programlisting>
<para>
have the same effect as
</para>
<programlisting>+pink.floyd.u.heaven.af.example:203.0.113.4
@joe.u.heaven.af.example::mail.heaven.af.example
@bill.u.heaven.af.example::mail.heaven.af.example
@floyd.u.heaven.af.example::mail.heaven.af.example
@ishtar.u.heaven.af.example::mail.heaven.af.example
@joe.bob.u.heaven.af.example::mail.heaven.af.example
@sally.floyd.u.heaven.af.example::mail.heaven.af.example
@post.pink.floyd.u.heaven.af.example::mail.heaven.af.example</programlisting>
<para>
and so on.
</para>

<para>
Notice that the wildcard does not apply to <filename>pink.floyd.u.heaven.af.example</filename>, because that name has its own records.
</para>
</informalexample>

</refsection>

</refsection>

<refsection>
<title>Security and privacy</title>

<para>
When it starts <command>tinydns</command> changes its root to the directory specified by the <envar>ROOT</envar> environment variable, and drops privileges to run as the user ID and group ID specified by the <envar>UID</envar> and <envar>GID</envar> environment variables.
The latter can be set up with <citerefentry><refentrytitle>envuidgid</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
</para>

<para>
<code>ANY</code> queries used to be used by a few mail systems as a shortcut for performing <code>A</code> and <code>MX</code> queries in one go, although were never guaranteed to work that way, it just being an accident of implementation of ISC BIND in the 1990s.
They are nowadays, instead, a common attack on the Domain Name System; as documented in RFC8482 in January 2019.
<command>tinydns</command> does not return any data other than <code>CNAME</code>s from the data file in response to an <code>ANY</code> query.
If the domain name exists and has no <code>CNAME</code>s, they are answered with a single synthesized <code>HINFO</code> record.
</para>

<para>
<command>tinydns</command> has always minimized other "amplification" attacks, where a client falsifies its reply IP address to direct responses to a third party, or asks about third parties in order to generate back-end query resolution traffic to those third parties.
When there is no <code>SOA</code> resource record at or above a queried domain name, <command>tinydns</command> simply sends no response at all.
And it neither does query resolution, nor has a back end where it performs any kind of transaction with another server.
</para>

<para>
Sending no response at all to non-Internet-class queries is a privacy measure.
ISC's BIND made this into a way to fingerprint DNS servers by responding with synthetic internal program version information to <code>TXT</code> type queries in the CHAOS class domain names such as <filename>version.bind</filename>.
Others even extended this into a more generic <filename>version.server</filename> domain name.
<command>tinydns</command> never imitated this; and has never given out internal version information.
</para>
<note>
<para>
ChaosNet was a short-lived Local Area Network protocol at MIT in the 1970s; and BIND simply repurposed what had by the late 1980s become a defunct query class.
The only other actually assigned non-Internet query class, in the 21st century, is Hesiod.
The only use of non-Internet query classes in the wild is for fingerprinting people's versions of ISC's BIND, Microsoft's DNS server, Knot DNS, PowerDNS, et al..
</para>
</note>

<para>
<command>tinydns</command> can be used for providing a private copy of the DNS "root", or indeed any other, data for reducing query traffic that goes off-organization, off-LAN, or even off-machine.
This is just a matter of obtaining those data, which are officially published for such use by several domain owners including the ICANN root, removing any overlaps/duplications of other data, and incorporating them into the static database file.
It is in fact the very same process as providing "secondary" service for a domain, <emphasis>sans</emphasis> the step of listing the <command>tinydns</command> instance as one of the servers for the domain in a <code>.</code> record in the database.
</para>

<para>
For best results, such data should be tagged with a location code that limits their visibility to only hosts within the organization/LAN, or to the local machine; or the instance of <command>tinydns</command> should not be listening on an Internet-routable IP address.
<command>tinydns</command> does not leak location-tagged data.
Answers given to clients in one location are not affected by the presence of data tagged for another location.
</para>
<note>
<para>
More specifically:
If <command>tinydns</command> has a location-tagged copy of the DNS "root" for on-intranet/LAN/machine use, this will not cause it to therefore answer all queries from off-intranet/LAN/machine clients just because there is a SOA resource record set for the <filename>.</filename> domain name in the database.
A single instance of <command>tinydns</command> can serve a private "root" to one set of locations whilst still being Internet-facing.
</para>
</note>

</refsection>

<refsection>
<title>History</title>
<para>
<command>tinydns</command> was originally part of <personname><firstname>Daniel</firstname> <othername>J.</othername> <surname>Bernstein</surname></personname>'s djbdns toolset in 1999.
It incorporated the functionality of <citerefentry><refentrytitle>pickdns</refentrytitle><manvolnum>1</manvolnum></citerefentry>, rendering that obsolete, in 2001.
</para>
<para>
<command>tinydns</command> ceased responding in the old style to <code>ANY</code>  queries in March 2019.
It ceased similarly treating the <code>ANY</code> <emphasis>class</emphasis> (as opposed to <emphasis>type</emphasis>) as a wildcard in July 2025.
It ceased responding to non-Internet-class queries in August 2025; prior to which it replied with an error response.
</para>
<para>
<command>tinydns</command> gained EDNS0 capability in 2025.
</para>
</refsection>

<refsection>
<title>Author</title>
<para>
Original code and documentation by <personname><firstname>Daniel</firstname> <othername>J.</othername> <surname>Bernstein</surname></personname>.
Documentation modernizations by <personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname>.
</para>
</refsection>

</refentry>
