How to Check and Identify DNS Servers on Ubuntu

DNS (Domain Name System) servers translate human-readable domain names into IP addresses that computers use to communicate. If you’re troubleshooting network issues, optimizing connectivity, or verifying your system’s configuration, knowing which DNS servers are in use is crucial.

In this guide, we’ll explore various ways to check DNS servers on an Ubuntu system, with detailed explanations of the commands used.


Step-by-Step Guide

1. Using systemd-resolve

Modern Ubuntu versions rely on systemd-resolved for DNS resolution. You can check the current DNS configuration using this command:

systemd-resolve --status

What This Command Does:

  • systemd-resolve: A tool to query the DNS settings managed by systemd-resolved.
  • --status: Displays detailed information about the current DNS configuration, including DNS servers, search domains, and routing for each network interface.

Example Output:

Global
     DNS Servers: 8.8.8.8
                  8.8.4.4
Link 2 (enp0s3)
     Current Scopes: DNS
          DNS Servers: 192.168.1.1
  • The Global section shows DNS servers applied system-wide.
  • The Link section lists DNS servers used by specific interfaces like enp0s3.

2. Using nmcli

If your system uses Network Manager, the nmcli command provides detailed information about network configurations, including DNS servers.

Run the following command:

nmcli dev show | grep DNS

What This Command Does:

  • nmcli: The command-line interface for Network Manager.
  • dev show: Displays information about devices managed by Network Manager.
  • | grep DNS: Filters the output to show only lines containing “DNS.”

Example Output:

IP4.DNS[1]:                             192.168.1.1
IP4.DNS[2]:                             8.8.8.8

Here, IP4.DNS[1] and IP4.DNS[2] indicate the DNS servers being used for IPv4 traffic.


3. Inspecting /etc/resolv.conf

The /etc/resolv.conf file traditionally contains DNS settings. To view its contents, run:

cat /etc/resolv.conf

What This Command Does:

  • cat: Displays the contents of a file.
  • /etc/resolv.conf: The file where DNS resolvers are configured.

Example Output:

nameserver 127.0.0.53
  • If the nameserver is 127.0.0.53, your system uses systemd-resolved. You can then use systemd-resolve --status to see the actual DNS servers.
  • Otherwise, the listed nameserver values represent the active DNS servers.

4. Using the dig Command

The dig command queries DNS servers to resolve domain names. Install dnsutils if it’s not available:

sudo apt install dnsutils

Then, run:

dig google.com

What This Command Does:

  • dig: A DNS query tool.
  • google.com: The domain name to query.

Example Output:

;; ANSWER SECTION:
google.com.      299   IN   A   142.250.72.14

;; SERVER: 8.8.8.8#53(8.8.8.8)
  • The ANSWER SECTION shows the resolved IP address for google.com.
  • The SERVER line indicates the DNS server used for the query (in this case, 8.8.8.8).

5. Using resolvectl (Alternative to systemd-resolve)

On some systems, resolvectl replaces systemd-resolve. To display DNS configuration:

resolvectl status

What This Command Does:

  • resolvectl: Queries and controls the DNS resolver managed by systemd-resolved.
  • status: Displays detailed information about DNS resolution.

The output is similar to systemd-resolve --status.


6. Using nslookup

The nslookup tool also helps identify the DNS server used for resolving queries. Install it if necessary:

sudo apt install dnsutils

Run the command:

nslookup google.com

What This Command Does:

  • nslookup: Queries a DNS server for information.
  • google.com: The domain name to resolve.

Example Output:

Server:  8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
Name:   google.com
Address: 142.250.72.14
  • The Server line shows the DNS server handling the query (8.8.8.8).

Conclusion

With tools like systemd-resolve, nmcli, dig, and others, you can easily identify which DNS servers your Ubuntu system is using. Each method provides unique insights, whether you’re troubleshooting, verifying configurations, or optimizing your DNS setup.

For additional guidance, refer to the Ubuntu Networking Guide or the Ask Ubuntu community.


By mastering these commands, you can efficiently diagnose DNS-related issues and ensure optimal network performance.