Use DNS (Domain Name System) on a Linux server to map domain names to IP addresses, enabling users and applications to locate resources on the internet or private networks easily by name instead of numeric IPs. Running a DNS server on Linux allows you to host your domain name resolution services, manage local network naming, and improve network reliability and control.

This guide explains how to install, configure, manage, and use DNS server on Linux, primarily using BIND (Berkeley Internet Name Domain), the most common DNS server in Linux environments.
Prerequisites
- A Linux server running Ubuntu, Debian, CentOS, or similar distributions
- Root or sudo access to install and modify system services
- Basic Linux command-line knowledge
- A registered domain name is required if you plan to host public DNS zones
Use DNS on a Linux Server
DNS (Domain Name System) translates domain names into IP addresses, allowing users to access your Linux server via easy-to-remember URLs. Configuring DNS ensures proper routing, email delivery, and web accessibility. Whether you’re running a web server or internal services, DNS is a critical layer of your Linux server setup.
Install BIND DNS Server Packages
BIND (Berkeley Internet Name Domain) is the most widely used DNS server on Linux. Installing BIND is the first step in setting up a fully functional DNS server. It provides authoritative name resolution, caching, and zone management capabilities needed for hosting your domain.
- On Ubuntu/Debian:
sudo apt update
sudo apt install bind9 bind9utils -y
- On CentOS/RHEL:
sudo yum install bind bind-utils -y
BIND installation provides the DNS server daemon (named
) and necessary utilities.
Configure BIND DNS Server Options
The main BIND configuration files are in /etc/bind
(Ubuntu/Debian) or /etc/named
(CentOS/RHEL). The global server options are typically set in /etc/bind/named.conf.options
(Ubuntu) or /etc/named.conf
(CentOS).
Edit the options file to configure DNS parameters:
sudo nano /etc/bind/named.conf.options
Add or edit the following example options for a DNS server that allows recursive queries for your local network and forwards other queries to external DNS servers such as Google DNS:
acl local-network {
192.168.1.0/24; # Replace with your network subnet
};
options {
directory "/var/cache/bind";
dnssec-validation auto;
recursion yes;
allow-query { localhost; local-network; };
forwarders {
8.8.8.8;
8.8.4.4;
};
listen-on { 127.0.0.1; 192.168.1.10; }; # Your server's IP address
listen-on-v6 { none; };
};
- acl local-network: Defines trusted IP ranges allowed to query your DNS server.
- recursion yes: Allows your DNS server to perform recursive queries.
- forwarders: External DNS servers to forward unresolved queries.
- listen-on: IP addresses on which the DNS server listens for queries.
Save and exit the file.
Configure DNS Zones
You need forward zone files (domain name to IP mappings) and reverse zone files (IP to domain mappings).
- Edit
/etc/bind/named.conf.local
to define your zones. For example:
zone "example.com" {
type master;
file "/etc/bind/zones/db.example.com";
};
zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/zones/db.192.168.1";
};
- Create the directory for zone files:
sudo mkdir /etc/bind/zones
Create Forward and Reverse Zone Files
- Forward Zone (e.g.,
/etc/bind/zones/db.example.com
):
$TTL 604800
@ IN SOA ns1.example.com. admin.example.com. (
2025073101 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
; Name servers
IN NS ns1.example.com.
; A records for name servers
ns1 IN A 192.168.1.10
; Other hosts
www IN A 192.168.1.20
- Reverse Zone (e.g.,
/etc/bind/zones/db.192.168.1
):
$TTL 604800
@ IN SOA ns1.example.com. admin.example.com. (
2025073101 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
; Name servers
IN NS ns1.example.com.
; PTR records
10 IN PTR ns1.example.com.
20 IN PTR www.example.com.
- Replace IPs and domain names with your actual details.
- Increment the serial number every time you update the zone files.
Check Configuration and Restart BIND
- Test your BIND configuration for errors:
sudo named-checkconf
sudo named-checkzone example.com /etc/bind/zones/db.example.com
sudo named-checkzone 1.168.192.in-addr.arpa /etc/bind/zones/db.192.168.1
- Restart the BIND service to apply changes:
sudo systemctl restart bind9 # Ubuntu/Debian
sudo systemctl restart named # CentOS/RHEL
- Check the service status:
sudo systemctl status bind9
Test Your DNS Server
- Query your DNS server using
dig
ornslookup
:
dig @192.168.1.10 example.com
dig @192.168.1.10 www.example.com
dig -x 192.168.1.20 @192.168.1.10
- You should see proper responses for forward and reverse lookups.
Conclusion
To use DNS on a Linux server, install and configure the BIND DNS server with configured forwarders, recursion rules, and custom forward and reverse zone files. Start and enable the BIND service, then test DNS resolution locally and from other machines in your network. Running your own DNS server provides control over your network’s name resolution and can improve performance and security. For complete details and advanced configurations, consult the official BIND documentation.