Skip to Content

4 ways to Check DNS Server in Ubuntu

Introduction

When you browse the internet, you are actually accessing different websites by their domain names. However, your computer doesn’t understand domain names, so it needs to translate them into IP addresses.

This is where Domain Name System (DNS) servers come into play. A DNS server is responsible for translating domain names into IP addresses. In this blog post, we will discuss how to check DNS server in Ubuntu.

Check DNS Server with systemd-resolve command in Ubuntu

In Ubuntu, you can check the DNS server by using the systemd-resolve command. Open the terminal and type the following command:

systemd-resolve --status | grep 'DNS Servers'

This command will display the DNS server that your system is currently using. If you have multiple DNS servers configured, it will show all of them.

Get Your Free Linux training!

Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!

For example,

# systemd-resolve --status | grep 'DNS Servers'
DNS Servers**: 10.0.0.2

In Ubuntu 18.04 and 20.04 we can use systemd-resolve –status. In newer versions, we can use resolvectl status.

Check DNS server with tcpdump command in Ubuntu

You can also check the DNS server in Ubuntu using the tcpdump command. Open the terminal and type the following command:

sudo tcpdump -n -i any port 53

This command will display all DNS traffic on your system, including the DNS servers that your system is using.

You can stop the command by pressing Ctrl+C. This method is useful for troubleshooting DNS issues or for monitoring DNS traffic on your system.

Here is one example of this.

13:52:05.279330 IP 10.0.0.76.53630 > 10.0.0.2.53: 34214+ [1au] A? kinesis.us-east-1.amazonaws.com. (60)
13:52:05.279481 IP 10.0.0.76.49768 > 10.0.0.2.53: 22036+ [1au] AAAA? kinesis.us-east-1.amazonaws.com. (60)
13:52:05.281134 IP 10.0.0.2.53 > 10.0.0.76.53630: 34214 1/0/1 A 3.227.250.254 (76)
13:52:05.281543 IP 10.0.0.2.53 > 10.0.0.76.49768: 22036 0/1/1 (138)

This is the command output in my system. We can see that 10.0.0.2 is the DNS server.

Find DNS server with dig command in Ubuntu

You can also check the DNS server in Ubuntu using the dig command. Open the terminal and type the following command:

dig google.com

This command will display the IP address of the DNS server that was used to resolve the domain name of google.com.

You can replace google.com with any other domain name to check which DNS server was used to resolve it.

For example,

# dig google.com
; <<>> DiG 9.16.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6566
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com.            IN  A
;; ANSWER SECTION:
google.com.     73  IN  A   172.217.14.238
;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Feb 28 13:56:59 UTC 2023
;; MSG SIZE rcvd: 55

From the output, we can see that 127.0.0.53 is the local DNS server ip. 127.0.0.53 is the address of the local caching stub resolver. It forwards DNS requests to whatever upstream DNS servers you specify.

Most distributions of Linux nowadays use local resolvers, which essentially cache DNS lookup results on your local computer. It’s just an additional layer in between your computer and the DNS server.

Checking DNS Server in Ubuntu Network Manager

If you are using Network Manager to manage your network connections, you can also check the DNS server that your system is using through the GUI. Follow these steps:

  1. Click on the Network Manager icon in the top-right corner of the screen.
  2. Click on the gear icon next to the network you are connected to.
  3. Click on the IPv4 or IPv6 tab, depending on which protocol you are using.
  4. Under the DNS section, you will see the DNS servers that your system is currently using.

 

nmcli is a command-line tool provided by NetworkManager, which is widely used in many Linux distributions, including Ubuntu, for network configuration and management.

The command nmcli dev show | grep ‘IP4.DNS’ is used in Unix-like operating systems, such as Ubuntu, to display the DNS server settings for network interfaces managed by NetworkManager.

nmcli dev show | grep 'IP4.DNS'

dev show:

  • dev is short for device. This part of the command requests information about network devices.
  • show tells nmcli to display detailed information about each network device.


| grep ‘IP4.DNS’:

  • The pipe symbol | is used to pass the output of the preceding command (nmcli dev show) to another command.
  • grep is a command-line utility used for searching plain-text data for lines that match a regular expression.
  • ‘IP4.DNS’ is the regular expression. In this context, it tells grep to filter and display only those lines of the output that contain ‘IP4.DNS’.

 

Conclusion

In this blog post, we have discussed how to check DNS server in Ubuntu. By using the systemd-resolve command, tcpdump command and network manager. Knowing which DNS server your system is using can be helpful in troubleshooting network issues or configuring your network settings.

JefferyL

Tuesday 17th of December 2024

cool. This is accurate info.

Eric H

Sunday 26th of November 2023

The methods you've outlined are clear and easy to follow, making them accessible even to those new to Ubuntu.

Articles like this are invaluable for both beginners and experienced users who need a quick refresher on managing network settings in Linux environments.