Raspberry Pi 5 DNS Server Lab

The Domain Name System (DNS) is a core part of how networks operate. It translates human-readable domain names into logical IP addresses (and vice versa). Allowing computers and devices to locate and communicate with one another across a network or the internet.

This lab demonstrates how to configure a Raspberry Pi 5 as a DNS server using both DNSMasq and BIND9. Each implementation is documented step-by-step, including setup, configuration, and validation.

View this project on GitHub

Part 1: Configuring DNSMasq

DNSMasq is a lightweight DNS forwarder and DHCP server suitable for small environments. It's efficient, simple to configure, and ideal for local caching.

1. Begin with updating software packages on Raspberry Pi with apt package manager.

Installing dnsmasq

2. Install the DNSMasq DNS software on the Raspberry Pi with apt package manager.

Editing dnsmasq config

3. Configure DNSMasq:

Configuring no-resolv

Here in the nano text editor, use CTRL + W to search and locate the following lines by removing the hash sign (#).

Adding Cloudflare DNS

#domain-needed

Setting cache size
Saving configuration
Restarting dnsmasq service

#bogus-priv

Testing from Windows client
Testing DNS resolution
Verifying configuration

#no-resolve

Verifying DNS query results
Verifying dnsmasq logs

#server=/local/192.168.0.1

Checking DNS configuration file
Testing network connectivity

#cache-size=150

Reviewing DNS cache entries
DNS query validation

4. Restart the dnsmasq service and verify the status.

Testing local domain

5. Configure Windows 11 Lab-Client with Raspberry Pi IP address as Preferred DNS Server.

Restarting network services

6. Run nslookup command to test out DNS server functionality with DNSMasq running on the Raspberry Pi.

Final dnsmasq verification

After configuration, the Raspberry Pi successfully caches DNS queries and forwards requests to Cloudflare's 1.1.1.1 and 1.0.0.1 servers.

From here, the Raspberry Pi IP address can be added as the DNS server IP on other devices.

Part 2: Configuring BIND9

BIND9 is a robust DNS server supporting authoritative and recursive resolution. This setup transforms the Raspberry Pi 5 into a local DNS authority for home.lan while forwarding external lookups to Cloudflare.

Static IP Configuration

To begin, the Raspberry Pi needs to be configured with a Static IP address. In order to do that, we need to systematically identify how networking is managed on the given Raspberry Pi OS.

Setting this up will ensure the Raspberry Pi retains the same IP address after rebooting, enabling reliable DNS, SSH, and other network services.

1. Identify the OS Version

Learn which networking framework the OS uses.

Here we see the OS Version Raspberry Pi OS Bookworm. This means the OS Version uses NetworkManager as the networking framework.

Check OS version

2. Verify Which Network Service Is Active

Confirm that NetworkManager is indeed running and controlling interfaces.

If it wasn't active, the configuration file /etc/dhcpcd.conf would be modified instead.

This prevents misconfigurations caused by editing the wrong files.

Identify service

3. List Active Network Connections

Discover the connection profile (e.g., "Wired Connection 1" or "WLAN connection 1").

You must know this name before modifying or applying static IP settings.

NetworkManager connections

4. Check Current Network Interface and IP

To confirm which interface (e.g., eth0, wlan0) is active and what IP/subnet the Pi currently uses.

This ensures your static IP stays in the same valid range and avoids conflicts.

In this example, I'm only using the command hostname -I, in other cases running ip a would be necessary.

Check hostname

5. Inspect Connection Settings

Verify whether the current IPv4 method is auto (DHCP).

You need to switch it to manual before applying a static address.

This step validates your assumptions before changing configuration.

Inspect network settings

6. Apply Static IP Configuration

To explicitly define:

This makes the Pi use a fixed IP address that won't change after reboots - critical for consistent DNS, SSH, or web service operations.

Apply static IP

7. Verify Connectivity and Persistence

Confirm that the Pi is reachable at its new static IP and still has internet access through the gateway.

This validation ensures that the configuration was applied correctly and is functioning as expected.

Verify IP config 1

Here at the bottom we see valid_lft forever preferred_lft forever indicating that this is a static IP configuration.

Verify IP config 2

Re-verify that the current Ipv4 method ipv4.method is set to manual.

Verify IP config 3

Verify connectivity:

Verify IP config 4

Installing and configuring BIND9

1. Installing BIND9

Now that the Raspberry Pi is configured with a Static IP address, we can install BIND.

In this example, I'm installing the program bind9 and bind9utils.

The bind9utils is not required, but does contain some useful tools for managing the DNS server.

Installing BIND9

Here, I'm setting up a forward lookup and reverse lookup zone.

Opening named.conf.local
Zone configuration

2. Specify Configuration Settings

The zones are specified in the /etc/bind/named.conf.local file.

With the zones set in the configuration file, the individual zone files need to be created like so.

Forward Lookup Zone:

Creating db.home.lan 1
Creating db.home.lan 2

Reverse Lookup Zone:

Editing reverse zone
PTR records

Options:

Configuring named.conf.options

Here, I'm going to set the Forwarders to two of Cloudflare's DNS servers.

With a DNS server now setup on the Raspberry Pi, the Raspberry Pi device now functions as a cache of DNS queries. As soon as the device queries a successful name resolution, that entry remains saved on the Raspberry Pi DNS server.

In this setup the DNS queries are still being forwarded to another DNS server.

The DNS server IP can be modified in the /etc/bind/named.conf.options by opening the file and changing the IP address in the Forwarders entry.

Adding forwarders
Restart BIND9 service

3. Restart bind9 service & verify functionality

And this is how you setup a DNS server with BIND on a Raspberry Pi 5.

For the configuration changes to take effect, restart bind9 like so after verifying the configuration.

Verify forwarders configuration
BIND9 status

Verification:

Testing with dig

The BIND9 configuration includes both forward and reverse zone definitions, along with Cloudflare's DNS for external resolution. Successful testing with dig confirms the DNS server's proper function.

Part 3: Results and Key Takeaways

Both DNS implementations demonstrate how the Raspberry Pi 5 can serve as a powerful and flexible DNS solution for lab or production networks.

This project demonstrates local name resolution, forward and reverse zone management, and verification using dig and systemctl. The lab also reinforces the importance of DNS in network infrastructure and the versatility of the Raspberry Pi 5.

Back to Home