How to Check DNS Server IP Address in Linux

DNS (Domain Name System) is a fundamental facilitator of several networking technologies such as mail servers, Internet browsing, and streaming services e.g., Netflix and Spotify, among others.

It works on a special computer called a DNS server – which keeps a database record of several public IP addresses along with their corresponding hostnames for it to resolve or translate hostnames to IP addresses upon user request.

This happens so that we would not need to bother ourselves with remembering the IP addresses of the different websites we visit.

While there are several things we can discuss on DNS servers, such as redirection and malware attack prevention, our focus today is on how to find out your very own dns server IP address.

How to Find Your DNS Server IP Address in Linux

There are several ways to check for it, depending on the Operating System that you’re running, but Linux, BSD, and Unix-like systems all share the same method, so let’s begin with them.

1. Using the /etc/resolv.conf File

The /etc/resolv.conf file is like a little address book for your computer, which tells your system which DNS servers to use whenever it needs to translate a website name (like google.com) into an IP address.

To view this file, you can use the cat command, which prints the entire content to your terminal.

cat /etc/resolv.conf

Or, if you want to scroll through it more comfortably, use less command.

less /etc/resolv.conf

Inside this file, you’ll usually see lines that look like this:

nameserver 109.78.164.20

Here’s what it means:

  • nameserver – This keyword indicates that the line defines a DNS server.
  • 109.78.164.20 – This is the IP address of the DNS server your computer will query when looking up website names.

So, whenever your computer wants to open a website, it asks this DNS server: “Hey, what’s the IP for example.com?” The server then responds with the correct IP address so your system can connect.

Think of /etc/resolv.conf as the first stop your computer makes when trying to figure out where a website lives. By checking this file, you can see exactly which DNS server your system is using.

2. For Systems Using systemd

Many modern Linux distributions, like Ubuntu, Fedora, and Debian, use systemd to manage system services, and one of the things systemd handles is network configuration, including DNS.

If your system uses systemd, the traditional /etc/resolv.conf file may not always show the full or correct DNS information because systemd manages DNS dynamically. In this case, you can use the resolvectl command with grep to check your DNS servers reliably.

resolvectl status | grep "DNS"

What this does:

  • resolvectl status shows detailed information about your network connections, including the DNS servers being used.
  • grep "DNS Servers" filters the output so you only see the lines that list the DNS IP addresses.

Example output:

DNS Servers: 192.168.0.1 8.8.8.8

Here, the first address (192.168.0.1) is usually your local router or gateway, while the second (8.8.8.8) might be a public DNS server like Google DNS.

3. If You’re Using NetworkManager

If your Linux system uses NetworkManager, which most modern desktop distributions do, you can easily find your DNS server IP using the nmcli command, which shows detailed information about all your network connections.

nmcli dev show | grep 'IP4.DNS'

Example output:

IP4.DNS[1]: 192.168.0.1

Here’s what it means:

  • IP4.DNS[1] indicates that this is the first IPv4 DNS server your system is using. If you have a secondary DNS server, it may appear as IP4.DNS[2].
  • 192.168.0.1 is the DNS server IP address, which is the address your computer contacts to resolve domain names into IP addresses.

The format 192.168.0.1 is called dot-decimal notation, which is the standard way IP addresses are written, with four numbers separated by dots. Each number ranges from 0 to 255, representing 8 bits of the address.

How to Find a Website’s DNS Server IP Address

To find out a website’s DNS Server IP address, you can use the following dig command, which is used to query DNS information.

tecmint.com
Sample Output
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.1 <<>> tecmint.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30412
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;tecmint.com.			IN	A

;; ANSWER SECTION:
tecmint.com.		21	IN	A	204.45.67.203
tecmint.com.		21	IN	A	204.45.68.203

;; Query time: 0 msec
;; SERVER: 209.74.194.20#53(209.74.194.20)
;; WHEN: Mon Jun 24 07:25:42 2019
;; MSG SIZE  rcvd: 61

The output will provide you with a list of IP addresses for authoritative nameservers for your website (i.e., the DNS servers responsible for your domain).

tecmint.com.		21	IN	A	204.45.67.203
tecmint.com.		21	IN	A	204.45.68.203

Please note that the actual IP addresses you receive may vary depending on your website hosting provider or domain registrar. If your website is using third-party DNS services like Cloudflare or Google Cloud DNS, the IP addresses will be specific to those services.

Easy right? Perhaps we’ll talk about primary and secondary DNS Server addresses next time. Till then, feel free to share and drop your comments/suggestions in the discussion section below.

💡 Want to Level Up Your Linux Skills?

Check out Pro.Tecmint.com for ad-free reading, exclusive guides, downloadable resources, and certification prep (RHCSA, RHCE, LFCS) - all with lifetime access.

Martins D. Okoi
Martins Divine Okoi is a graduate of Computer Science with a passion for Linux and the Open Source community. He works as a Graphic Designer, Web Developer, and programmer.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

12 Comments

Leave a Reply
  1. When using local dns cache systemd-resolved you can use:

    $ resolvectl status 
    

    It will show the current DNS servers for each interface. You can specify the interface name (found with $ ifconfig) to filter a specific interface.

    For example,

    $ resolvectl status eth0
    $ resolvectl status eth0
    

    Sample Output

    Link 1 (eth0)
          Current Scopes: DNS      
    DefaultRoute setting: yes      
           LLMNR setting: yes      
    MulticastDNS setting: no       
      DNSOverTLS setting: no       
          DNSSEC setting: no       
        DNSSEC supported: no       
      Current DNS Server: 10.0.0.1
             DNS Servers: 10.1.0.1
    
    Reply
  2. $ nslookup -type=any google.com
    

    Server: 192.168.7.1
    Address: 192.168.7.1:53
    Non-authoritative answer:
    Name: google.com
    Address: 142.250.191.206
    google.com nameserver = ns1.google.com
    google.com nameserver = ns4.google.com
    google.com nameserver = ns2.google.com
    google.com nameserver = ns3.google.com

    Server: 192.168.7.1

    Reply
  3. Many Linux users these days use a dns cache and so the dns server in resolve.conf is a loopback address to the dns cache on your own PC/Linux.

    systemd’s resolved is also often used but this updates resolve.conf for informational reference. Systemd-Resolved can have different dns servers for different networks concurrently and the resolve.conf will not reflect this but the man pages and status command are very informative.

    network manager also does some things differently. i think it sets up one of these dns caches but id don’t know much about it.

    I keep reading these “how to find my dns” how to pages but have yet to find one that covers the more modern scenarios.

    Reply
  4. On my Fedora 29 and RHEL 8 /etc/resolv.conf is still used for listing the nameservers.

    Same for my PureOS, Alpine, TinyCore and Atomic Host…

    My Ubuntu 16.04 LTSB and 18.04 LTSB have 127.0.0.1 and 127.0.0.53 respectively.

    Reply
  5. Except that all the modern Desktop Linux distros stopped listing nameservers in /etc/resolve.conf many years ago! If you look in that file now, all you get is 127.0.1.1, because most now have a local caching nameserver.

    Reply
    • Yes, anytime I see an article written since NetworkManager was forced upon us that still thinks resolv.conf is at all a useful source, I immediately know the author is clueless.

      Reply
  6. How to find your own external IP address?

    $ dig +short myip.opendns.com @resolver1.opendns.com
    

    This works fine on CentOS and RHEL but not on Ubuntu. Looks like Ubuntu’s dig command has less capabilities.

    Reply
  7. That’s almost completely wrong and complete deprecated on almost every recent Ubuntu or Debian version I’ve used ! Contents of resolv.conf on my Raspberry Pi running Raspbian Stretch :

    # Generated by resolvconf
    domain LOCAL
    nameserver 127.0.0.1
    

    looking at the contents /etc/resolv.conf may have been true 10+ years ago – on a UNIX system like Solaris…

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.