Why Run Your Own DNS Server?
When configuring a router for an office or a home lab, most of us take the easiest path: entering Google’s 8.8.8.8 or Cloudflare’s 1.1.1.1. It is undeniably convenient. In return, however, your entire browsing history and query logs end up in the hands of third parties.
Not to mention undersea cable disruptions, where domain resolution latency can spike from 20ms to 300ms. Every click to open a website or curl command calling an API noticeably stutters.
To permanently solve this issue, I set up a dedicated Unbound server on Fedora Server 39. After six months of continuous operation serving about 25 devices on my local network, the service consumes under 65MB of RAM. Cache response times hover near 0ms, and most importantly: there is zero dependency on upstream DNS providers.
How Does Unbound Work?
Many people confuse Unbound with BIND9 or Dnsmasq. Before getting hands-on, let’s clarify three core concepts:
- Recursive Resolver: Unlike an authoritative server that only holds records for a specific domain (such as Route53), Unbound queries everything directly from the roots. When you look up
itfromzero.com, Unbound sequentially queries the Root Server (.) → TLD Server (.com) → Authoritative Server for that domain. The entire process is completely independent without any middleman. - DNSSEC Validation: A mechanism that verifies data integrity using digital signatures. If an attacker attempts DNS cache poisoning to redirect you to a malicious IP, the signature will be invalid. Unbound immediately drops the connection and returns a
SERVFAILcode to protect the client. - Caching: Once resolved, records are stored directly in RAM. When another device on your network needs the same query, Unbound returns the result instantly without sending a single packet out to the Internet.
Step-by-Step Implementation
Step 1: Install Unbound on Fedora
Fedora maintains software repositories very close to NLnet Labs upstream releases. Security patches often arrive just days after their official release. Install Unbound along with essential network utilities:
sudo dnf install unbound bind-utils -y
The bind-utils package provides the dig command, an indispensable tool for verifying DNS resolution results and DNSSEC flags in subsequent steps.
Step 2: Initialize the Root Anchor for DNSSEC
To validate DNSSEC, Unbound requires the public key of the Root Zone managed by ICANN. Although Fedora includes a default file, you should explicitly initialize the trust anchor key:
sudo unbound-anchor -a "/var/lib/unbound/root.key"
This command connects via HTTPS to IANA servers, verifies digital certificates, and writes a standard root.key file into the runtime directory.
Step 3: Craft a Performance-Optimized Configuration File
The default /etc/unbound/unbound.conf file contains hundreds of verbose comment lines. The best approach is to back up the original file and create a clean configuration:
sudo mv /etc/unbound/unbound.conf /etc/unbound/unbound.conf.bak
sudo nano /etc/unbound/unbound.conf
Paste the production configuration below:
server:
verbosity: 1
interface: 0.0.0.0
interface: ::0
port: 53
do-ip4: yes
do-ip6: yes
do-udp: yes
do-tcp: yes
# Restrict allowed query ranges to the local network
access-control: 127.0.0.0/8 allow
access-control: 192.168.1.0/24 allow
access-control: ::1 allow
# Hide version information to enhance security
hide-identity: yes
hide-version: yes
harden-glue: yes
harden-dnssec-stripped: yes
use-caps-for-id: no
# Enable DNSSEC validation
auto-trust-anchor-file: "/var/lib/unbound/root.key"
val-clean-additional: yes
# Cache optimization (tuned for 2 CPUs, 2GB-4GB RAM)
num-threads: 2
msg-cache-size: 64m
rrset-cache-size: 128m
infra-cache-numhosts: 10000
prefetch: yes
prefetch-key: yes
serve-expired: yes
serve-expired-ttl: 86400
# Service execution permissions
directory: "/etc/unbound"
username: "unbound"
Three notable options in the configuration above:
rrset-cache-size: 128m: Always set the RRset cache size to twice themsg-cache-sizeaccording to official NLnet Labs documentation to prevent memory waste.prefetch: yes: Automatically refreshes records before their TTL expires if frequently accessed. Users will always get cached results without experiencing re-resolution latency.serve-expired: yes: The biggest lifesaver during unstable international connectivity. If root servers fail to respond in time, Unbound serves expired records from cache instead of dropping the connection and reporting an error to the browser.
Verify the syntax before starting the service:
sudo unbound-checkconf
If the output shows unbound-checkconf: no errors in /etc/unbound/unbound.conf, your configuration is valid.
Step 4: Open Firewall Ports and Start the Service
Fedora enables firewalld by default with strict rules. Open port 53 for both UDP and TCP:
sudo firewall-cmd --add-service=dns --permanent
sudo firewall-cmd --reload
Enable and start Unbound on system boot:
sudo systemctl enable --now unbound
sudo systemctl status unbound
Step 5: Measure Performance and Test DNSSEC
Run a test query for a domain you haven’t accessed recently:
dig @127.0.0.1 itfromzero.com
Pay attention to the Query time line. On the first run, it typically ranges between 60ms and 180ms because the server must traverse multiple root and TLD levels. Now run the exact same command a second time:
dig @127.0.0.1 itfromzero.com
The result will now display Query time: 0 msec. The record is now cached directly in RAM.
Next, test the DNSSEC validation mechanism using two standard test domains provided by RIPE NCC:
# 1. Domain with valid DNSSEC signatures:
dig @127.0.0.1 sigok.verteiltesysteme.net +dnssec
The status returns status: NOERROR and includes the ad (Authenticated Data) flag. This confirms that the digital signature was successfully validated.
# 2. Domain with intentionally invalid signatures:
dig @127.0.0.1 sigfail.verteiltesysteme.net +dnssec
The status immediately changes to status: SERVFAIL with an empty ANSWER SECTION. Unbound detects the spoofed data and proactively blocks the threat to the client.
Conclusion
With just a lightweight Fedora virtual machine (1 vCPU, 1GB RAM) or an old Raspberry Pi, you have a fully functional recursive DNS resolver. No query logging. Noticeably faster page load times thanks to RAM caching. For the final step, simply point your router’s DHCP DNS settings to this Fedora server’s IP address, and every device on your home or office network will be automatically protected.

