— 10 July, 2014

I recently reinstalled my home server, and during the process, I decided to
throw away the heavy BIND nameserver from my application stack. I decided to
go with the light couple tinydns + dnscache.

This wasn't really "easy" to do so, as there are really few resources on the web
explaining the step to get this working (If you're aware of one, please send me
a link, I'll be glad to share it). So here is a full tutorial !

TL;DR

create tinydns zone file

make tinydns listen on 127.0.0.1

create the ip files for dnscache

create the servers file for dnscache containing 127.0.0.1

Fire it up

Enjoy.

The whole installation

First of all, I had to find out what were my needs. It seems stupid to say so,
but I have the bad habit to dive into configuration, barely knowing what I'm
trying to do. Here's what I wanted:

The DNS nameserver will be running on a machine with IP 10.0.0.1.
My local network will be named domain.lan.
I want all my machines to contact 10.0.0.1 to resolve URIs, and the server
will provide authoritative answers for domain.lan, and forward
everything else to some other servers.

How should we organise things then ?

Here's how I see it:

tinydns listens on 127.0.0.1

tinydns answers queries related to *.domain.lan

dnscache answer queries from any address

dnscache forwards queries related to *.domain.lan to ip 127.0.0.1

dnscache forwards everything else to others DNS

dnscache answers on any address

Let's set this up then!

tinydns

tinydns is fairly simple to use, and even more simple to configure. But it's
nothing you've ever seen before. You can configure tinydns from a single file:

In this directory, each file represent a domain, and the content of this file is
the list of the servers to contact in order to resolve those names.
"@" is a special name for the "fallback" entry.

In our case, we want tinydns to resolve names from "domain.lan", and forward
everything else to the root servers in the "@" file. To query tinydns, we
need to forward queries to 127.0.0.1. Here's how to do this:

# cat <<EOF > /etc/dnscache/servers/domain.lan
127.0.0.1
EOF

That's all. Pretty simple isn't it ?

It's now time to start dnscache. It needs (like tinydns) two environment
variables: ROOT for the configuration directory path, and IP for the address
of the interface to listen on (note that you can use 0.0.0.0 to listen on all
interfaces).