Network and System AdministrationUnit 521 min read
DNS, Name Servers & Configuration: Domains, Zones, Records & Troubleshooting
Unit 5 of Network and System Administration covers Domain Name System (DNS) architecture, name server roles (primary/secondary), record types (A, MX, CNAME), zone file configuration, and troubleshooting techniques—essential for mapping human-readable domain names to IP addresses in modern networks.
TAKEAWAYS:
- DNS translates domain names (e.g.,
esewa.com.np) to IP addresses (e.g.,103.22.16.10) using a hierarchical, distributed database of name servers and resource records. - A zone file defines a domain’s DNS data, including A records (IPv4), MX records (mail servers), and CNAME records (aliases), stored on a primary name server and replicated to secondary servers for redundancy.
- DNS resolution follows a recursive query process: resolver → root → TLD → authoritative servers, with caching at each step to improve speed.
- Troubleshooting involves checking
nslookup,dig, orhostcommands, verifying zone files for syntax errors, and testing connectivity between name servers. - Security risks include DNS spoofing (cache poisoning), DDoS attacks on DNS servers, and misconfigured records causing downtime.
- Real-world impact: Every app (e.g., WhatsApp, Daraz) and service (e.g., Ncell, NTC) relies on DNS to route users to the correct servers—misconfigurations can break services entirely.
1. Why DNS? The Problem It Solves
Imagine typing daraz.com.np instead of 103.22.16.10 every time you want to shop online. DNS makes this possible by acting as the "phonebook of the internet", translating human-readable domain names into machine-readable IP addresses.
sequenceDiagram
participant User
participant Browser
participant LocalDNS
participant RootDNS
participant ComTLD
participant EsewaDNS
participant WebServer
User->>Browser: Types "esewa.com.np"
Browser->>LocalDNS: DNS Query (esewa.com.np)
LocalDNS->>RootDNS: Query for .np TLD
RootDNS-->>LocalDNS: Redirect to .np TLD
LocalDNS->>ComTLD: Query for esewa.com.np
ComTLD-->>LocalDNS: Redirect to Authoritative (ns1.esewa.com)
LocalDNS->>EsewaDNS: Query for esewa.com.np
EsewaDNS-->>LocalDNS: A Record (103.22.16.10)
LocalDNS-->>Browser: IP Address (103.22.16.10)
Browser->>WebServer: HTTP Request
WebServer-->>Browser: HTML ResponseDNS resolution flow for esewa.com.np (IPv4) with caching at each step
How DNS Works: A Step-by-Step Trace
When you type khalti.com in your browser, this happens:
- Your local resolver (e.g., ISP’s DNS server) checks its cache for
khalti.com. - If not found, it sends a recursive query to the root name server (
.). - The root server replies with the TLD (Top-Level Domain) server for
.com. - The TLD server points to Khalti’s authoritative name servers (e.g.,
ns1.khalti.com). - The authoritative server returns the A record (IPv4 address) or AAAA record (IPv6) for
khalti.com. - Your browser connects to the IP address and loads the website.
2. DNS Architecture: The Hierarchy of Name Servers
DNS uses a distributed, hierarchical system to avoid a single point of failure. The structure is:
| Level | Example | Role |
|---|---|---|
| Root Servers | . (13 clusters) |
Direct queries to TLD servers (e.g., .com, .np). |
| TLD Servers | .com, .org, .np |
Point to authoritative servers for domains under their TLD. |
| Authoritative Servers | ns1.esewa.com |
Hold the zone files for a domain (e.g., esewa.com.np). |
| Recursive Resolvers | ISP DNS (e.g., NTC, Ncell) | Cache results to speed up future queries for their users. |
3. DNS Records: The Building Blocks of a Zone File
A zone file is a text file (e.g., esewa.com.np.zone) that defines how a domain should resolve. Key record types:
| Record Type | Purpose | Example | Format in Zone File |
|---|---|---|---|
| A | Maps a domain to an IPv4 address. | esewa.com.np → 103.22.16.10 |
esewa.com.np. IN A 103.22.16.10 |
| AAAA | Maps a domain to an IPv6 address. | esewa.com.np → 2001:db8::1 |
esewa.com.np. IN AAAA 2001:db8::1 |
| MX | Specifies mail servers for email delivery. | esewa.com.np → mail.esewa.com (priority 10) |
esewa.com.np. IN MX 10 mail.esewa.com. |
| CNAME | Creates an alias for another domain (must point to another domain, not IP). | www.esewa.com → esewa.com |
www.esewa.com. IN CNAME esewa.com. |
| NS | Defines authoritative name servers for the domain. | esewa.com.np → ns1.esewa.com |
esewa.com.np. IN NS ns1.esewa.com. |
| TXT | Stores text records (e.g., SPF, DKIM for email security). | esewa.com.np → "v=spf1 include:_spf.esewa.com ~all" |
esewa.com.np. IN TXT "v=spf1..." |
| SOA | Start of Authority: Contains admin info (primary NS, refresh time, etc.). | esewa.com.np → ns1.esewa.com (admin@esewa.com) |
esewa.com.np. IN SOA ns1.esewa.com admin.esewa.com (...) |
Worked Example: Configuring DNS for a Bank (e.g., Nabil Bank) Suppose Nabil Bank wants:
nabilbank.comto point to192.0.2.1.mail.nabilbank.comto handle emails (MX record).www.nabilbank.comto alias tonabilbank.com.
Their zone file (nabilbank.com.zone) would look like:
$TTL 86400
@ IN SOA ns1.nabilbank.com. admin.nabilbank.com. (
2023101501 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
@ IN NS ns1.nabilbank.com.
@ IN A 192.0.2.1
www IN CNAME @
mail IN A 192.0.2.2
@ IN MX 10 mail.nabilbank.com.
4. Primary vs. Secondary Name Servers
| Feature | Primary Name Server | Secondary Name Server |
|---|---|---|
| Role | Holds the master copy of the zone file. | Holds a replica (copied via zone transfer). |
| Updates | Can modify the zone file directly. | Gets updates from the primary (read-only). |
| Zone Transfer | Initiates transfers to secondaries (via AXFR). |
Requests updates from the primary. |
| Failure Impact | If down, DNS for the domain fails. | If down, primary continues serving. |
| Example | ns1.esewa.com (writes zone files). |
ns2.esewa.com (reads from ns1). |
Why Use Secondaries?
- Redundancy: If the primary fails, secondaries take over.
- Load Balancing: Distributes query load.
- Geographic Distribution: Secondaries in different regions reduce latency.
5. DNS Resolution Process: A Deep Dive
When you type pathao.com, your computer performs a recursive resolution:
stateDiagram-v2
[*] --> QueryStart
QueryStart --> ClientQuery: User types `daraz.com.np`
ClientQuery --> LocalCache: Check local resolver cache
LocalCache --> CacheHit: Found?
CacheHit --> ReturnIP: Yes → Return IP
CacheHit --> RootQuery: No → Query Root (.)
RootQuery --> TLDQuery: Root redirects to `.np` TLD
TLDQuery --> AuthQuery: TLD redirects to `ns1.daraz.com.np`
AuthQuery --> ReturnData: Authoritative server returns A/AAAA record
ReturnData --> Client: Browser connects to IP
Client --> [*]- Local Cache Check: Your OS/browser checks if it has cached
pathao.com. - Resolver Query: If not cached, your recursive resolver (e.g.,
8.8.8.8or1.1.1.1) queries:- Root Server → Returns TLD server for
.com. - TLD Server → Returns Pathao’s authoritative servers (
ns1.pathao.com). - Authoritative Server → Returns
AorAAAArecord.
- Root Server → Returns TLD server for
- Response: The resolver caches the result (TTL-based) and returns it to you.
Caching Example:
- If
dig @8.8.8.8 pathao.comreturns192.0.2.3with a TTL of 3600 seconds (1 hour), your resolver will use this IP for the next hour, even if Pathao’s IP changes.
6. Common DNS Misconfigurations and Fixes
| Issue | Cause | Fix |
|---|---|---|
| Website Unreachable | Missing A or AAAA record. |
Add example.com. IN A 192.0.2.1. |
| Emails Bouncing | Incorrect MX record. |
Set example.com. IN MX 10 mail.example.com.. |
| DNS Propagation Delays | TTL too high (e.g., 86400 seconds). | Lower TTL temporarily (e.g., 3600) during changes. |
| DNS Spoofing (Cache Poisoning) | Malicious responses injected into cache. | Use DNSSEC to sign records. |
| Zone Transfer Failures | Firewall blocking port 53 (TCP). |
Open port 53 for TCP between primary and secondary servers. |
| CNAME Loop | A CNAME B and B CNAME A. |
Remove circular references; use A records instead. |
Worked Example: Fixing a Broken MX Record for NEPSE
Suppose NEPSE’s nepse.com.np has an MX record pointing to a non-existent server (mail.nepse.com), causing emails to fail. The fix:
- Check current records:
Output:dig MX nepse.com.np;; ANSWER SECTION: nepse.com.np. 3600 IN MX 10 mail.nepse.com. - Verify
mail.nepse.comexists:
Output (error):dig A mail.nepse.commail.nepse.com: No answer - Solution: Update the zone file to point to the correct mail server (e.g.,
smtp.nepse.com):nepse.com.np. IN MX 10 smtp.nepse.com. smtp.nepse.com. IN A 192.0.2.4 - Force a zone transfer to secondaries:
rndc refresh nepse.com.np
7. DNS Tools: Commands Every Admin Should Know
| Command | Purpose | Example |
|---|---|---|
nslookup |
Query DNS records interactively. | nslookup esewa.com.np |
dig |
Advanced DNS lookup (shows full response). | dig MX khalti.com |
host |
Simple DNS lookup (like nslookup). |
host www.daraz.com.np |
whois |
Look up domain registration details. | whois nepse.com.np |
rndc |
Manage BIND DNS server (reload, refresh, restart). | rndc reload |
dig +trace |
Trace the full resolution path. | dig +trace google.com |
Worked Example: Diagnosing a Slow Website (e.g., NTC’s ntc.net.np)
- Check if DNS is resolving:
Output:dig A ntc.net.np;; ANSWER SECTION: ntc.net.np. 86400 IN A 192.0.2.5 - Test latency to the IP:
Output (high latency):ping 192.0.2.5PING 192.0.2.5 (192.0.2.5) 56(84) bytes of data. 64 bytes from 192.0.2.5: icmp_seq=1 ttl=55 time=450 ms - Conclusion: DNS resolution is fast (TTL=86400), but the network path to the IP is slow. Possible fixes:
- Use a CDN (e.g., Cloudflare) to cache content closer to users.
- Check for routing issues with
traceroute 192.0.2.5.
8. Security in DNS: Protecting Against Attacks
| Attack | How It Works | Mitigation |
|---|---|---|
| DNS Spoofing | Fake responses injected into cache (e.g., redirecting bank.com to a phishing site). |
Use DNSSEC to sign records. |
| DDoS on DNS Servers | Flooding authoritative servers (e.g., ns1.esewa.com) with queries. |
Use Anycast (e.g., Cloudflare DNS). |
| Zone Transfer Abuse | Exfiltrating zone files via unauthorized AXFR. |
Restrict transfers to trusted IPs (allow-transfer). |
| Cache Poisoning | Corrupting resolver caches with malicious data. | Deploy DNSSEC and monitor logs. |
| Pharming | Redirecting traffic via compromised DNS (e.g., pathao.com → fake site). |
Use DNS over HTTPS (DoH) or DoT. |
Real-World Example: DNSSEC in Nepal
- Nepal’s
.npdomain uses DNSSEC to prevent spoofing. - When you visit
ntc.net.np, your resolver checks the digital signature of the DNS response to ensure it’s authentic.
9. DNS in the Real World
DNS is invisible but critical to every internet service. Here’s how Nepalese and global companies use it:
eSewa (
esewa.com.np)- A Records: Maps
esewa.com.npto its web server IPs (103.22.16.10). - MX Records: Routes emails to
mail.esewa.com(priority10). - CNAME:
api.esewa.comaliases toesewa.com.npfor backend services. - Why it matters: If eSewa’s DNS misconfigures its
MXrecord, users can’t receive payment confirmations.
- A Records: Maps
Ncell (
ncell.com.np)- Uses load-balanced DNS: Multiple
Arecords point to different web servers (e.g.,192.0.2.1,192.0.2.2) for high availability. - Anycast DNS: Root servers for
.npuse Anycast to distribute queries globally, reducing latency for international users.
- Uses load-balanced DNS: Multiple
Daraz (
daraz.com.np)- Geographic DNS: Returns different IPs based on user location (e.g.,
192.0.2.10for Kathmandu,192.0.2.20for Pokhara) via GeoDNS. - CDN Integration: Uses Cloudflare’s DNS to cache static content (e.g., product images) at edge locations.
- Geographic DNS: Returns different IPs based on user location (e.g.,
NTC (
ntc.net.np)- Critical Infrastructure: NTC’s DNS must be highly available—if
ntc.net.npresolves incorrectly, internet access for millions fails. - BGP + DNS: NTC’s routers use BGP to announce routes, but DNS translates
ntc.net.npto the correct gateway IP.
- Critical Infrastructure: NTC’s DNS must be highly available—if
NEPSE (
nepse.com.np)- Financial Security: NEPSE’s
MXrecords must be accurate to prevent email fraud (e.g., phishing for stock trade confirmations). - SPF/DKIM Records: Uses
TXTrecords to verify legitimate emails:nepse.com.np. IN TXT "v=spf1 ip4:192.0.2.4 ~all"
- Financial Security: NEPSE’s
10. Hands-On: Configuring a Primary DNS Server (BIND)
Let’s set up a primary DNS server for example.edu.np on Ubuntu using BIND.
Step 1: Install BIND
sudo apt update
sudo apt install bind9
Step 2: Configure the Zone File
Edit /etc/bind/db.example.edu.np:
$TTL 86400
@ IN SOA ns1.example.edu.np. admin.example.edu.np. (
2023101501 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
@ IN NS ns1.example.edu.np.
@ IN A 192.168.1.10
www IN CNAME @
mail IN A 192.168.1.20
@ IN MX 10 mail.example.edu.np.
Step 3: Update BIND Configuration
Edit /etc/bind/named.conf.local:
zone "example.edu.np" {
type master;
file "/etc/bind/db.example.edu.np";
allow-transfer { 192.168.1.20; }; // Secondary server IP
};
Step 4: Restart BIND
sudo systemctl restart bind9
Step 5: Test DNS
dig @localhost example.edu.np
Expected output:
;; ANSWER SECTION:
example.edu.np. 86400 IN A 192.168.1.10
Exam Tip
Understand the Hierarchy: Always draw the root → TLD → authoritative flow. Examiners love questions like: "Trace how
dig google.comresolves from a recursive resolver." Answer: Root →.comTLD → Google’s authoritative servers.Zone File Syntax: Memorize the SOA record format and common records (
A,MX,CNAME). A typical exam question: *"Write the zone file forcollege.edu.npwith:- Web server at
192.168.1.10 - Mail server
mail.college.edu.npat192.168.1.20 - Alias
wwwto@"* Answer: Use the template from Section 3 above.
- Web server at
Troubleshooting Scenarios: Be ready to diagnose issues like:
- "A website loads but emails fail. What record is missing?" → MX record.
- "DNS resolution takes 5 seconds. Why?" → High TTL or slow authoritative server.
Security Questions: Expect:
- "How does DNSSEC prevent cache poisoning?" → Digital signatures validate responses.
- "Why use secondary DNS servers?" → Redundancy and load balancing.
Real-World Applications: Relate concepts to Nepalese services:
- "How does Ncell use DNS for load balancing?" → Multiple
Arecords for web servers. - "Why might eSewa’s DNS fail during a power outage?" → Primary server downtime (no secondaries).
- "How does Ncell use DNS for load balancing?" → Multiple
Key Formulas and Shortcuts
| Concept | Formula/Command | When to Use |
|---|---|---|
| TTL Calculation | TTL = 3600 (1 hour) |
Set in SOA record for cache duration. |
| Zone Transfer | rndc refresh domain.com |
Update secondaries after zone file changes. |
| DNS Query Types | dig A, dig MX, dig TXT |
Debug specific record types. |
| DNSSEC Validation | dig +dnssec google.com |
Check if a domain uses DNSSEC. |
Common Pitfalls
- Circular CNAMEs: Never do
A CNAME BandB CNAME A—it creates a loop. - Missing SOA Record: Without an SOA, the zone file is invalid.
- Incorrect TTL: Too high = slow updates; too low = excessive queries.
- Firewall Blocking Port 53: DNS won’t work if TCP/UDP 53 is blocked.
- Forgetting Trailing Dot: In zone files,
example.commust beexample.com.(FQDN).
Summary Checklist
Before the exam, ensure you can:
- Explain the DNS hierarchy (root → TLD → authoritative).
- Write a zone file for a given domain (e.g.,
university.edu.np). - Trace a DNS query step-by-step (use the sequence diagram).
- Fix common misconfigurations (missing
MX, circularCNAME). - Describe DNS security risks (spoofing, DDoS) and mitigations.
- Configure BIND for a primary/secondary setup.
Based on the TU BSc CSIT syllabus for Network and System Administration, unit 5.
Discussion
Loading…