How to Configure DNS Server in Linux Step by Step?


How to Configure DNS Server in Linux Step by Step?

Configuring a DNS (Domain Name System) server in Linux is a fundamental skill for anyone managing a network or a server. DNS is the backbone of the internet, translating human-readable domain names into IP addresses. In this guide, we'll walk you through the step-by-step process of configuring a DNS server on a Linux system, demystifying the complexities and making it accessible even for beginners.

Step 1: Install Bind (Berkeley Internet Name Domain)
The first step is to install Bind, the most widely used DNS software on Linux. Open your terminal and use the following command to install Bind:

sudo apt-get install bind9 # For Debian/Ubuntu
sudo yum install bind # For CentOS/RHEL

Step 2: Configure Bind
Once Bind is installed, navigate to the configuration directory. Here, we'll be editing the main configuration file named "named.conf.options." Use your preferred text editor; for instance, with Nano:

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

Edit the "options" block to configure your DNS server settings, including listening on specific IP addresses and enabling recursion.

options {
directory "/var/cache/bind";
recursion yes;
allow-recursion { trusted; };
...
};

Save the file and exit the text editor.

Step 3: Define Forward and Reverse Zones
DNS works by mapping domain names to IP addresses (forward lookup) and vice versa (reverse lookup). Now, let's define forward and reverse zones.

  • Forward Zone:
sudo nano /etc/bind/named.conf.local

Add a zone configuration for your domain:

zone "example.com" {
type master;
file "/etc/bind/db.example.com";
};

Create the zone file:

sudo nano /etc/bind/db.example.com

Edit the file with the appropriate DNS records:

$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2023121601 ; Serial
7200 ; Refresh
120 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL

@ IN NS ns1.example.com.
@ IN A 192.168.1.1
www IN A 192.168.1.2
  • Reverse Zone:
sudo nano /etc/bind/named.conf.local

Add a reverse zone configuration:

zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168.1";
};

Create the reverse zone file:

sudo nano /etc/bind/db.192.168.1

Edit the file with the appropriate reverse DNS records:

$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2023121601 ; Serial
7200 ; Refresh
120 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL

@ IN NS ns1.example.com.
1 IN PTR ns1.example.com.
2 IN PTR www.example.com.

Step 4: Restart Bind Service
After making changes, restart the Bind service to apply the configurations:

sudo service bind9 restart # For systemd-based systems
sudo service named restart # For non-systemd systems

Step 5: Test DNS Resolution
Finally, ensure your DNS server is working by testing the resolution:

nslookup www.example.com

You should receive the IP address associated with the domain.

Congratulations! You've successfully configured a DNS server on your Linux system. This fundamental skill is crucial for managing networks and ensuring efficient communication between devices.

Related Searches and Questions asked:

  • How to Add CNAME Record to DNS in Linux
  • How to Find All DNS Servers in Linux?
  • How to Configure DNS Server in Linux CentOS 7
  • How to Configure DNS Server in Linux Ubuntu?
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.