Edited 2 weeks ago by ExtremeHow Editorial Team
DebianDNSBindNetworkingServer SetupLinuxOpen SourceSystem AdministrationCLIIT
This content is available in 7 different language
DNS, which stands for Domain Name System, is often called the phonebook of the Internet. It translates human-friendly domain names like www.example.com into IP addresses like 192.0.2.1 that computers use to identify each other on the network. BIND, which stands for Berkeley Internet Name Domain, is one of the most widely used DNS servers and is especially prominent in Unix-like systems like Debian.
In this guide, we will go through the steps required to install and configure the BIND DNS server on a Debian-based system. We will cover the installation process, basic configuration, and some of the essential tasks needed to set up a reliable DNS server.
Before you can install BIND on your Debian server you will need the following:
BIND is available in the default Debian repositories, so you can install it using the package manager apt. Follow the steps below to install BIND on your system.
sudo apt update
sudo apt install bind9 bind9utils bind9-doc -y
The bind9utils
package contains some useful command line utilities for interacting with DNS servers, and bind9-doc
contains documentation you may find useful.
After you have successfully installed BIND, you will need to configure it to work as your DNS server. The configuration files for BIND are usually located in the /etc/bind
directory.
The named.conf.options
file contains global DNS options. Open this file using a text editor:
sudo nano /etc/bind/named.conf.options
Inside this file, you'll find a section called options. Within options { }
block, you'll need to define a few key settings:
any
.any
.Here is an example configuration:
options { directory "/var/cache/bind"; forwarders { 8.8.8.8; 8.8.4.4; }; listen-on-v6 { any; }; allow-query { any; }; };
In the Domain Name System, a zone is a subset of the DNS database. A typical BIND setup involves defining the zones you want to manage or serve. You would define these in the named.conf.local
file.
Open the named.conf.local
file:
sudo nano /etc/bind/named.conf.local
In this file, you will configure a forward lookup zone (name to IP) and a reverse lookup zone (IP to name). Here is an example of both:
zone "example.com" { type master; file "/etc/bind/zones/db.example.com"; }; zone "1.168.192.in-addr.arpa" { type master; file "/etc/bind/zones/db.192"; };
In this setup:
example.com
stores the DNS records for that domain.1.168.192.in-addr.arpa
converts IP addresses in the 192.168.1.xxx range to domain names.Once you have your zones set up in the configuration file, it’s time to create the actual DNS records in the zone files.
Create a directory for your zone files:
sudo mkdir /etc/bind/zones
Now, create a zone file for your forward lookup zone:
sudo nano /etc/bind/zones/db.example.com
Here is an example of a forward lookup zone file. Adjust the details according to your domain and IP settings:
$TTL 604800 @ IN SOA ns1.example.com. admin.example.com. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. ns1 IN A 192.168.1.1 www IN A 192.168.1.2 ;
Next, create a zone file for your reverse lookup:
sudo nano /etc/bind/zones/db.192
And here's an example of a reverse lookup zone configuration:
$TTL 604800 @ IN SOA ns1.example.com. admin.example.com. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. 1 IN PTR ns1.example.com. 2 IN PTR www.example.com.
After modifying the configuration and creating the zone files, it is important to check that the syntax is correct before restarting the BIND server:
sudo named-checkconf
Also verify the zone files:
sudo named-checkzone example.com /etc/bind/zones/db.example.com
If the above commands return without any errors, then your configuration files are set up correctly.
After configuration, start the BIND service and make sure it runs on every system reboot:
sudo systemctl restart bind9
sudo systemctl enable bind9
Finally, test your DNS server to make sure it resolves queries correctly. Use the dig
command to query your DNS server. Make sure your server's IP address or "localhost" is specified as the server:
dig @localhost example.com
This command should return an A record for the configured domain. You can also test a reverse lookup:
dig @localhost -x 192.168.1.1
By following these steps, you have installed and configured a functional BIND DNS server on a Debian-based system. This server can now resolve and serve DNS queries for the domains and IPs you configured.
Remember, the BIND DNS server can be extended to include more advanced configurations such as caching strategies, access controls, and more complex zone setup for larger deployments.
If you find anything wrong with the article content, you can