Operating System CentOS

How to Install MaraDNS and Deadwood on AlmaLinux 9 or Rocky Linux 9

Build the current MaraDNS release from source on AlmaLinux 9 or Rocky Linux 9 and run Deadwood as a recursive DNS cache limited to your own networks.

This guide builds the current MaraDNS release from source on AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9 and sets up Deadwood, the recursive resolver that ships with it, as a caching DNS server for your own machines. At the end you will have a resolver managed by systemd that answers only the networks you allow.

Older tutorials on this topic targeted CentOS 6 and MaraDNS 2.0. CentOS 6 is end-of-life, and so are CentOS 7 and 8; AlmaLinux, Rocky Linux and CentOS Stream 9 are the replacements, and the steps below are the same on all three.

What to know before you start

MaraDNS is still published by its original author, but read the project status before you choose it:

  • The author describes MaraDNS as being in "deep freeze" since late 2022. It only receives fixes for important security holes and for compile errors with new GCC or Clang releases. No new features are planned.
  • The current series is 3.5. This guide uses release 3.5.0039, the stable version listed on the download page at the time of writing.
  • Deadwood is no longer a separate project. It is included in the MaraDNS tarball and is built and installed with it.
  • Deadwood does not support DNSSEC, and the README says that using it as a fully recursive server "is not guaranteed to be fully supported". By default it forwards queries to the Quad9 public resolvers instead of walking the DNS tree from the root servers.
  • There is no MaraDNS package in the AlmaLinux or Rocky base repositories, so you compile it. The upstream installer only guarantees boot-time start-up on Ubuntu 22.04, but states that it should also work on Rocky Linux, RHEL, CentOS and other systemd distributions.

If you need DNSSEC validation or a resolver under active development, install Unbound (sudo dnf install unbound) or BIND from the distribution repositories instead. MaraDNS remains a reasonable choice when you want a very small resolver for a private network.

Requirements

  • A server running AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9.
  • A user with sudo rights (the examples use deploy).
  • The server's IP address. The examples use 203.0.113.10 for the server and 198.51.100.0/24 for the client network that may use it.
  • Nothing else listening on port 53. Check with sudo ss -lntup | grep ':53 '.

Step 1: Update the system and install build tools

MaraDNS needs a C99 compiler, make and a POSIX shell environment. bind-utils provides dig for testing.

sudo dnf update -y
sudo dnf install -y gcc make tar xz curl bind-utils

Reboot if the update installed a new kernel.

Step 2: Download and compile MaraDNS

Download the source tarball from the official site and unpack it in your home directory. The configure script must be run from inside a directory whose name starts with maradns, which is the case when you extract the tarball as is.

cd ~
curl -O https://maradns.samiam.org/download/3.5/3.5.0039/maradns-3.5.0039.tar.xz
tar -xf maradns-3.5.0039.tar.xz
cd maradns-3.5.0039

Check the download page for a newer release first and adjust the version number in the commands if there is one.

./configure
make

If the build fails with GCC, the README recommends Clang: run sudo dnf install -y clang, then make clean, export CC=clang and make again.

Step 3: Install

sudo make install

The installer does the following:

  • copies the programs (maradns, Deadwood, askmara and others) and man pages under /usr/local;
  • creates /etc/mararc (authoritative server), /etc/dwood3rc (Deadwood) and the directory /etc/maradns, but only if they do not exist yet, so a reinstall keeps your configuration;
  • copies maradns.service, deadwood.service and colunacydns.service to /etc/systemd/system and enables maradns and deadwood at boot. It does not start them.

The maradns service is the authoritative server. If you only want a recursive resolver, disable it so it does not start at the next boot:

sudo systemctl disable maradns

Step 4: Configure Deadwood

Open the Deadwood configuration file:

sudo vi /etc/dwood3rc

The installed file binds Deadwood to 127.0.0.2 and only lets local addresses use it. Three settings matter for a resolver that serves other machines.

Listening addresses

Comment out the existing bind_address line and list every address Deadwood should listen on with ipv4_bind_addresses:

#bind_address="127.0.0.2" # IP we bind to
ipv4_bind_addresses = "203.0.113.10, 127.0.0.2"

Who may use the resolver

recursive_acl takes networks in IP/mask form. Replace the existing line with the loopback range plus your own client network:

recursive_acl = "127.0.0.0/8, 198.51.100.0/24"

Never allow 0.0.0.0/0. A resolver that answers the whole Internet will be abused for DNS amplification attacks.

Upstream or root servers

With neither upstream_servers nor root_servers set, Deadwood forwards to Quad9 (9.9.9.9 and 149.112.112.112). To forward to different resolvers, add:

upstream_servers = {}
upstream_servers["."]="198.51.100.53, 198.51.100.54"

To make Deadwood resolve names itself, uncomment the root_servers block that is already in the file instead. Keep in mind the upstream caveat about full recursion.

If the names you resolve point to private addresses (for example internal hosts in 10.0.0.0/8), also uncomment this line. By default Deadwood drops answers that contain private or loopback addresses:

filter_rfc1918 = 0

Leave chroot_dir, maradns_uid and maradns_gid as installed. Numeric values must not be quoted and string values must be quoted, otherwise Deadwood refuses to start.

Step 5: Start Deadwood and open the firewall

sudo systemctl start deadwood
sudo systemctl status deadwood

Allow DNS through firewalld only from the client network:

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="198.51.100.0/24" service name="dns" accept'
sudo firewall-cmd --reload

Step 6: Test the resolver

On the server:

dig @127.0.0.2 example.com A +short

From a machine in the allowed network:

dig @203.0.113.10 example.com A

A reply with status: NOERROR and an address in the answer section means the resolver works. A time-out from a client usually means the firewall rule or recursive_acl does not cover that client's address.

Maintenance and troubleshooting

  • Logs go to the journal: sudo journalctl -u deadwood -e. Configuration errors are reported there with the offending line.
  • After editing /etc/dwood3rc, run sudo systemctl restart deadwood.
  • To upgrade, download the new tarball, repeat steps 2 and 3 and restart the service. Your files in /etc are not overwritten.
  • If Deadwood cannot bind to port 53, another DNS service is using it. Find it with sudo ss -lntup | grep ':53 ' and stop it or bind Deadwood to a different address.

Reference: the MaraDNS site and the MaraDNS repository hold the download page, the README and the Deadwood manual.

Frequently asked questions

Is MaraDNS still maintained?

Yes, in a limited way. Releases still appear, but only to fix security problems and compiler errors. If you need new protocol features such as DNSSEC validation or DNS over TLS, choose Unbound, BIND or Knot Resolver.

What is the difference between maradns and Deadwood?

maradns is an authoritative server: it publishes the records of zones you own from files in /etc/maradns. Deadwood is the recursive cache that looks up other people's names for your clients. They are separate daemons with separate configuration files, and each needs its own IP address if both use port 53 on one host.

Can Deadwood listen on IPv6?

The sample configuration contains a commented bind_address="::1" line and IPv6 support is compiled in by default. Add your IPv6 networks to recursive_acl with a mask between 0 and 128 if you enable it.

Can I keep the cache across restarts?

Yes. Uncomment cache_file in /etc/dwood3rc and make sure the directory it points to inside chroot_dir is writable by the user ID Deadwood runs as. Without it the cache starts empty after every restart.

Share story:

Continue reading other guides on How VPS.