Table of Contents
- Introduction to DNS
- History of DNS
- How DNS Works (Step-by-Step)
- Real-Life Examples
- How to Use DNS in Linux
- DNS Client Configuration (Red Hat & Debian-Based)
- Setting Up a DNS Server (BIND)
- Troubleshooting and Useful Commands
- Conclusion
1. Introduction to DNS
DNS, or Domain Name System, is often described as the “phonebook of the internet.” It translates human-friendly domain names (like www.google.com) into IP addresses (like 142.250.64.100) that computers use to identify each other.
Without DNS, you’d have to remember IP addresses instead of domain names — a logistical nightmare.
2. Brief History of DNS
- In the early days of ARPANET, name-to-IP mapping was done via a flat file called hosts.txt.
- As networks grew, this method became unsustainable.
- In 1983, Paul Mockapetris introduced the Domain Name System (DNS) in RFC 882 and 883.
- It became a hierarchical, distributed system, forming the backbone of the modern internet.
3. How DNS Works (Step-by-Step)
Let’s say you open your browser and type www.example.com.
Lookup Flow:
- Browser checks local DNS cache.
- OS checks /etc/hosts (if on Linux).
- Sends query to configured DNS server (e.g., 8.8.8.8).
- DNS server checks its cache. If not found:
- Queries root name servers.
- Then TLD servers (e.g., .com).
- Then authoritative name server for example.com.
- IP address is returned to the client.
- Connection proceeds using the resolved IP.
4. Real-Life Examples of DNS
Scenario | DNS Role |
---|---|
Typing a website URL | Resolves domain to IP |
Sending an email | Finds mail server via MX records |
Using cloud services | Resolves subdomains, APIs, CNAMEs |
Internal networks | Private DNS zones for devices and VMs |
5. How to Use DNS in Linux
Check Current DNS Settings:
cat /etc/resolv.conf
Sample output:
nameserver 8.8.8.8
nameserver 1.1.1.1
Query DNS Using dig
, nslookup
, and host
➤ dig
(most powerful)
dig google.com
Output (simplified):
;; ANSWER SECTION:
google.com. 300 IN A 142.250.64.100
➤ nslookup
nslookup google.com
➤ host
host google.com
6. DNS Client Configuration in Linux
Red Hat / CentOS / Rocky (NetworkManager-controlled)
Static DNS:
nmcli con mod "System eth0" ipv4.dns "8.8.8.8 1.1.1.1"
nmcli con up "System eth0"
Confirm:
nmcli dev show | grep DNS
Legacy:
Edit /etc/resolv.conf (though NetworkManager may overwrite this)
Debian / Ubuntu (Netplan or systemd-resolved)
With Netplan:
# /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
sudo netplan apply
Check DNS:
systemd-resolve --status
7. Setting Up a DNS Server (BIND)
We’ll use BIND9, the most popular open-source DNS server.
Install on Ubuntu/Debian:
sudo apt install bind9 bind9utils bind9-doc
Install on RHEL/CentOS:
sudo dnf install bind bind-utils
Configure Zone:
Edit /etc/bind/named.conf.local (Debian) or /etc/named.conf (RHEL)
zone "example.com" {
type master;
file "/etc/bind/zones/db.example.com";
};
Create /etc/bind/zones/db.example.com:
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2024061101 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Minimum TTL
@ IN NS ns1.example.com.
@ IN A 192.168.1.100
www IN A 192.168.1.100
Start and Enable BIND:
sudo systemctl enable named
sudo systemctl start named
8. Troubleshooting and DNS Tools
Command | Use |
---|---|
dig | Full DNS query |
host, nslookup | Quick lookups |
systemd-resolve –status | Show system DNS in Ubuntu |
resolvectl | Modern DNS client in systemd |
tcpdump port 53 | Capture DNS traffic |
journalctl -u named | Logs for BIND |
Example: Test Zone File
named-checkzone example.com /etc/bind/zones/db.example.com
9. Conclusion
DNS is more than just a background service — it’s the nervous system of modern networking. Whether you’re configuring a simple client, debugging an issue, or running your own DNS server, understanding DNS gives you powerful control over connectivity, performance, and even security.
From using tools like dig to configuring resolvers and setting up BIND, this guide has walked you through the full stack of DNS in a Linux environment — both Red Hat and Debian-based systems.