Skip to Content

How 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.

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.

Check 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.

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.