How to Check DNS Server in Linux: dig, nslookup, resolvectl

Check which DNS server Linux is using with resolvectl, dig, and cat /etc/resolv.conf — verify DNS resolution, test specific servers, and debug DNS configuration.

April 22, 2026·5 min read·Damon

Which DNS server is this machine using? Is it resolving correctly? Is it using the right server for internal hostnames? Here's how to check all of it.


TL;DR

# Current DNS servers
cat /etc/resolv.conf
resolvectl status | grep "DNS Servers"

# Test resolution
dig google.com
nslookup google.com

# Test with a specific DNS server
dig google.com @8.8.8.8

Check Configured DNS Server

/etc/resolv.conf

cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
  • nameserver — DNS servers queried in order
  • search — domain suffix appended to short hostnames

Warning on Ubuntu: /etc/resolv.conf is a symlink managed by systemd-resolved. Editing it directly won't persist.

ls -la /etc/resolv.conf
# /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

resolvectl (Ubuntu/systemd systems)

resolvectl status
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 8.8.8.8
       DNS Servers: 8.8.8.8 8.8.4.4
        DNS Domain: example.com

This shows DNS per network interface — useful when different interfaces use different DNS servers.

Compact form

resolvectl status | grep -A3 "DNS Server"
# or
systemd-resolve --status | grep "DNS Servers"

Test DNS Resolution

dig: The Professional Tool

# Basic lookup
dig google.com

# Short answer only
dig +short google.com
# 142.250.80.46

# Query a specific record type
dig google.com MX     # mail servers
dig google.com NS     # name servers
dig google.com TXT    # text records
dig google.com AAAA   # IPv6 address

# Reverse lookup (IP to hostname)
dig -x 8.8.8.8

dig output:

; <<>> DiG 9.18.0 <<>> google.com
;; ANSWER SECTION:
google.com.     300  IN  A  142.250.80.46

;; Query time: 12 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)
  • SERVER: — which DNS server answered
  • Query time: — how long it took
  • ANSWER SECTION: — the actual result

nslookup: Simpler Interactive Tool

nslookup google.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   google.com
Address: 142.250.80.46

Test With a Specific DNS Server

# Test with Google DNS
dig google.com @8.8.8.8

# Test with Cloudflare DNS
dig google.com @1.1.1.1

# Test with internal DNS
dig internal.company.com @10.0.0.1

# Compare results
for dns in 8.8.8.8 1.1.1.1 9.9.9.9; do
  echo -n "$dns: $(dig +short google.com @$dns) "
  dig google.com @$dns | grep "Query time"
done

Real Examples

Find which DNS server is actually being used

# dig shows the server that responded
dig google.com | grep "SERVER:"
# ;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
# 127.0.0.53 = systemd-resolved stub resolver

# The real upstream server
resolvectl status | grep "Current DNS Server"
# Current DNS Server: 8.8.8.8

Debug internal hostname not resolving

# Does the internal DNS server know about it?
dig internal-host @10.0.0.1
# ANSWER SECTION: internal-host. 300 IN A 10.0.2.50  ← it works

# But does the system use that server?
cat /etc/resolv.conf | grep nameserver
# nameserver 8.8.8.8  ← only using public DNS, not internal

# Fix: add internal DNS
# RHEL: nmcli connection modify eth0 ipv4.dns "10.0.0.1 8.8.8.8"
# Ubuntu: add to netplan

Verify DNS propagation after a change

# Check the same hostname at different DNS servers
for dns in 8.8.8.8 1.1.1.1 9.9.9.9 208.67.222.222; do
  result=$(dig +short mysite.com @$dns)
  echo "$dns → $result"
done

Check DNS response time

dig google.com | grep "Query time"
# ;; Query time: 12 msec

# Compare multiple servers
for dns in 8.8.8.8 1.1.1.1 9.9.9.9; do
  time=$(dig google.com @$dns | grep "Query time" | awk '{print $4}')
  echo "$dns: ${time}ms"
done

Check DNS Cache

# Flush systemd-resolved cache
resolvectl flush-caches
# or
systemd-resolve --flush-caches

# Check cache statistics
resolvectl statistics

# Flush on RHEL (nscd if installed)
nscd -i hosts

Common Mistakes

Mistake 1: Editing /etc/resolv.conf directly on Ubuntu It's a symlink managed by systemd-resolved. Edits get overwritten. Use netplan or nmcli to set DNS persistently.

Mistake 2: Trusting /etc/resolv.conf as the final answer The system may use nscd or systemd-resolved caching in front of it. dig shows which server actually answered.

Mistake 3: Ignoring the search domain search example.com means ping db01 resolves as db01.example.com. If the search domain is wrong, short hostnames won't resolve correctly.

Mistake 4: Not testing from the right location A hostname may resolve correctly from your laptop but not from the server. Always test from the machine that has the problem.


Quick Reference

cat /etc/resolv.conf               # configured nameservers
resolvectl status                  # detailed DNS config per interface
dig google.com                     # test resolution
dig +short google.com              # answer only
dig google.com @8.8.8.8            # test with specific server
dig -x 8.8.8.8                     # reverse lookup
nslookup google.com                # simple test
resolvectl flush-caches            # flush DNS cache

Conclusion

cat /etc/resolv.conf for the configured servers, resolvectl status for per-interface detail on systemd systems. Use dig (not nslookup) for serious testing — it shows which server responded and how long it took. Test with @8.8.8.8 to bypass local config and verify the DNS record itself is correct.


Related: DNS Not Resolving Linux Fix — when DNS is broken and you need to fix it. How to Restart Network Service Linux — apply DNS config changes.