Ubuntu – Command-line to list DNS servers used by the system

command linedns

Is there a command to list dns servers used by my system?

I tried

$ cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
$ cat /etc/network/interfaces 
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

But it doesn't list any servers, if I go to "Network Manager GUI Tool", in Wireless section it lists "DNS 192.168.1.1 8.8.8.8 8.8.4.4"

Can I get same information from command line?

I am using Ubuntu 12.04 LTS

Best Answer

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.

Related Question