Command-line to list DNS servers used by my system

resolv.conf isn't really used anymore, unless you implement it yourself. The network manager does it now. I created an alias to list the DNS servers on my system, as I sometimes switch from OpenDNS to Google's open DNS.

Ubuntu >= 15

nmcli device show <interfacename> | grep IP4.DNS

Ubuntu <= 14

nmcli dev list iface <interfacename> | grep IP4

In my case, <interfacename> is eth0, which is common, but not always the case.

See if this is what you want.

EDIT:

I think resolv.conf is actually used indirectly, because the network manager creates the server that listens on 127.0.0.1, but I was told that this is an implementation detail that should not be counted on. I think that if you enter DNS addresses before this entry, they might get used, but I'm not sure exactly how this works. I think it's best to use the network manager in most cases, when possible.


This is valid for Ubuntu 13.10 and earlier. For Ubuntu 14.04 and above, see Koala Yeung's answer to: How to know what DNS am I using in Ubuntu from 14.04 onwards


Use

nm-tool

You will get an output similar to

NetworkManager Tool

State: connected (global)

- Device: eth0  [Wired connection 1] -------------------------------------------
  Type:              Wired
  Driver:            e1000e
  State:             connected
  Default:           yes
  HW Address:        00:11:22:33:44:55

  Capabilities:
    Carrier Detect:  yes
    Speed:           1000 Mb/s

  Wired Properties
    Carrier:         on

  IPv4 Settings:
    Address:         10.21.6.13
    Prefix:          24 (255.255.255.0)
    Gateway:         10.21.6.1

    DNS:             10.22.5.133
    DNS:             10.22.5.3

Or to see just the DNS do

nm-tool | grep DNS

In Ubuntu 18.04 you can use systemd-resolve --status