Tutorial: Install BIND9 DNS as a DNS Forwarder and Cache on Ubuntu 22.04
BIND9 (Berkeley Internet Name Domain) is one of the most widely used DNS software. In this tutorial, we will install and configure BIND9 as a DNS forwarder and cache that connects directly to the root DNS servers on Ubuntu 22.04.
Step 1: Update the System
First, ensure your system is up-to-date by running the following commands:
sudo apt update
sudo apt upgrade -y
Step 2: Install BIND9
Install BIND9 using the apt package manager:
sudo apt install bind9 bind9-utils bind9-doc -y
Step 3: Configure BIND9 as a Forwarder and Cache
After installation, we need to configure BIND9 to function as a DNS forwarder and cache.
1. Backup the Default Configuration
Before making changes, it’s recommended to back up the default configuration files:
sudo cp /etc/bind/named.conf.options /etc/bind/named.conf.options.bak
2. Edit the BIND9 Configuration File
Open the BIND9 configuration file with a text editor like nano:
sudo nano /etc/bind/named.conf.options
3. Add Forwarder and Cache Configuration
Add or edit the following section in the configuration file:
options {
directory "/var/cache/bind";
// Listen on all interfaces
listen-on { any; };
listen-on-v6 { any; };
// Enable DNS caching
recursion yes;
allow-recursion { any; };
// Use root hints for DNS resolution
dnssec-validation auto;
// Forward queries to upstream DNS servers
forwarders {
8.8.8.8;
8.8.4.4;
};
// Enable DNSSEC validation
dnssec-enable yes;
dnssec-lookaside auto;
// Cache settings
max-cache-size 256M;
max-cache-ttl 86400;
max-ncache-ttl 3600;
};
You can replace 8.8.8.8 and 8.8.4.4 with other DNS servers of your choice.
4. Download Root Hints
BIND9 requires a root hints file for DNS resolution. The root hints file is already included in the BIND9 installation, but you can update it manually if needed:
sudo wget -O /etc/bind/db.root https://www.internic.net/domain/named.cache
Step 4: Restart and Enable BIND9
After completing the configuration, restart BIND9 and enable it to start on boot:
sudo systemctl restart named
sudo systemctl enable named
Step 5: Test the Configuration
To ensure BIND9 is working correctly, you can test it using the dig command:
dig @127.0.0.1 google.com
If the configuration is successful, you will see the DNS query result from BIND9.
Step 6: Configure Clients to Use BIND9
Finally, configure your clients or devices to use BIND9 as the DNS server. You can change the DNS settings on your router or on individual devices.
Conclusion
By following this tutorial, you have successfully installed and configured BIND9 as a DNS forwarder and cache on Ubuntu 22.04. BIND9 will help improve the speed and reliability of your DNS resolution.