How to Set up DNS Server on Ubuntu 22.04 / Ubuntu 20.04 | Holhol24

0

A domain Name System is an internet service used to resolve a domain name to IP Address and vice versa. This DNS service relieves us from remembering IP addresses to reach any services over the internet or intranet.

Here, we will see how to set up DNS server on Ubuntu 22.04 / Ubuntu 20.04.

Set up Environment

Let us create a DNS server for the holhol24.local domain. You may also change it as per your requirement.

Domain Name: holhol24.local

DNS Server Name: ns.holhol24.local

IP Address: 192.168.0.10

Additionally, you need to ensure sure the DNS server has a static IP address.

READ: How to configure static ip address in Ubuntu 22.04/20.04

Install DNS Server

First, update the repository index.

sudo apt update

The package name of the DNS server in the Ubuntu operating system is bind9. It is available in the base OS repository. So, you can use the apt command to install the bind9 package along with other utility packages.

sudo apt install -y bind9 bind9-utils

Creating DNS Zones and Zone Files

Creating DNS Zones

The /etc/bind/ is the configuration directory for the DNS server that holds configuration files and zone files. The global configuration file for DNS server is /etc/bind/named.conf.

For the zone creations, use the /etc/bind/named.conf.local file instead of the global configuration file.

Let us begin by creating DNS zones for your domain.

sudo nano /etc/bind/named.conf.local

Creating Forward Zone

The following is the forward zone entry for the holhol24.local domain in the named.conf.local file. This forward zone translates a fully qualified domain name (FQDN) into an IP address.

zone "holhol24.local" IN { // Domain name

     type master; // Primary DNS

     file "/etc/bind/holhol24.local.db"; // Forward Zone file

     allow-update { none; }; // Since this is the primary DNS, it should be none.

};

Creating Reverse Zone

The following is for the reverse name resolution zone in the named.conf.local file. This forward zone translates an IP address into a fully qualified domain name (FQDN).

zone "0.168.192.in-addr.arpa" IN { // Reverse lookup name, should match your network in reverse order

     type master; // Primary DNS

     file "/etc/bind/r.holhol24.local.db"; // Reverse lookup file

     allow-update { none; }; // Since this is the primary DNS, it should be none.

};

Creating Zone Files

Once you have created DNS zones, create DNS zone files for the forward and reverse zones.

Creating Forward Zone File

Create a  zone file /etc/bind/holhol24.local.db for the forward zone.

sudo nano /etc/bind/holhol24.local.db

Record types in the zone file,

SOA – Start of Authority
NS – Name Server
A – A record
MX – Mail for Exchange
CN – Canonical Name

Domain names should end with a dot (.).

Whenever you change any records in the zone file, update the serial number +1 with the current number.

$TTL    86400
@       IN      SOA     ns.holhol24.local. root.holhol24.local. (
                         200101         ; Serial
                         21600          ; Refresh
                         3600           ; Retry
                         604800         ; Expire
                         86400 )        ; Negative Cache TTL
;
;Name Server Information

@        IN      NS      ns.holhol24.local.

;IP address of Name Server

ns      IN      A       192.168.0.10  

;Mail Exchanger

@       IN     MX   10   mail.holhol24.local.

;A – Record HostName To Ip Address

www     IN       A      192.168.0.101
mail    IN       A      192.168.0.102

;CNAME record

ftp     IN      CNAME   www.itgeek.local.

Creating Reverse Zone File

Create a zone file /etc/bind/r.holhol24.local.db for the reverse zone.

sudo nano /etc/bind/r.holhol24.local.db

Update the content as shown below.

PTR – Pointer
SOA – Start of Authority

Whenever you change any records in the lookup file, update the serial number +1 with the current number.

$TTL    86400
@       IN      SOA     ns.holhol24.local. root.holhol24.local. (
                         200101         ; Serial
                         21600          ; Refresh
                         3600           ; Retry
                         604800         ; Expire
                         86400 )        ; Negative Cache TTL
;
;Name Server Information

@       IN      NS     ns.holhol24.local.

;Reverse lookup for Name Server

10      IN      PTR    ns.holhol24.local.

;PTR Record IP address to HostName

101     IN      PTR    www.holhol24.local.
102     IN      PTR    mail.holhol24.local.

Validating DNS Syntax

Use the named-checkconf command to check the syntax of DNS configuration files for any errors.

sudo named-checkconf

Command will return to the shell if there are no errors.

Also, you can use named-checkzone to check the syntax errors in zone files.

Validating Forward Zone

sudo named-checkzone holhol24.local /etc/bind/holhol24.local.db

Output:

zone holhol24.local/IN: loaded serial 200101
OK

Validating Reverse Zone

sudo named-checkzone 0.168.192.in-addr.arpa /etc/bind/r.holhol24.local.db

Output:

zone 0.168.192.in-addr.arpa/IN: loaded serial 200101
OK

Finally, reload both the configuration file and zones. You may also use the same command whenever you change zone and zone files.

sudo rndc reload

Verify DNS Server

Use the dig command to verify the DNS server by looking up records.

dig www.holhol24.local @192.168.0.10

Output:

; > DiG 9.18.1-1ubuntu1-Ubuntu > www.holhol24.local @192.168.0.10
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADERwww.holhol24.local.      86400   IN      A       192.168.0.101

;; Query time: 0 msec
;; SERVER: 192.168.0.10#53(192.168.0.10) (UDP)
;; WHEN: Mon May 30 11:28:51 EDT 2022
;; MSG SIZE  rcvd: 90

Confirm the reverse lookup with the dig command.

dig -x 192.168.0.101 @192.168.0.10

Output:

; > DiG 9.18.1-1ubuntu1-Ubuntu > -x 192.168.0.101 @192.168.0.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER101.0.168.192.in-addr.arpa. 86400 IN    PTR     www.holhol24.local.

;; Query time: 0 msec
;; SERVER: 192.168.0.10#53(192.168.0.10) (UDP)
;; WHEN: Mon May 30 11:33:24 EDT 2022
;; MSG SIZE  rcvd: 114

This result confirms that both the forward and reverse zone are working fine.

Conclusion

That’s All. I hope you have learned how to set up DNS server on Ubuntu 22.04 / Ubuntu 20.04. In the next article, we will configure the slave DNS server on Ubuntu.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More