Operations 11 min read

Master Linux DNS: From Basics to Advanced BIND9 Configuration

Explore the essential role of DNS in the internet, learn how Linux resolves domain names, configure resolvers via /etc/resolv.conf, NetworkManager, systemd-resolved, set up a BIND9 server with zone files, and discover advanced techniques like DNSSEC, DoH, split views, and troubleshooting tools.

Raymond Ops
Raymond Ops
Raymond Ops
Master Linux DNS: From Basics to Advanced BIND9 Configuration

In the world of the internet, DNS (Domain Name System) acts like a massive phone book, translating human‑readable domain names into machine‑understandable IP addresses. For Linux system administrators and network engineers, understanding DNS operation and its Linux applications is essential.

DNS Basics: What Is DNS?

DNS, short for Domain Name System, is a core internet service that converts domain names (e.g.,

www.example.com

) into IP addresses (e.g.,

192.0.2.1

) so users can access sites without memorizing numeric addresses.

How DNS Works

Query Process : When you type a URL, your computer first checks its local DNS cache.

Recursive Query : If not cached, it sends a recursive query to the DNS server provided by your ISP.

Iterative Query : The ISP’s server performs iterative queries, starting from the root servers and moving down until it finds the target IP.

Result Return : The IP address is returned to your computer, allowing the browser to connect.

Linux DNS Configuration

Linux DNS configuration involves several components:

1. /etc/resolv.conf

This is the primary resolver configuration file, containing DNS server IPs and search domains.

nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com

Note: On many modern distributions this file may be generated dynamically and should not be edited directly.

2. NetworkManager

Desktop Linux distributions often use NetworkManager to manage network connections, including DNS. You can configure DNS via the GUI or the

nmcli

command:

nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4"

3. systemd-resolved

systemd-resolved is a modern DNS resolver service providing local caching and DNSSEC validation. Its configuration file is typically

/etc/systemd/resolved.conf

.

4. /etc/hosts

This file allows manual hostname‑to‑IP mappings, overriding DNS queries:

127.0.0.1   localhost
192.168.1.10   myserver.local

DNS Server: BIND9

BIND (Berkeley Internet Name Domain) is the most widely used DNS server software. Setting up BIND9 on Linux involves the following steps:

1. Install BIND9

On Ubuntu/Debian:

sudo apt install bind9

On CentOS/RHEL:

sudo yum install bind

2. Configure BIND9

The main configuration file is

/etc/bind/named.conf

(Ubuntu/Debian) or

/etc/named.conf

(CentOS/RHEL). A basic example:

options {
    directory "/var/cache/bind";
    recursion yes;
    allow-recursion { trusted; };
    listen-on { 192.168.1.100; };
    allow-transfer { none; };
};

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

3. Create Zone File

The zone file defines DNS records for a domain, e.g.,

/etc/bind/db.example.com

:

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

4. Start and Enable BIND9

sudo systemctl start named
sudo systemctl enable named

Advanced DNS Techniques

1. DNSSEC (DNS Security Extensions)

DNSSEC uses digital signatures to verify the authenticity of DNS responses, preventing spoofing. Enable DNSSEC in BIND9:

options {
    dnssec-enable yes;
    dnssec-validation auto;
};

2. DNS over HTTPS (DoH)

DoH encrypts DNS queries via HTTPS for privacy. Tools such as

cloudflared

can be used as a DoH client on Linux.

3. Split DNS Views

BIND9 can provide different DNS views for internal and external clients:

view "internal" {
    match-clients { 192.168.0.0/16; };
    zone "example.com" {
        type master;
        file "/etc/bind/internal/db.example.com";
    };
};

view "external" {
    match-clients { any; };
    zone "example.com" {
        type master;
        file "/etc/bind/external/db.example.com";
    };
};

4. DNS Load Balancing

Multiple A records can implement simple round‑robin load balancing:

www     IN      A       192.168.1.10
www     IN      A       192.168.1.11
www     IN      A       192.168.1.12

5. Reverse DNS

Reverse DNS maps IP addresses back to hostnames. Configure a reverse zone in BIND9:

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

Corresponding zone file example:

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

@       IN      NS      ns1.example.com.
10      IN      PTR     www.example.com.

Troubleshooting Tools

dig : Detailed DNS query tool

dig www.example.com

nslookup : Interactive DNS query tool

nslookup www.example.com

host : Simple DNS lookup utility

host www.example.com

tcpdump : Capture and analyze DNS traffic

sudo tcpdump -i eth0 port 53

Security Considerations

Regular Updates : Keep DNS server software up‑to‑date to patch vulnerabilities.

Access Control : Restrict recursive query permissions to prevent abuse as a DDoS amplifier.

Monitoring : Enable logging and monitoring to detect abnormal queries.

DNSSEC : Deploy DNSSEC to verify response authenticity.

Separate Servers : When possible, separate authoritative and recursive DNS services.

Conclusion

DNS is a critical component of internet infrastructure. Mastering its operation and configuration on Linux—from client resolvers to full BIND9 server setups and advanced features like DNSSEC and DoH—empowers administrators to ensure reliable, secure name resolution and effective troubleshooting.

LinuxsecurityDNSBIND9Network Administration
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.