DNS server address no longer stored in resolv.conf; where is it now?

18,881

Solution 1

The information is managed internally by Network Manager. You can get this information on the command line using the included nmcli tool.

You can retrieve Network Manager's information for a particular network interface with the following command:

nmcli dev list iface eth0

(replace eth0 with the interface you are connecting with). The output will include information about the interface and the currently active connection on that interface:

GENERAL.DEVICE:                         eth0
GENERAL.TYPE:                           802-3-ethernet
...
IP4.DNS[1]:                             192.168.0.1
...

It shouldn't be too difficult to extract the information you are after from this output.

If you need a programmatic method of accessing this data that doesn't rely on the output of nmcli, this information should also be available from Network Manager's D-Bus interface.

Solution 2

Ubuntu developers should document these changes in /etc/resolv.conf, but have not.

Here is a list of quick commands to get you going.

  1. Show the current DNS servers

    nm-tool | grep DNS
    
  2. Define a static DNS server in /etc/dhcp/dhclient.conf. Add the following line, and restart local resolver:

    supersede domain-search "sub.mydomain.com", "domain.com";
    prepend domain-name-servers 192.168.0.1;
    

    From the command prompt:

    invoke-rc.d network-manager restart
    

Solution 3

Be aware that using nmcli may not always give you the full answer. e.g. if you use openconnect (or vpnc, presumably) to start a VPN, and if you have the resolvconf package installed (to take care of automatically managing /etc/resolv.conf), you'll find that it can still automatically insert the VPN's DNS settings into /etc/resolv.conf ahead of 127.0.0.1. In this circumstance, just checking (e.g.) "nmcli -f IP4 dev list" won't give you the true current DNS list. Not sure if this scenario affects you, but figured it worth mentioning.

Share:
18,881

Related videos on Youtube

Deepak Verma
Author by

Deepak Verma

Updated on September 18, 2022

Comments

  • Deepak Verma
    Deepak Verma over 1 year

    I sometimes switch DNS servers, using the NetworkManager indicator in the taskbar; this worked fine with previous versions, and actually works fine with 12.04, too, except for one thing: I use Conky to display some system information, including the DNS address, and I noticed that it is now always displaying 127.0.0.1.

    I looked in resolv.conf, which is where it gets this address, and sure enough, that's what it always says. I has a single line, with the admonishment not to edit the file by hand:

    nameserver 127.0.0.1
    

    The only way I know to check the DNS server address now is to open the network manager GUI to check the info page. So, where is this information stored now?

  • Deepak Verma
    Deepak Verma about 12 years
    Thanks a lot, that's some great information. It should be pretty easy to create a simple shell script using that nmcli command to list various interesting parameters. Maybe I can whip something useful up and share someplace. I didn't really think Network Manager was required, and I suppose there may be alternate ways for someone to do this, but this works for me.
  • James Henstridge
    James Henstridge about 12 years
    Well, you can see that the server listening on 127.0.0.1 is an instance of dnsmasq started by Network Manager (see the output of sudo netstat -tlnp). But it is best to think of that as an implementation detail and ask Network Manager for the information you want, since it is the one making the decision here.
  • Deepak Verma
    Deepak Verma about 12 years
    Thanks for providing such good information. And, thanks also for editing my question - I'll try to take more time in the future. :) My excuse is that I had just upgraded to 12.04, and was putting out little fires on multiple fronts. :)
  • Deepak Verma
    Deepak Verma about 12 years
    Thanks for the extra info; it's always good to learn more. For my use case, I won't have to worry about it, as I mainly just want to be able to know which of two possible DNS addresses is active.
  • jdthood
    jdthood over 11 years
    Some more documentation: resolvconf(8), /usr/share/doc/resolvconf/README.gz.
  • Jorge Suárez de Lis
    Jorge Suárez de Lis over 11 years
    If you are using networkmanager to connect to a VPN, what command should give you the dns? The dns are working but I can't find them.
  • Beni Cherniavsky-Paskin
    Beni Cherniavsky-Paskin almost 9 years
    nmcli dev list iface doesn't work for me but nmcli dev show does [ubuntu 15.04]