Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a command to list dns servers?

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

share|improve this question
    
What are you trying to find? the DNS servers being used by your system? or are you trying to do a DNS lookup? –  Thomas W. Jun 18 '12 at 14:42
    
The former @LordofTime –  izx Jun 18 '12 at 15:16
    
@LordofTime DNS servers being used by my system –  Anurag Uniyal Jun 18 '12 at 15:19
    
@izx asking for clarification is perfectly acceptable :P –  Thomas W. Jun 18 '12 at 15:21
add comment

4 Answers

up vote 27 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. Here is the alias I use:

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.

share|improve this answer
    
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
    
That didn't work for me, but nm-tool does. –  Matt H Apr 8 at 0:58
show 1 more comment

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

share|improve this answer
    
just wanted to add-up, going to nm-applet's connection information menu will also work :) –  Samik Jun 18 '12 at 15:26
    
+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
add comment

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
share|improve this answer
3  
but /etc/NetworkManager/NetworkManager.conf doesn't have any dns servers listed in it –  Anurag Uniyal Jun 18 '12 at 15:20
add comment

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.

 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 the network-manager. In my opinion its a pill of crap. everything you need to do you can do manually without the worry that it is going to change your settings especially if you have multiple NIC's on the computer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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