Setting up a personal DNS server offers a great way to learn about DNS and control your local network. A Raspberry Pi, with its affordability and accessibility, makes this a surprisingly simple project. This guide will walk you through the process, enabling you to manage DNS records for your home network.
Table of Contents
- Setting a Static IP Address on Your Raspberry Pi
- Setting Up the DNS Server (Bind9)
- Testing Your DNS Server
Setting a Static IP Address on Your Raspberry Pi
Before configuring your DNS server, it’s crucial to assign a static IP address to your Raspberry Pi. This prevents IP address changes from disrupting DNS functionality. We’ll use the Raspberry Pi Configuration Tool:
- Access the Configuration Tool: Open a terminal on your Raspberry Pi (or via SSH) and type:
- Network Options: Navigate to “5 Interfacing Options” then “P5 Network Configuration”.
- Set Static IP: Select “Manual” configuration. Enter your desired static IP address, subnet mask, gateway, and DNS server addresses (use your router’s DNS servers temporarily). Ensure the IP address is within your network’s range and doesn’t conflict with other devices. Note down these settings.
- Save and Reboot: Save changes and reboot your Raspberry Pi using:
- Verify: After rebooting, verify your static IP using:
sudo raspi-config
sudo reboot
ip addr show
Setting Up the DNS Server (Bind9)
We’ll utilize Bind9, a reliable and widely-used DNS server.
- Update Packages: Update your Raspberry Pi’s package list:
- Install Bind9: Install Bind9 and its utilities:
- Configure Bind9: The primary configuration file is located at `/etc/bind/named.conf.local`. Add entries for your domains. For example, to serve records for `example.local`, add:
- Create the Database File: Create `/etc/bind/db.example.local` with the following (replace placeholders with your information):
- Restart Bind9: Restart Bind9 to implement changes:
- Firewall (Optional): If using a firewall (e.g., `ufw`), allow DNS traffic (port 53):
sudo apt update
sudo apt install bind9 bind9utils
zone "example.local" {
type master;
file "/etc/bind/db.example.local";
};
$TTL 604800
@ IN SOA raspberrypi.example.local. admin.example.local. (
2023102702 ; Serial (increment this number with each change)
86400 ; Refresh
7200 ; Retry
3600000 ; Expire
604800 ; Negative Cache TTL
)
@ IN NS raspberrypi.example.local.
raspberrypi IN A 192.168.1.100
www IN A 192.168.1.100
sudo systemctl restart bind9
sudo ufw allow 53/udp
sudo ufw allow 53/tcp
Testing Your DNS Server
- Client Configuration: On a device in your network, change its DNS server settings to your Raspberry Pi’s static IP address.
- Test Resolution: Ping or browse to a hostname defined in `db.example.local` (e.g., `raspberrypi.example.local` or `www.example.local`). Successful resolution confirms your DNS server is operational. If not, double-check your configuration files.
Remember to replace placeholder values with your actual IP addresses and domain names. This is a basic setup; for advanced configurations, consult the Bind9 documentation. Always back up configuration files before making changes.