How to Configure DNS Server in Linux CentOS 7


How to Configure DNS Server in Linux CentOS 7

Setting up a Domain Name System (DNS) server on a Linux CentOS 7 system is a crucial step in managing and resolving domain names to IP addresses. This article will guide you through the process of configuring a DNS server on CentOS 7, providing step-by-step instructions, commands, and examples to ensure a smooth setup.

Prerequisites:

Before diving into the configuration process, make sure you have:

  1. A CentOS 7 system with root or sudo privileges.
  2. A static IP address configured on your CentOS server.

Step 1: Install BIND DNS Server:

The Berkeley Internet Name Domain (BIND) is the most widely used DNS software on the internet. Install it using the following command:

sudo yum install bind bind-utils

Step 2: Configure BIND:

Navigate to the BIND configuration directory and create a new configuration file named named.conf:

cd /etc/named
sudo cp named.conf named.conf.original
sudo nano named.conf

Paste the following basic configuration into the file:

options {
listen-on port 53 { any; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;
};

Step 3: Create Forward and Reverse Zone Files:

Create files for forward and reverse DNS zones. In this example, we'll use example.com for demonstration purposes. Adjust the domain and IP addresses accordingly.

Forward Zone File:

sudo nano /var/named/forward.example.com

Paste the following content:

$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2023121601 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
@ IN NS ns1.example.com.
@ IN A 192.168.1.10
ns1 IN A 192.168.1.10
www IN A 192.168.1.20

Reverse Zone File:

sudo nano /var/named/reverse.example.com

Paste the following content:

$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2023121601 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
@ IN NS ns1.example.com.
10 IN PTR ns1.example.com.
20 IN PTR www.example.com.

Step 4: Update SELinux and Firewall Settings:

Adjust SELinux and firewall settings to allow DNS traffic:

sudo setsebool -P named_write_master_zones 1
sudo firewall-cmd --permanent --add-port=53/tcp
sudo firewall-cmd --permanent --add-port=53/udp
sudo firewall-cmd --reload

Step 5: Start and Enable BIND:

Start the BIND service and enable it to start on boot:

sudo systemctl start named
sudo systemctl enable named

Step 6: Test DNS Configuration:

Verify the DNS configuration by querying the server for the domain and IP address:

nslookup www.example.com

Congratulations! You have successfully configured a DNS server on CentOS 7. This setup is fundamental for efficiently managing domain name resolutions on your network. Feel free to explore advanced configurations and security measures to enhance your DNS server's performance.

Related Searches and Questions asked:

  • How to Add TXT Record to DNS Configuration in Linux?
  • How to Configure DNS Server?
  • How Do I List My DNS Servers?
  • How to Add DNS Records in Linux?
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.