Linux bind Beginner AlmaLinux Red Hat Enterprise Linux Rocky Linux

Nameserver basics

The basic configuration for nameserver.

Created 13.10.2026 by ffasel · updated 14.10.2026

Use at your own risk. Please never just copy and run commands from the internet – including the ones on this page. Disclaimer

Introduction

In this tutorial, we will install and configure a basic BIND (Berkeley Internet Name Domain) DNS server on AlmaLinux 10 or Red Hat Enterprise Linux (RHEL) 10.

BIND is an open-source DNS server implementation that allows computers to resolve domain names into IP addresses and vice versa.

We will configure BIND as an authoritative DNS server for the internal domain test.lab and as a recursive caching DNS resolver for clients on the local network.

Steps

  1. Install BIND and the required DNS utilities.
  2. Understand the BIND configuration files.
  3. Configure the BIND DNS server.
  4. Create a forward DNS zone.
  5. Create a reverse DNS zone.
  6. Set file permissions and SELinux contexts.
  7. Validate the BIND configuration and zone files.
  8. Configure the firewall to allow DNS traffic.
  9. Start and enable the BIND service.
  10. Test forward, reverse, and external DNS resolution.
  11. Configure a DNS client to use the BIND server.
  12. Troubleshoot common DNS issues.

Example network environment

SettingExample value
DNS domaintest.lab
DNS server hostnamens1.test.lab
DNS server IP192.168.10.10
Network192.168.10.0/24
Forward zonetest.lab
Reverse zone10.168.192.in-addr.arpa
Web server192.168.10.20
Client192.168.10.100

All IP addresses in this tutorial are examples and should be adjusted to match your network.

How the DNS server works

flowchart TD
    A["DNS Client<br/>192.168.10.100"]
    B["BIND DNS Server<br/>ns1.test.lab<br/>192.168.10.10"]
    C["Internal DNS Zone<br/>test.lab<br/>Forward & Reverse DNS"]
    D["External DNS Resolvers<br/>1.1.1.1 / 9.9.9.9"]

    A -->|"DNS Query (Port 53)"| B
    B -->|"Internal DNS Query"| C
    B -->|"External DNS Query"| D
    C -->|"DNS Response"| B
    D -->|"DNS Response"| B
    B -->|"DNS Response"| A

    classDef client fill:#e0f2fe,stroke:#0284c7,color:#075985
    classDef server fill:#ccfbf1,stroke:#0d9488,color:#115e59
    classDef internal fill:#fef3c7,stroke:#d97706,color:#92400e
    classDef external fill:#f3e8ff,stroke:#9333ea,color:#6b21a8

    class A client
    class B server
    class C internal
    class D external
Mermaid source
flowchart TD
    A["DNS Client<br/>192.168.10.100"]
    B["BIND DNS Server<br/>ns1.test.lab<br/>192.168.10.10"]
    C["Internal DNS Zone<br/>test.lab<br/>Forward & Reverse DNS"]
    D["External DNS Resolvers<br/>1.1.1.1 / 9.9.9.9"]

    A -->|"DNS Query (Port 53)"| B
    B -->|"Internal DNS Query"| C
    B -->|"External DNS Query"| D
    C -->|"DNS Response"| B
    D -->|"DNS Response"| B
    B -->|"DNS Response"| A

    classDef client fill:#e0f2fe,stroke:#0284c7,color:#075985
    classDef server fill:#ccfbf1,stroke:#0d9488,color:#115e59
    classDef internal fill:#fef3c7,stroke:#d97706,color:#92400e
    classDef external fill:#f3e8ff,stroke:#9333ea,color:#6b21a8

    class A client
    class B server
    class C internal
    class D external

The DNS server will perform two main functions:

Authoritative DNS: The server stores DNS records for test.lab and responds directly to queries for this domain.

Recursive DNS: When a client requests an external domain, such as www.redhat.com, BIND forwards the query to an external DNS resolver or performs recursion itself.

Only trusted clients from the internal network will be allowed to use the DNS server.

Preparing the Server

Before installing BIND, verify that the system is configured correctly.

Check the operating system

Bash / Shell
cat /etc/os-release

This command displays information about the installed Linux distribution and version.

Check the IP address

Bash / Shell
ip -4 addr show

Make sure the DNS server has the correct IP address.

The server should use a static IP address because clients must always be able to reach the DNS service at the same address.

Configure the hostname

Set the hostname:

Bash / Shell
sudo hostnamectl set-hostname ns1.test.lab

Verify the hostname:

Bash / Shell
hostnamectl

Update the system

Bash / Shell
sudo dnf update -y

This installs available package updates, including security updates.

If the update installs a new kernel or other components requiring a reboot, restart the server before continuing.

Installing BIND

Install BIND and the DNS utilities:

Bash / Shell
sudo dnf install -y bind bind-utils

Package explanation

PackageDescription
bindContains the BIND DNS server and the named daemon
bind-utilsContains DNS tools such as dig, host, and nslookup

The DNS server service is called named, which stands for name daemon.

Verify that BIND is installed:

Bash / Shell
named -v

This displays the installed BIND version.

You can also check the installed packages:

Bash / Shell
rpm -q bind bind-utils

Understanding BIND Configuration Files

BIND uses several files and directories for its configuration.

File / DirectoryPurpose
/etc/named.confMain BIND configuration file
/etc/named.rfc1912.zonesAdditional predefined zone declarations
/var/named/Directory containing DNS zone files
/var/named/named.caRoot DNS server hints
/var/named/data/Directory for certain BIND runtime data

The most important file is /etc/named.conf

This file controls how the DNS server operates, which clients can access it, and which DNS zones it manages.

The zone files contain the actual DNS records.

Back up the original configuration

Before making changes, create a backup:

Bash / Shell
sudo cp -a /etc/named.conf /etc/named.conf.bak

The -a option preserves file attributes such as permissions and timestamps.

This backup allows you to restore the original configuration if necessary.

Configuring the BIND DNS Server

Open the main BIND configuration file:

Bash / Shell
sudo vi /etc/named.conf

For this basic standalone lab, replace the contents with the following configuration.

/etc/named.conf

named.conf (1.5 KB) Download

//
// BIND DNS Server Configuration
// AlmaLinux 10 / RHEL 10
// Domain: test.lab
// DNS Server: 192.168.10.10
//

// Trusted networks
acl "trusted" {
    127.0.0.1;
    192.168.10.0/24;
};

// Global DNS server settings
options {
    directory "/var/named";

    // IPv4 listening interfaces
    listen-on port 53 {
        127.0.0.1;
        192.168.10.10;
    };

    // IPv6 listening interface
    listen-on-v6 port 53 { ::1; };

    // DNS query permissions
    allow-query { trusted; };

    // Recursive DNS resolution
    recursion yes;
    allow-recursion { trusted; };
    allow-query-cache { trusted; };

    // DNSSEC validation
    dnssec-validation auto;

    // External DNS forwarders
    forwarders {
        1.1.1.1;
        9.9.9.9;
    };

    forward first;

    // Disable zone transfers
    allow-transfer { none; };

    // BIND runtime directories
    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";

    // Hide BIND version information
    version "not disclosed";
};

// Logging configuration
logging {
    channel default_debug {
        file "data/named.run";
        severity dynamic;
    };
};

// Root DNS hints
zone "." IN {
    type hint;
    file "named.ca";
};

// Forward DNS zone
zone "test.lab" IN {
    type primary;
    file "test.lab.zone";
    allow-update { none; };
};

// Reverse DNS zone
zone "10.168.192.in-addr.arpa" IN {
    type primary;
    file "10.168.192.rev";
    allow-update { none; };
};

This configuration defines trusted clients, DNS listening interfaces, recursion settings, forwarders, and two authoritative DNS zones.

Configuration elements

DirectivePurpose
aclDefines trusted clients or networks
optionsContains global BIND settings
directorySpecifies the working directory
listen-onDefines IPv4 listening addresses
listen-on-v6Defines IPv6 listening addresses
allow-queryControls DNS query access
recursionEnables or disables recursive DNS resolution
allow-recursionRestricts recursive DNS queries
allow-query-cacheRestricts access to cached DNS responses
dnssec-validationControls DNSSEC validation
forwardersSpecifies external DNS resolvers
forwardControls DNS forwarding behavior
allow-transferRestricts DNS zone transfers
dump-fileSpecifies the DNS cache dump file
statistics-fileSpecifies the statistics output file
memstatistics-fileSpecifies the memory statistics file
versionControls the exposed BIND version string
loggingConfigures DNS server logging
zoneDeclares a DNS zone
type hintConfigures root DNS hints
type primaryDefines a primary authoritative DNS zone
fileSpecifies the associated zone file
allow-updateControls dynamic DNS updates

Creating the Forward DNS Zone

A forward DNS zone resolves hostnames to IP addresses.

Create the zone file

Bash / Shell
sudo vi /var/named/test.lab.zone

Add the following content:

/var/named/test.lab.zone

test.lab.zone (424 bytes) Download
$TTL 86400
@   IN  SOA ns1.test.lab. admin.test.lab. (
        2026101401 ; Serial
        3600       ; Refresh
        1800       ; Retry
        604800     ; Expire
        86400      ; Negative cache TTL
)

; Name server
@       IN  NS      ns1.test.lab.

; A records
ns1     IN  A       192.168.10.10
www     IN  A       192.168.10.20
client1 IN  A       192.168.10.100

; CNAME record
web     IN  CNAME   www.test.lab.

Understanding the SOA record

Every authoritative DNS zone requires a Start of Authority (SOA) record.

The SOA record defines important administrative information about the zone.

FieldValueDescription
Primary serverns1.test.lab.Primary authoritative DNS server
Administratoradmin.test.lab.Represents admin@test.lab
Serial2026101401Zone version number
Refresh3600Secondary DNS refresh interval
Retry1800Retry interval after a failed refresh
Expire604800Maximum time secondary servers may use stale zone data
Negative TTL86400Negative response caching TTL

All timing values are specified in seconds.

The serial number must be increased whenever the zone is modified.

Creating the Reverse DNS Zone

A reverse DNS zone resolves IP addresses to hostnames using PTR records.

For the network 192.168.10.0/24, the reverse DNS zone is 10.168.192.in-addr.arpa.

Create the reverse zone file


Bash / Shell
sudo vi /var/named/10.168.192.rev

Add the following content:

/var/named/10.168.192.rev

10.168.192.in-addr.arpa (379 bytes) Download
$TTL 86400
@   IN  SOA ns1.test.lab. admin.test.lab. (
        2026101401 ; Serial
        3600       ; Refresh
        1800       ; Retry
        604800     ; Expire
        86400      ; Negative cache TTL
)

; Name server
@       IN  NS      ns1.test.lab.

; PTR records
10      IN  PTR     ns1.test.lab.
20      IN  PTR     www.test.lab.
100     IN  PTR     client1.test.lab.

A PTR record maps an IP address to a hostname.

Configuring File Permissions and SELinux

BIND needs permission to read the DNS zone files.

Bash / Shell
sudo chown root:named \
    /var/named/test.lab.zone \
    /var/named/10.168.192.rev

This sets:

  • root as the file owner.
  • named as the file group.

Set file permissions


Bash / Shell
sudo chmod 640 \
    /var/named/test.lab.zone \
    /var/named/10.168.192.rev

Configure SELinux contexts

SELinux (Security-Enhanced Linux) provides an additional security layer by controlling access to system resources.

Restore the correct SELinux contexts:

Bash / Shell
sudo restorecon -v \
    /var/named/test.lab.zone \
    /var/named/10.168.192.rev

Because the zone files are stored in /var/named/, the standard SELinux policy should allow BIND to read them.

Validating the BIND Configuration

Before starting the DNS server, check the configuration for syntax errors.

BIND provides tools for validating the main configuration and zone files.

Check the main configuration


Bash / Shell
sudo named-checkconf

This command checks the syntax of /etc/named.conf.

Check the forward zone

Bash / Shell
sudo named-checkzone \
    test.lab \
    /var/named/test.lab.zone

Check the reverse zone

Bash / Shell
sudo named-checkzone \
    10.168.192.in-addr.arpa \
    /var/named/10.168.192.rev

Configuring the Firewall

DNS uses port 53 over both UDP and TCP.

ProtocolPortPurpose
UDP53Standard DNS queries
TCP53Large DNS responses and other DNS operations

Allow DNS traffic

Add the DNS service to the firewall configuration:

Bash / Shell
sudo firewall-cmd --permanent --add-service=dns
sudo firewall-cmd --reload

Starting and Enabling BIND

Now that the configuration and zone files are ready, enable and start the BIND service.

Bash / Shell
sudo systemctl enable --now named

Checks

Check if the DNS server is working. Check the forward and reverse zone with dig.

Bash / Shell
dig +short @192.168.10.10 www.test.lab
dig +short @192.168.10.10 -x 192.168.10.20

Sources

  1. Official documentation from Red Hat https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_networking_infrastructure_services/assembly_setting-up-and-configuring-a-bind-dns-server_networking-infrastructure-

#bind#dns#nameserver

Finished? Let others know whether this tutorial worked for you.
It worked!