Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Configure DNS on a Linux System

Configuring DNS (Domain Name System) on a Linux system is an essential task for network administrators and systems engineers. DNS is responsible for translating human-readable domain names into IP addresses, allowing users to access websites and services using easy-to-remember names. In this article, we will explore how to set up and configure DNS on a Linux system using the BIND (Berkeley Internet Name Domain) software, which is one of the most commonly used DNS servers on Linux.

Step-by-Step Guide to Configure DNS with BIND

Step 1: Install BIND

To begin, you need to install the BIND package on your Linux system. Use the package manager specific to your Linux distribution. For instance, on Debian-based systems like Ubuntu, you can use apt, and on Red Hat-based systems like CentOS, you can use yum or dnf.

For Debian-based systems:

sudo apt update
sudo apt install bind9 bind9utils bind9-doc

For Red Hat-based systems:

sudo yum install bind bind-utils

Step 2: Configure the BIND DNS Server

Once BIND is installed, you need to configure it. The main configuration file for BIND is /etc/bind/named.conf on Debian-based systems and /etc/named.conf on Red Hat-based systems.

Edit the configuration file using a text editor:

sudo nano /etc/bind/named.conf    # For Debian-based systems
sudo nano /etc/named.conf         # For Red Hat-based systems

Add or modify the following sections to set up your DNS zones:

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

zone "0.168.192.in-addr.arpa" {
    type master;
    file "/etc/bind/zones/db.192.168.0";
};

Step 3: Create Zone Files

Create the directory for your zone files if it doesn't exist:

sudo mkdir -p /etc/bind/zones

Create the forward zone file /etc/bind/zones/db.example.com:

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

Add the following content:

$TTL    604800
@       IN      SOA     ns1.example.com. admin.example.com. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.example.com.
@       IN      A       192.168.0.1
ns1     IN      A       192.168.0.1
www     IN      A       192.168.0.2

Create the reverse zone file /etc/bind/zones/db.192.168.0:

sudo nano /etc/bind/zones/db.192.168.0

Add the following content:

$TTL    604800
@       IN      SOA     ns1.example.com. admin.example.com. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; 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: Check Configuration and Restart BIND

Check the configuration for any syntax errors:

sudo named-checkconf
sudo named-checkzone example.com /etc/bind/zones/db.example.com
sudo named-checkzone 0.168.192.in-addr.arpa /etc/bind/zones/db.192.168.0

If there are no errors, restart the BIND service:

For Debian-based systems:

sudo systemctl restart bind9

For Red Hat-based systems:

sudo systemctl restart named

Step 5: Test Your DNS Server

To ensure that your DNS server is working correctly, use the dig command to query your DNS server:

dig @localhost example.com

You should see a response with the IP address you configured for example.com.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.