Home/Engineer/Troubleshooting/Diagnosing DNS Resolution Er…
TroubleshootingBeginnerUbuntuDebianCentOSdnsnslookupdig

Diagnosing DNS Resolution Errors — nslookup · dig · systemd-resolved

How to diagnose and fix DNS issues such as lookup failures, cache pollution, and incorrect nameserver configuration using nslookup, dig, host, and systemd-resolved.

Contents
  1. DNS Error Symptoms
  2. Basic Diagnostic Tools
  3. dig — Detailed DNS Analysis
  4. systemd-resolved (Ubuntu 22.04+)
  5. Common DNS Problems and Fixes
  6. Troubleshooting Checklist

DNS Error Symptoms

  • curl: Could not resolve host: example.com
  • ssh: Could not resolve hostname
  • Only certain sites fail to load in the browser
  • Ping works, but connecting by domain name fails

Basic Diagnostic Tools

Bash
# Check the current DNS servers
cat /etc/resolv.conf
# nameserver 8.8.8.8
# nameserver 1.1.1.1

# Basic DNS lookup (nslookup)
nslookup google.com
nslookup google.com 8.8.8.8    # Query a specific DNS server

# host command
host google.com
host google.com 1.1.1.1

# Reverse lookup (IP → domain)
nslookup 8.8.8.8
host 8.8.8.8

dig — Detailed DNS Analysis

Bash
# Query A records
dig google.com

# Specific record types
dig google.com A
dig google.com AAAA      # IPv6
dig google.com MX        # Mail servers
dig google.com TXT       # SPF, DKIM, etc.
dig google.com NS        # Name servers
dig google.com CNAME     # Alias

# Query a specific DNS server (@)
dig @8.8.8.8 google.com
dig @1.1.1.1 google.com

# Short output (+short)
dig +short google.com
dig +short google.com MX

# Check propagation (query multiple DNS servers)
for ns in 8.8.8.8 1.1.1.1 9.9.9.9 208.67.222.222; do
  echo -n "$ns: "; dig +short @$ns example.com
done

# Trace (root → TLD → authoritative servers)
dig +trace google.com

systemd-resolved (Ubuntu 22.04+)

Bash
# Check current DNS configuration
resolvectl status
resolvectl dns

# Query a specific domain
resolvectl query google.com

# Flush the DNS cache
sudo resolvectl flush-caches

# Statistics
resolvectl statistics

# Temporarily change DNS servers
sudo resolvectl dns eth0 8.8.8.8 1.1.1.1

Common DNS Problems and Fixes

Problem 1: /etc/resolv.conf is empty or incorrect

Bash
cat /etc/resolv.conf

# Temporary fix
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
echo "nameserver 1.1.1.1" | sudo tee -a /etc/resolv.conf

# Permanent setting on Ubuntu (using systemd-resolved)
sudo nano /etc/systemd/resolved.conf
# [Resolve]
# DNS=8.8.8.8 1.1.1.1
# FallbackDNS=9.9.9.9
sudo systemctl restart systemd-resolved

Problem 2: Only a specific domain fails (cache pollution)

Bash
# Flush the DNS cache
sudo resolvectl flush-caches             # systemd-resolved
sudo systemd-resolve --flush-caches

# Flush the nscd cache (if installed)
sudo systemctl restart nscd

# Query DNS servers directly and compare
dig @8.8.8.8 example.com
dig @local-dns-server example.com

Problem 3: Internal DNS server cannot be found

Bash
# When internal domains fail to resolve on VPN/corporate networks
# Check the search domain setting
cat /etc/resolv.conf | grep search

# Use a different DNS server for a specific domain (systemd-resolved)
# /etc/systemd/resolved.conf.d/internal.conf
# [Resolve]
# DNS=10.0.0.1
# Domains=internal.example.com

Problem 4: Waiting for TTL propagation

Bash
# Check TTL (time until the record expires)
dig google.com | grep -A1 "ANSWER SECTION"
# google.com. 299 IN A 142.250.196.110
#             ↑ cache expires after 299 seconds

# Verify new record propagation
dig +short @ns1.registrar.com yourdomain.com
dig +short @8.8.8.8 yourdomain.com

Troubleshooting Checklist

Bash
# 1. Verify basic internet connectivity
ping -c 3 8.8.8.8

# 2. Verify DNS resolution
dig +short @8.8.8.8 google.com

# 3. Check the local DNS server
dig +short google.com

# 4. Check /etc/hosts (forced overrides)
cat /etc/hosts | grep -v "^#" | grep -v "^$"

# 5. DNS server response time
dig @8.8.8.8 google.com | grep "Query time"
#dns#nslookup#dig#Troubleshooting#systemd-resolved
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Topic-related official docs (auto-linked · not per-claim sources)Linux man pages ↗

Questions & answers

Ask a question about this guide. We'll review and reply.