Linux / Unix: Find Out DNS Server IP Address / Names

How do I find out my DNS server IP address assiged my my ISP under Unix or Linux operating system using command prompt? How do I find preferred dns server under Debian / Ubuntu / Fedora Linux desktop system?

Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time N/A
Under Unix or Linux operating systems the resolver is used (set of routines in the C library) that provide access to the Internet Domain Name System (DNS). The resolver configuration file is located at /etc/resolv.conf location and it contains information that is read by the resolver routines the first time they are invoked by a process. Use the cat command or grep command to find out your dns server addresses as follows:
cat /etc/resolv.conf

Sample outputs:

# Generated by NetworkManager

In this example my dns server address are and in dot notation that the resolver should query. Currently name servers may be listed, one per keyword. If there are multiple servers, the resolver library queries them in the order listed. If no nameserver entries are present, the default is to use the name server on the local machine. The grep command can be used as follows:
$ grep --color nameserver /etc/resolv.conf
Sample outputs:

Fig.01: Linux / Unix: Find Preferred Dns Server Command

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • Thad E Ginathom Oct 3, 2012 @ 20:01

    For the cynical, who might think, “That is what the configuration file is telling the system to do, how can I be sure what it *is* doing, you can find out how your system resolves any given name using dig

    $ dig

    ; <> DiG 9.8.1-P1 <>
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46538
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

    ; IN A


    ;; Query time: 870 msec
    ;; SERVER:
    ;; WHEN: Thu Oct 4 01:26:31 2012
    ;; MSG SIZE rcvd: 80

  • Jalal Hajigholamali Oct 4, 2012 @ 12:11


    Thanks a lot

    simple and useful ..

  • Mac Oct 4, 2012 @ 14:36

    Can someone help to explain to how use the color option but without using the case sensitive requirement like for example:

    grep –color hostname /etc/sysconfig/network
    no data output

    grep –color HOSTNAME /etc/sysconfig/network

    is there a way in grep to get it to display regardless of case sensitive?

    any help/advice would be great

    • iWonder Sep 30, 2015 @ 9:27

      Just use “grep -i”, case insensitive search
      ie., grep -i -color hostname /etc/sysconfig/network

  • JBruyet Oct 4, 2012 @ 19:33

    man grep
    that will give you -i, –ignore-case
    Ignore case distinctions in both the PATTERN and the input files. (-i is specified by POSIX.)

    man pages are your friend.


    Joe B

  • Thad E Ginathom Oct 4, 2012 @ 19:36

    $ man grep

    … … ..

    -i, –ignore-case
    Ignore case distinctions in both the PATTERN and the input
    files. (-i is specified by POSIX.)

    … … …

    Is that what you wanted?
    $ grep -i PEAFOWL hosts peafowl
    $ grep -i peafowl hosts peafowl

  • Mac Oct 5, 2012 @ 15:59

    Thanks Thad I will check that out.


  • spettro Dec 25, 2016 @ 3:12

    nm-tool | grep DNS

    • cata Jan 18, 2017 @ 21:49

      Thanks! Didn’t know about: nm-tool (NetworkManager Tool)

  • Bart Jan 13, 2017 @ 12:11

    grep -i
    grep --ignore
    for readability.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum