Caddy DNS update

March 17, 2016


More light!

My “Port Caddy to be a DNS server”-project is alive and kicking. Code will be published soon-ish, mostly waiting for actually naming the bloody thing. Code is also littered with TODOs.

I’ve implemented the following middlewares, the all need tests and actual use, but here we go:

  • log, for logging (as in Caddy)
  • error, for error logging (as in Caddy). These both include the {{placeholder}} syntax, so you can use {{port}} and even {>} for logging header bits.
  • file, really, really stupid zone file backed zone implementation, more a proof of concept
  • reflect, reflect (test) middleware
  • proxy, proxy requests to an upstream nameserver/resolver

I also want to add a rewrite middleware that will, for instance, rewrite ANY queries to HINFO ones.

To give some feeling of what is possible, consider the following Caddyfile:

.:1053 {
    proxy .
} {

This defines two zones, . and that both listen on port 1053 for incoming queries. The root zone entry (.) loads a file from disk ( with the origin set to This means any query hitting Xaddy will be forwarded to this middleware. If the query falls in the domain is will be answered from the file. If it doesn’t ’t fall under the query will be proxied to Let’s see how this works with dig:

Query something under

% dig @localhost -p 1053 a
;			IN	A


Yep, looks like a correct answer from the contents of the file.

And now for something totally different domain, that should be proxied:

% dig @localhost -p 1053 mx
; EDNS: version: 0, flags:; udp: 512
;			IN	MX

;; ANSWER SECTION:		821	IN	MX	10		821	IN	MX	10		821	IN	MX	5		821	IN	MX	1		821	IN	MX	5

Note that this proxy implementation is a complete copy of the one in Caddy, so the health checking and the matching on specific names will work in the same way (eventually).

Queries for the zone will be processed by the second entry in the Caddyfile:

% dig @localhost -p 1053 TXT
;			IN	TXT

;; ANSWER SECTION:		1800	IN	TXT	"Hello!"

The reflect middleware will never be used in this case, because all queries for will be handled by the file middleware.

DNS  Caddy  Server  Middleware  core  coreDNS