Updated April 18, 2023
Introduction to DNS Configuration in Linux
DNS(Domain Naming System) is an internet service that translates the domain name to IP address that is understandable by the computer. For example, the domain name www.domainsystem.com might translate to 198.105.232.4. This process is the backbone of the internet and very important in the server. In this topic, we are going to learn about DNS Configuration in Linux.
DNS Configuration
Before going for DNS configuration in Linux, one should first understand the basics of DNS and how it works.
1. Domain Names
Consider the website www.facebook.com. This is called FQDN (Fully Qualified Domain Name) Each domain consists of domain components, the dot separates these components.
The text com is the top-level domain component and Facebook is the second-level domain component and www is the third-level domain component
dot is called the root domain.
2. Subdomains
When you visit a website like newsroom.facebook.com. the newsroom here is a subdomain of facebook.com. Only the name servers for newsroom.facebook.com know all the hosts existing beneath it, so Facebook answers if there is newsroom subdomain or not, the root name servers have no clue about that.
Types of DNS Servers
There are three types of DNS servers:
Primary DNS servers: The primary DNS server holds the master copy of the domain’s configuration files. They contain information like IP address and administrator’s details.
Secondary DNS server (slave): They contain the read-only copy of domain information that they get from the primary DNS server. This is useful when the primary server is down the Secondary server acts as a backup.
Caching DNS server: A caching DNS server holds the data of recently requested queries from the users so that the workload of primary and secondary servers is reduced.
INSTALL BIND
Let’s see how to install bind on different Linux distributions.
On Debian/Ubuntu Linux, use the following syntax
$ sudo apt-get install bind9
On Redhat/CentOS/Fedora system, use the following syntax
# yum install bind9
/etc/bind directory contains all the DNS configurations. /etc/bind/named.conf is the primary configuration that includes all other needed files. The file named /etc/bind/db.root specifies the root nameservers in the world.
After completing the installation you can start it and enable it to run at boot time.
$ systemctl start named
$ systemctl enable named
CONFIGURING BIND
The service configuration file is /etc/named.conf file
DEFINING PRIMARY ZONE
For defining the primary zone in /etc/named.conf file the syntax is as follows
Zone "abcexample.com" {
Type master ;
File abcexample.com.db
};
The zone statement allows you to define a particular DNS zone.
The file which contains the zone information is located in the directory called /var/named.
Since this is the primary zone the type is master.
DEFINING A SECONDARY ZONE
Zone "abcexample.com" {
Type slave
masters Primary Nameserver IP Address Here; ;
file abcexample.com.db
};
The domain name in the secondary zone is the same as that of the primary zone and the type is slave since this is the secondary zone. the master’s option is to specify the IP addresses of the primary name server and the file indicates the path of the primary zone files.
DEFINING A CACHING ZONE
The caching zone decreases the queries on the DNS server. For defining a caching zone we need to define 3 zone sections.
Zone "." IN {
type hint;
file "root.hint";
};
Here the dot indicates the root name servers. The type hint indicates caching zone entry ane the file “root.hint”; specifies the file that contains the root servers.
Zone "localhost" IN {
type master;
file "localhost.db";
};
The third zone performs the reverse lookup for the localhost.
Zone "0.0.127.in-addr.arpa" IN {
type master;
file "127.0.0.rev";
};
Putting these three zones on /etc/named.conf will make our system work like a caching DNS server. Now we should type the content of the files referenced like abcexample.com.db, localhost.db, and 127.0.0.revThese files contain the DNS record types for each zone with some kind of options. Let us see about those record types.
DNS RECORD TYPES
SOA : start of authority record
SOA record is the information stored in the DNS zone about the zone and other records. It defines the properties of the zone.
It should contain the following information
Name of the zone
IN (zone class) IN stands for internet
Primary master name server
The serial number for the zone
Refresh, retry, expire and TTL time in seconds
SYNTAX
abcexample.com. 86400 IN SOA ns1.abcexample.com.mail.abcexample.com. (
2020020204 ;serial
86400 ;refresh, seconds
8200 ;retry, seconds
3600000 ;expire, seconds
86400 ;minimum, seconds
)
Query the SOA Record using
-query=soa
NAME SERVER RECORD(NS)
It is used to specify the name server for the zone.
SYNTAX
IN NS ns1.abcexample.com.
IN NS ns2.abcexample.com.
Query the NS Record using
-query=ns
ADDRESS RECORD(A & AAAA)
This record maps the hostname to the corresponding IP address
SYNTAX :
support IN A 192.168.1.5
POINTER RECORD (PTR)
This record does the opposite of the address record. It will map the IP address to the hostname
SYNTAX
192.168.1.5 IN PTR support.example.com.
MAIL EXCHANGE RECORD(MX)
It is a type of DNS record used to specify the mail server that is responsible for accepting emails on behalf of the domain.
SYNTAX
Domain TTL Class Type Priority Host
abcexample.com. 1936 IN MX 10 onemail.abcexample.com
abcexample.com. 1936 IN MX 10 twomail.abcexample.com
here the priority indicates which mail server should be preferred. Higher the priority value higher will be the priority.
Query the MX Record using
-query=mx
CANONICAL NAME RECORD(CNAME)
Canonical name record is a type of DNS record that specifies alias or nickname for the host.
NAME TYPE VALUE
--------------------------------------------------
abc.example.com. CNAME cab.example.com.
cab.example.com. A 192.0.2.23
TEXT RECORD (TXT)
A text record is a type of DNS record that enables you to add any text like the contact information or any other information that you want the users to know about your domain.
abcexample.com. IN TXT "welcome to our website"
DNS TTL VALUE
TTL stands for time to live.
The TTL value informs bind about the life span of each record. The unit used is in seconds. The common ttl value is 86400 ( 24 hours ). lower ttl may cause heavy traffic loads on the authoritative name server.
CATCHING CONFIGURATION ERRORS
You may make errors while writing a zone file. You can diagnose those errors from the log using the following syntax
$tail -f /var/log/messages
HOST COMMAND
After you have successfully added and modified your resource records you can check whether your host is resolved correctly using the following command
If you provide the hostname it will return the corresponding IP address
$ host abcexample.com
Also if you provide the IP address it will return the hostname.
$ host 192.168.1.5
WHOIS COMMAND
The whois command is used to get the details of the owner of the domain. The details may be information like a contact number or phone number.
$ whois abcexample.com
RNDC COMMAND
The rndc command is used to secure your name server from both locally and a remote place. To prevent any unauthorized access to your name server rndc must be configured on the selected port (port 953 by default)
You can check the status of the dns server using the following command.
$ rndc status
If you make any change to any of the zone files you can reload the service using the following command
$ rndc reload abcexample.com
You can reload all zone files using the following command
$ rndc reload
If you add new zones or you change the configuration of the server you can reload the configuration using the following command.
$ rndc reconfig
In this article, we have seen about DNS and how to install and configure the DNS server using Linux.
Recommended Articles
We hope that this EDUCBA information on “DNS Configuration in Linux” was beneficial to you. You can view EDUCBA’s recommended articles for more information.