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

  • What are you trying to find? the DNS servers being used by your system? or are you trying to do a DNS lookup? – Thomas Ward Jun 18 '12 at 14:42
  • The former @LordofTime – ish Jun 18 '12 at 15:16
  • @LordofTime DNS servers being used by my system – Anurag Uniyal Jun 18 '12 at 15:19
  • you are using 127.0.0.1. are you running a DNS server? – Skaperen Aug 19 '15 at 10:18
  • See unix.stackexchange.com/q/28941/38647 for a non-Ubuntu version of this question – mwfearnley Jun 11 at 12:41
up vote 208 down vote accepted

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.

  • 2
    thanks, yes that seems to be working, ubuntu networking seems to be confusing, so I can set dns servers in resolve.conf/base or in /etc/network/interfaces or in network manager, is there a definitive guide for ubuntu networking? – Anurag Uniyal Jun 18 '12 at 15:26
  • If you use the GUI, then the best place to set it is by creating profiles in the Network Connections Dialog. I duplicated the default, then edited the duplicate to make the changes I wanted, keeping the default to make sure I always had a working profile. Then, it's easy to switch profiles. I don't know how to do this without the GUI, but there is a user "James Henstridge" who is very knowledgeable on Ubuntu's networking; you might try searching askubuntu for his information. He told me about the command I gave you in this post. – Marty Fried Jun 18 '12 at 15:35
  • 1
    stgraber.org/2012/02/24/dns-in-ubuntu-12-04 is a nice article abount DNS resolution in ubuntu 12.04 – Anurag Uniyal Jun 18 '12 at 15:37
  • Nice link - a lot of good information there to digest. – Marty Fried Jun 18 '12 at 15:56
  • 6
    I'm using 15.04 and 'nmcli dev show |grep DNS' works for me instead. – flickerfly Aug 11 '15 at 18:37

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
  • 1
    just wanted to add-up, going to nm-applet's connection information menu will also work :) – Samik Jun 18 '12 at 15:26
  • 1
    +1 this also works, as does nm-cli as answered by @Marty Fried – Anurag Uniyal Jun 18 '12 at 15:30
  • Yes, same info, but nmcli is easier to parse if you want to extract it out for a different presentation, such as conky, or simply a summary like my grep. – Marty Fried Jun 18 '12 at 15:40
  • 2
    works great on lubuntu 14.04 as well. thanks – jamescampbell Oct 21 '15 at 13:50
  • 1
    nm-tool is not found on 15.10 – labyrinth Nov 24 '15 at 17:16

The two top-scoring answers, nmcli dev list iface <interfacename> | grep IP4 and nm-tool both assume that network-manager is in control. Which it is - on desktop machines most of the time at least. But the fuller answer is that sometimes network-manager is not in control. E.g. vpnc messes with /etc/resolv.conf directly.

So: First check if 127.0.0.1/localhost is used. This could be done with dig:

> dig something.unknown  | grep SERVER:
;; SERVER: 127.0.0.1#53(127.0.0.1)

Now you know that we are using localhost. Go ahead with one of the popular answers. I like:

> nm-tool | grep DNS:
    DNS:             8.8.8.8

But if 127.0.0.1/localhost is not used, then nm-tool's and nmcli's output will be misleading:

> dig something.unknown  | grep SERVER:
;; SERVER: 172.22.216.251#53(172.22.216.251)
> nm-tool | grep DNS:
    DNS:             8.8.8.8

Here, dig is correct and nm-tool's information is misleading. In reality addresses local to the environment I've VPN-ed into are resolved correctly. All of which Google's DNS 8.8.8.8 doesn't know about.

This is because after connecting to a VPN with vpnc, it puts a line in /etc/resolv.conf so it looks like:

# 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 1.2.3.4
nameserver 127.0.0.1
search MyDomain
  • 2
    This is the most complete answer – Marinos An Jul 4 at 13:17
  • Thank you. Some of us out here do not use NM and that is good for the community. – Stephen Boston Sep 9 at 12:27

cat /etc/resolv.conf should show your DNS servers.

You may not modify the resolv.conf directly with Ubuntu 12.04. If you need to change them though, you can add new DNS servers in your /etc/network/interfaces file by adding the following:

 dns-nameservers x.x.x.x x.x.x.x

where x is the DNS servers you wish to use.

If I were you, I would uninstall network-manager. In my opinion it's a pile of crap.

You can accomplish everything you need to do manually without worrying about changing your settings, especially if you have multiple NICs on the computer.

  • 1
    Do I have to restart nm after doing the dns change? – Bhargav Nanekalva Mar 25 '15 at 7:43
  • 1
    --Thanks. This is great. It works even without that network-manager business. – Adam Jul 18 '15 at 8:23
  • "cat /etc/resolv.conf should show your DNS servers". It doesn't. – Marinos An Jul 4 at 13:14

nmcli version 0.9.10

You can use either of these commands:

nmcli -t -f IP4.DNS device show eth0
IP4.DNS[1]:192.168.1.1
IP4.DNS[2]:8.8.8.8

nmcli -t -f IP4.DNS connection show conn-name
IP4.DNS[1]:192.168.1.1
IP4.DNS[2]:8.8.8.8

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

In Ubuntu 15.10 you can get DNS

nmcli device show <interface name> 

Seems to be managed by network manager. Have a look here http://manpages.ubuntu.com/manpages/precise/man5/NetworkManager.conf.5.html

for a large explanation.

Or the short version it to look in

 /etc/NetworkManager/NetworkManager.conf

or

 <SYSCONFDIR>/NetworkManager/NetworkManager.conf
  • 4
    but /etc/NetworkManager/NetworkManager.conf doesn't have any dns servers listed in it – Anurag Uniyal Jun 18 '12 at 15:20

protected by Community May 28 '15 at 19:02

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.