
How to Configure BIND as a Caching or Forwarding DNS Server on Ubuntu 24
Setting up BIND as a caching or forwarding DNS server on Ubuntu 24 can significantly improve your network’s DNS resolution performance and reduce external DNS queries. Whether you’re managing a corporate network, running multiple servers, or just want to optimize DNS lookups for your homelab, configuring BIND properly is essential for network efficiency. This guide walks you through the complete setup process, covering both caching and forwarding configurations, common troubleshooting scenarios, and performance optimization techniques that’ll save you hours of trial and error.
How BIND DNS Caching and Forwarding Works
BIND operates in two distinct modes that serve different networking needs. A caching DNS server stores DNS query results locally, reducing repeated lookups to external servers and speeding up response times for frequently accessed domains. When a client requests a domain that’s already cached, BIND serves the response instantly without hitting external DNS servers.
Forwarding mode takes a different approach – instead of performing recursive DNS resolution itself, BIND forwards all queries to specified upstream DNS servers like Google’s 8.8.8.8 or Cloudflare’s 1.1.1.1. This setup is particularly useful in corporate environments where you want centralized DNS control or need to route queries through specific DNS providers for security or compliance reasons.
Feature | Caching Mode | Forwarding Mode |
---|---|---|
Query Resolution | Recursive, contacts authoritative servers directly | Forwards queries to upstream DNS servers |
Network Traffic | Higher initial traffic, lower over time | Consistent traffic to forwarders |
Response Speed | Fast for cached entries, slower for new queries | Dependent on upstream server performance |
Control Level | Full control over resolution process | Limited to upstream server capabilities |
Resource Usage | Higher CPU/memory for recursive resolution | Lower resource usage |
Step-by-Step Installation and Basic Setup
Let’s start with installing BIND on Ubuntu 24 and getting the basic configuration running. The process is straightforward, but there are several configuration gotchas that can trip you up.
# Update package repositories
sudo apt update && sudo apt upgrade -y
# Install BIND9 and utilities
sudo apt install bind9 bind9utils bind9-doc dnsutils -y
# Check if BIND is running
sudo systemctl status bind9
# Enable BIND to start on boot
sudo systemctl enable bind9
Ubuntu 24 ships with BIND 9.18+, which includes several security improvements and performance enhancements over previous versions. The installation creates the necessary directory structure under /etc/bind/
and sets up default configuration files.
Before diving into specific configurations, let’s examine the default file structure:
# View the default configuration structure
ls -la /etc/bind/
# Output shows:
# named.conf - Main configuration file
# named.conf.options - Global options
# named.conf.local - Local zone definitions
# named.conf.default-zones - Default zones
# db.* - Zone database files
Configuring BIND as a Caching DNS Server
Setting up BIND as a caching server requires modifying the options configuration to enable recursion and define which clients can use the server. Here’s the complete configuration:
# Edit the main options file
sudo nano /etc/bind/named.conf.options
# Replace the contents with this configuration:
options {
directory "/var/cache/bind";
# Enable recursion for caching
recursion yes;
# Define which networks can query this server
allow-query {
localhost;
192.168.1.0/24; # Adjust to your network
10.0.0.0/8; # Private networks
172.16.0.0/12;
};
# Restrict recursion to trusted networks
allow-recursion {
localhost;
192.168.1.0/24; # Match your allow-query networks
10.0.0.0/8;
172.16.0.0/12;
};
# DNS over TCP
listen-on-v6 { any; };
listen-on { any; };
# Root hints file
file "/usr/share/dns/root.hints";
# Cache settings
max-cache-size 256m;
max-cache-ttl 86400; # 24 hours
max-ncache-ttl 3600; # 1 hour for negative caching
# Security settings
allow-transfer { none; };
auth-nxdomain no;
dnssec-validation auto;
# Rate limiting to prevent abuse
rate-limit {
responses-per-second 10;
window 5;
};
};
The caching configuration includes several important parameters. The max-cache-size
setting limits memory usage – 256MB is suitable for most small to medium networks, but you can increase this for high-traffic environments. The TTL settings control how long records stay cached, balancing performance with data freshness.
Validate and restart the configuration:
# Check configuration syntax
sudo named-checkconf
# If no errors, restart BIND
sudo systemctl restart bind9
# Monitor logs for any issues
sudo journalctl -u bind9 -f
Setting Up BIND as a Forwarding DNS Server
Forwarding mode is excellent for environments where you want to use specific upstream DNS providers while still maintaining local caching. This configuration sends all queries to designated forwarders:
# Edit options for forwarding mode
sudo nano /etc/bind/named.conf.options
# Forwarding configuration:
options {
directory "/var/cache/bind";
# Enable forwarding mode
forward only; # Use "forward first" for fallback behavior
forwarders {
1.1.1.1; # Cloudflare primary
1.0.0.1; # Cloudflare secondary
8.8.8.8; # Google primary
8.8.4.4; # Google secondary
};
# Client access controls
allow-query {
localhost;
192.168.1.0/24; # Your network range
};
# Disable recursion since we're forwarding
recursion yes; # Keep enabled for client functionality
allow-recursion {
localhost;
192.168.1.0/24;
};
# Listening configuration
listen-on-v6 { any; };
listen-on { any; };
# Cache configuration (still useful for forwarded responses)
max-cache-size 128m;
max-cache-ttl 86400;
# Security settings
allow-transfer { none; };
auth-nxdomain no;
dnssec-validation yes;
# Performance tuning
minimal-responses yes;
prefetch 2 9; # Prefetch records that expire soon
};
The key difference here is the forward only
directive, which ensures all queries go to the specified forwarders. Using forward first
instead allows BIND to fall back to recursive resolution if forwarders fail, providing better resilience at the cost of potentially inconsistent behavior.
Advanced Configuration and Performance Tuning
For production environments, several additional configurations can significantly improve performance and security. Here’s an enhanced setup that addresses real-world requirements:
# Create a comprehensive configuration
sudo nano /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
pid-file "/run/named/named.pid";
# Forwarder configuration with performance optimization
forward first;
forwarders {
1.1.1.1 port 53;
1.0.0.1 port 53;
8.8.8.8 port 53;
8.8.4.4 port 53;
};
# Network and client settings
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
allow-query {
localhost;
localnets; # Automatically includes local subnets
192.168.0.0/16; # Broader private range if needed
};
allow-recursion {
localhost;
localnets;
};
# Performance optimization
recursive-clients 1000; # Max concurrent recursive queries
tcp-clients 100; # Max TCP connections
max-cache-size 512m; # Increase for high-traffic environments
cleaning-interval 60; # Cache cleanup frequency (minutes)
heartbeat-interval 60; # Health check interval
# Query optimization
minimal-responses yes; # Reduce response size
prefetch 3 9; # Prefetch records expiring in 9s if TTL > 3s
qname-minimisation relaxed; # Privacy enhancement
# Logging optimization
querylog no; # Disable query logging for performance
# Security enhancements
recursion yes;
allow-transfer { none; };
allow-update { none; };
version none; # Hide BIND version
hostname none; # Hide hostname
# DNSSEC configuration
dnssec-validation auto;
dnssec-lookaside auto;
# Rate limiting
rate-limit {
responses-per-second 20;
window 5;
log-only no;
qps-scale 250;
slip 2;
};
};
# Logging configuration for troubleshooting
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
channel security_log {
file "/var/log/named/security.log" versions 3 size 30m;
severity info;
print-time yes;
print-severity yes;
print-category yes;
};
category security { security_log; };
category dnssec { security_log; };
};
Real-World Use Cases and Examples
Different network environments benefit from specific BIND configurations. Here are several practical scenarios with tailored setups:
Corporate Network with Split DNS
Many organizations need to resolve internal domains differently from external ones. This configuration handles both scenarios:
# Add to /etc/bind/named.conf.local
zone "internal.company.com" {
type master;
file "/etc/bind/db.internal.company.com";
allow-update { none; };
};
# External forwarding for everything else
zone "." {
type hint;
file "/usr/share/dns/root.hints";
};
# Create the internal zone file
sudo nano /etc/bind/db.internal.company.com
$TTL 604800
@ IN SOA internal.company.com. admin.internal.company.com. (
2024010101 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
@ IN NS ns1.internal.company.com.
ns1 IN A 192.168.1.10
server1 IN A 192.168.1.100
server2 IN A 192.168.1.101
database IN A 192.168.1.200
High-Performance Homelab Setup
For homelab environments with multiple VMs and containers, this configuration maximizes caching efficiency:
# Optimized for homelab with Docker/containers
options {
directory "/var/cache/bind";
# Aggressive caching for homelab
max-cache-size 1g;
max-cache-ttl 604800; # 7 days
max-ncache-ttl 86400; # 1 day negative cache
# Support for container networks
allow-query {
localhost;
192.168.0.0/16; # Home network
172.16.0.0/12; # Docker default
10.0.0.0/8; # Container networks
};
# Fast forwarders for homelab
forward first;
forwarders {
1.1.1.1; # Cloudflare (often fastest)
9.9.9.9; # Quad9 (security-focused)
};
# Optimize for local development
prefetch 5 15;
minimal-responses no; # Full responses for development
recursion yes;
};
Performance Monitoring and Troubleshooting
Monitoring BIND performance is crucial for maintaining optimal DNS resolution. Here are essential commands and techniques for tracking performance:
# Check BIND statistics
sudo rndc stats
sudo cat /var/cache/bind/named.stats
# Monitor query patterns
sudo rndc querylog on
sudo tail -f /var/log/syslog | grep named
# Test DNS resolution performance
dig @localhost google.com +stats
dig @localhost facebook.com +stats
# Check cache hit rates
sudo rndc dumpdb -cache
sudo grep -c "cached" /var/cache/bind/named_dump.db
Common performance issues and their solutions:
- High memory usage: Reduce
max-cache-size
or increasecleaning-interval
- Slow responses: Check forwarder performance with
dig @1.1.1.1 domain.com +stats
- Cache misses: Increase TTL values or enable prefetching
- Security alerts: Review
allow-query
andallow-recursion
settings
Security Best Practices and Common Pitfalls
DNS servers are frequent attack targets, making security configuration critical. Here are essential security measures:
# Enhanced security configuration
options {
# Restrict zone transfers completely
allow-transfer { none; };
# Prevent cache poisoning
dnssec-validation auto;
dnssec-lookaside auto;
# Hide server information
version none;
hostname none;
server-id none;
# Implement response rate limiting
rate-limit {
responses-per-second 15;
window 5;
log-only no;
qps-scale 250;
slip 2;
exempt-clients { localhost; };
};
# Restrict recursion to known networks only
allow-recursion {
localhost;
192.168.1.0/24; # Specific networks only
};
# Additional security options
empty-zones-enable yes;
disable-empty-zone "10.in-addr.arpa";
blackhole {
0.0.0.0/8;
169.254.0.0/16;
224.0.0.0/4;
};
};
Common security pitfalls to avoid:
- Never set
allow-recursion { any; }
– this creates an open resolver - Don’t disable DNSSEC validation without good reason
- Always restrict
allow-query
to known networks - Enable logging for security events and monitor regularly
- Keep BIND updated – Ubuntu 24’s package manager handles this well
Comparison with Alternative DNS Solutions
While BIND remains the gold standard for DNS servers, several alternatives offer different advantages depending on your use case:
Solution | Memory Usage | Configuration Complexity | Performance | Best Use Case |
---|---|---|---|---|
BIND 9 | High (100-500MB+) | Complex but flexible | Excellent for large networks | Enterprise, complex DNS needs |
Unbound | Low (20-100MB) | Moderate | Fast, security-focused | Privacy-conscious setups |
dnsmasq | Very Low (5-20MB) | Simple | Good for small networks | Home routers, IoT devices |
PowerDNS | Moderate (50-200MB) | Database-driven | Highly scalable | Large-scale hosting providers |
CoreDNS | Low (30-80MB) | Plugin-based | Modern, cloud-native | Kubernetes, microservices |
BIND’s strength lies in its maturity, extensive feature set, and excellent documentation. For learning DNS concepts or managing enterprise networks, BIND provides unmatched flexibility. However, for simple caching scenarios, lighter alternatives like Unbound might be more appropriate.
The choice often comes down to specific requirements. BIND excels when you need complex zone management, detailed logging, or integration with existing enterprise infrastructure. Its configuration syntax, while initially complex, becomes second nature and offers precise control over DNS behavior.
For additional information and advanced configuration options, consult the official BIND 9 documentation at https://bind9.readthedocs.io/ and the Internet Systems Consortium’s resource center at https://www.isc.org/bind/.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.