Category | |
DNS – Blog – 3 | |
Time to Read | |
30 Minutes | |
Who should read this blog.? | |
If you want to learn how to install and configure the bind9 utility on Ubuntu Linux Server and configure the DNS server as a Primary DNS server. |
Preface
Welcome to our latest blog post, where we’ll be exploring how to configure Ubuntu as Primary DNS name server. DNS is a critical component of any network, and having a reliable name server is essential for seamless communication between devices. In this article, we’ll guide you through the process of setting up and configuring Ubuntu as your primary name server, ensuring that your network is running smoothly and efficiently.
Let’s set up this topology to understand setting up an ubuntu server as DNS Server. we will add a client machine as well to test and get a complete understanding.

To run a DNS server as the primary DNS server using the bind9
the package on Ubuntu, follow these steps:
Install the bind9
package by running the following command in the terminal:
sudo apt-get install bind9
There is a handy package that is often installed with bind9 package is dnsutils. This enables to running of several DNS testing and troubleshooting commands.
sudo apt-get install dnsutils
Once bind9 package is installed and its configuration files are available in /etc/bind directory.
under this directory we see three named.conf files which are used for different configuration options.
/etc/bind/named.conf.options
:/etc/bind/named.conf.default-zones
:/etc/bind/named.conf.local
:
Named.conf.options File
the file is used for configuring the forwarders which means in this DNS configuration mode DNS Server works as a courier boy, it receives the DNS queries and the pass on the queries to configured Forwarder Server addresses, Which resolves and returns the query, the return queries are then cached by our local server for faster resolutions of the same queries. Refer below blog to know more.
/etc/bind/named.conf.default-zones File
The named.conf.default-zones is a configuration file used by the BIND DNS server to define the default DNS zones that will be served by the server by default.
the file includes preconfigured zone definitions for common types of DNS records, such as root hint localhost
, 127.in-addr.arpa
, and 255.in-addr.arpa
. These definitions are used to provide basic DNS functionality for the server and can be customized as needed.
// prime the server with knowledge of the root servers
zone "." {
type hint;
file "/usr/share/dns/root.hints";
};
// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912
zone "localhost" {
type master;
file "/etc/bind/db.local";
};
zone "127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};
zone "0.in-addr.arpa" {
type master;
file "/etc/bind/db.0";
};
zone "255.in-addr.arpa" {
type master;
file "/etc/bind/db.255";
};
The files path stores the records of the specific zone types like SOA records and Name Server records.
Let’s take a look at the local host file path –
root@linuxdns-vm01:/etc/bind# cat /etc/bind/db.local
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
@ IN A 127.0.0.1
@ IN AAAA ::1
/etc/bind/named.conf.local
File
Our Subject of interest !!
this is the file we use to define the local authoritative domains (Primary and Secondary) if a domain is configured under this file. Our server becomes the author of that domain and holds all DNS record types.
In this blog, we will configure our server as only the Primary DNS Server.
Let’s look at the content of our file before we start configuring it
root@linuxdns-vm01:/etc/bind# cat named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
};
Setting up the Forward Record
First thing first, let’s add our domain name – ‘mydomain.com’. Make sure it is uncommented
Command to Edit the file :
nano named.conf.local
zone "mydomain.com" {
type master;
file "/etc/bind/db.mydomain.com";
};
Ctrl+O - To write out , Enter to modify same file
Ctrl+X - To Exit
Tada !! this is how our file looks like now
root@linuxdns-vm01:/etc/bind# cat named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "mydomain.com" {
type master;
file "/etc/bind/db.mydomain.com";
};
Now we will add the records under my file db.mydomain.com created for mydomain.com.
Let’s make it easy – Remember we have a file already created for the localhost zones under a file named.conf.default-zones which pointed to a file db.local
root@linuxdns-vm01:/etc/bind# cat /etc/bind/db.local
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
@ IN A 127.0.0.1
@ IN AAAA ::1
root@linuxdns-vm01:/etc/bind#
Copy the content of db.local to our blank file db.mydomain.com
sudo cp /etc/bind/db.local /etc/bind/db.mydomain.com
Modify the db.mydomain.com files as
Modify SOA record name server – ns1.mydomain.com and define the name server and A type record.
We increase the serial no every time we make some changes in the file.
root@linuxdns-vm01:/etc/bind# nano db.mydomain.com
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA ns1.mydomain.com. root.mydomain.com. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.mydomain.com.
@ IN A 10.1.0.4
ns1 IN A 10.1.0.4
@ IN AAAA ::1
Ctrl+O - To write out , Enter to modify same file
Ctrl+X - To Exit
Once you have made changes to the zone file BIND9 needs to be restarted for the changes to take effect:
sudo systemctl restart bind9.service
Setting up the reverse zone
Now that the Forward zone is set up and resolving names to IP Addresses, the Reverse zone needs to be stepped to allow DNS to resolve an address to a name.
Edit /etc/bind/named.conf.local
and add the following:
nano named.conf.local
zone "0.1.10.in-addr.arpa" {
type master;
file "/etc/bind/db.10";
};
Ctrl+O - To write out , Enter to modify same file
Ctrl+X - To Exit
Replace 0.1.10 with the first three octets of whatever network you are using. Also, name the zone file /etc/bind/db.10.
It should match the first octet of your network.
This is how our named.conf.local file looks now
root@linuxdns-vm01:/etc/bind# cat named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "mydomain.com" {
type master;
file "/etc/bind/db.mydomain.com";
};
zone "0.1.10.in-addr.arpa" {
type master;
file "/etc/bind/db.10";
};
root@linuxdns-vm01:/etc/bind#
We have a blank file /etc/bind/db.10 is now created for the reverse record creation.
Remember we have a file already created for the localhost reverse zones under a file named.conf.default-zones which pointed to a file db.127
root@linuxdns-vm01:/etc/bind# cat db.127
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
1.0.0 IN PTR localhost.
root@linuxdns-vm01:/etc/bind#
Copy the content of db.127 to our blank file db.10, it would be easier to adjust the changes
sudo cp /etc/bind/db.127/etc/bind/db.10
Modify the entries of db.10 file as below
root@linuxdns-vm01:/etc/bind# nano db.10
;
; BIND reverse data file for local 10.1.0.XXX Network
;
$TTL 604800
@ IN SOA ns1.mydomain.com. root.mydomain.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.
4 IN PTR ns1.mydomain.com.
root@linuxdns-vm01:/etc/bind#
Ctrl+O - To write out , Enter to modify same file
Ctrl+X - To Exit
For each A record you configure in /etc/bind/db.mydomain.com
, that is for a different address, you need to create a PTR record /etc/bind/db.10. When you make the change increase the serial no by 1.
After Making the change Restart Bind9 service
sudo systemctl restart bind9.service