89

After upgrade to 13.10 my DNS resolving fails. It seems the DNS servers which I get by DHCP (LAN) are not used.

I could temporary solve the problem by adding nameserver 8.8.8.8 to /etc/resolv.conf. But then the intranet hosts still can not be resolved.

When clicking on the Connection Information menu item on the network indicator, the Primary DNS and the Secondary DNS are set correctly. But my computer seams not to use them.

So my questions:

  • What should I put into resolv.conf, if anything?
  • How to find out, which name servers my computer is querying?
  • Where to look next, to find out, why name servers received by DHCP are not used?
Braiam
  • 67,791
  • 32
  • 179
  • 269
Witek
  • 3,933

7 Answers7

96

First you need to know a bit about how name resolving works in Ubuntu since Ubuntu 12.04.

Stéphane Graber blogged some information about it last year here. The most important thing to know is that both Ubuntu Server and Ubuntu Desktop use resolvconf to manage the resolv.conf file. That means that you should no longer edit /etc/resolv.conf directly; instead you should configure your network interface configuration utility to provide the right information to resolvconf. For Ubuntu Server the network interface configuration utility is ifup and it is configured by the file /etc/network/interfaces. For Ubuntu Desktop the network interface configuration utility is NetworkManager. This is what you are using.

NetworkManager is configured by means of Network indicator > Edit Connections. However, for network interfaces configured by DHCP it normally isn't necessary to change any settings manually. Normally what happens is that the (remote) DHCP server provides to NetworkManager both an IP address for the local interface and the address of a (remote) DNS nameserver to use. NetworkManager starts an instance of a forwarding nameserver that listens locally at 127.0.1.1. This address, 127.0.1.1, is sent to resolvconf which puts nameserver 127.0.1.1 in /etc/resolv.conf. NetworkManager also gives the (remote) IP address of the DHCP-provided DNS nameserver to the forwarding nameserver. Thus a program running on the local system asks the resolver to translate a host name into an IP address; the resolver queries the local forwarding nameserver at 127.0.1.1; the forwarding nameserver queries the remote nameserver(s) it has been told about, receives an answer and sends it back up the chain.

NetworkManager communicates with the forwarding nameserver process over D-Bus. You can see what NetworkManager told the forwarding nameserver by running the command

nmcli dev list iface eth0 | grep IP4.DNS

Update arising from the comments:
Note that resolvconf actually writes the file /run/resolvconf/resolv.conf to which /etc/resolv.conf is supposed to be a symbolic link. If /etc/resolv.conf is not a symbolic link then you need to recreate it. To do so you can run

sudo dpkg-reconfigure resolvconf

or

sudo ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf        
Zanna
  • 70,465
jdthood
  • 12,467
  • Thank you very much for this info. In my case the command shows the correct DNS servers. But the resolf.conf file is not updated. It has the timestamp from when I have put my values there. So I will have to find out why resolvconf is not writing the file. – Witek Oct 31 '13 at 10:55
  • 16
    Resolvconf actually writes the file /run/resolvconf/resolv.conf and /etc/resolv.conf is supposed to be a symbolic link to /run/resolvconf/resolv.conf. If you deleted /etc/resolv.conf then you deleted the symbolic link. To recreate the symbolic link you can run sudo dpkg-reconfigure resolvconf or you can do mv /etc/resolv.conf /run/resolvconf/resolv.conf && ln -s ../run/resolvconf/resolv.conf /etc/resolv.conf – jdthood Oct 31 '13 at 15:02
  • 13
    This has everything but the 'fix'. How can I resolve this issue? – Amal Murali Jan 18 '14 at 22:19
  • 7
    The fix may be to run sudo dpkg-reconfigure resolvconf as suggested in the last part of the answer. – jdthood Jan 20 '14 at 13:09
  • 2
    Thank you!!! I am not sure what happened to my system but running the sudo dpkg-reconfigure resolveconf seemed to work great! – Steven Combs Nov 22 '14 at 15:29
  • I had this issue on two different machines when upgrading from 12.04 to 14.04. /etc/resolv.conf was missing after the upgrade, which can be fixed as desbribed above (I did sudo dpkg-reconfigure resolvconf). – fuenfundachtzig Apr 24 '16 at 10:19
  • Count on me as one more soul saved. Thank you very much! – Jodevan May 24 '16 at 00:22
  • In others words if like me you removed /etc/resolv.conf and you think that it will be recreated by restarting the NetworkManager service, then you will be out of luck. You have to run dpkg-reconfigure resolvconf or recreate the link. – Rudy Vissers Dec 06 '16 at 14:33
  • 1
    After 5 hours of on again, off again trying, sudo dpkg-reconfigure resolveconf fixed my issue. – Shaun Overton Mar 03 '18 at 17:28
  • None of this helped. Only worked when I restarted NetworkManager – Philip Rego Aug 23 '20 at 04:21
  • Someone help me understand why /etc/resolv.conf needed to be replaced with a software stack. Seriously. I've already wasted hours trying to repair this mess. – converter42 Jun 18 '21 at 22:23
56

I made the change suggested on the link below (disabling dnsmasq). Now everything works great! http://www.ubuntugeek.com/how-to-disable-dnsmasq-in-ubuntu-12-04precise.html

Open /etc/NetworkManager/NetworkManager.conf file.

sudo gedit /etc/NetworkManager/NetworkManager.conf

Comment out line as:

#dnsmasq deactivated
#dns=dnsmasq
Sergio
  • 1,035
  • 7
    After commenting out dnsmasq, you need to restart network manager: sudo restart network-manager. – Don Kirkby Dec 17 '15 at 22:27
  • 2
    In my case (Xubuntu) the command is: sudo /etc/init.d/network-manager restart – aviram83 Apr 26 '16 at 04:37
  • 2
    If you have this happening to you, even though there is no dnsmasq installed, and there is nothing to even comment out, add dns=default to the [main] section. NetworkManager has its own nasty dnsmasq plugin which it will use otherwise. – dstibbe Dec 15 '17 at 23:15
  • 2
    I need to do this restart network-manager - sudo service network-manager restart – Sungam Jan 18 '18 at 21:35
  • One of my box had no dns after upgrade to 17.10 and it turns out the /etc/resolv.conf was not a symbolic link. Fixed it. Another box did not finish upgrading and I found a .dpkg-new file in the dir, diff them the main difference is dnsmasq. Copied it over and worked without restart any daemon – fchen Jan 21 '18 at 21:22
  • For Ubuntu 18.04.2 users, there is no dnsmasq deactivated to comment. I had to comment dns=default in addition to dns=dnsmasq to actually resolve the issue. Don't know why? If somebody knows the reason then please explain. – Zaid Khan Apr 21 '19 at 06:41
  • Then what are you using as your DNS? Cant just disable your DNS without replacing it. – Philip Rego Aug 23 '20 at 03:46
23

EDIT 2: Previous post was rightfully deleted by the moderation, I'm posting what I have found to be a solution. Sorry for that.

EDIT: I just found the answer and it's in this very page - sorry for my miopy. I posted my findings below, expanding the correct answer by Richard Lindstedt found in this page. I left my early rumbling for a bit of context. Please upvote Richard's answer, he deserves it.

It's actually really easy.

just open your interfaces conf file --> sudo vi /etc/network/interfaces

That sure did not help the OP and doesn't help me now. We don't want static addresses, we want to use the ones the DHCP server sends us. NetworkManager seems to recognise them, but Ubuntu bluntly ignores them:

# nmcli dev list iface wlan0 | grep IP4.DNS
IP4.DNS[1]:          10.*.*.*
IP4.DNS[2]:          10.*.*.*
IP4.DNS[3]:          8.8.8.8

But...

# dig microsoft.com
; <<>> DiG 9.9.5-4.3-Ubuntu <<>> microsoft.com
;; global options: cmd
;; connection timed out; no servers could be reached

And my /etc/network/interfaces is:

auto lo
iface lo inet loopback

which is a bit odd, I would expect all interfaces being declared here (or am I missing something?).

So, in short:

  • I did not mess with any file to start with
  • I have already run dpkg-reconfigure resolvconf
  • The right symlink is in place
  • NetworkManager retrieves the correct DNS servers from DHCP
  • Ubuntu DOES NOT use such addresses
  • The workaround is to put fixed 8.8.8.8 on /etc/network/interfaces WHICH I DON'T WANT
  • I want to use the DHCP-provided DNS servers in any and all situations.

Not opening another thread because it's the exact problem except I'm on 14.10 now (but this have been nagging me since de upgrade from 12.10 to 13.04).

SOLUTION

That last phrase got me on the right track, and only then I noticed Richard's answer.

The problem seems to be related to the conflicting dnsmasq and resolvconf packages. Until 12.10, dnsmasq was used. From 13.04 onwards, Ubuntu seemed to switch to a dnsmasq/resolvconf hybrid, where you have installed the packages dnsmasq-base and resolvconf, but not dnsmasq itself.

I can't say if it's a bug in the upgrade scripts for 13.04 or something else, because when upgrading (as in fresh installs) resolvconf is installed, dnsmasq-base is upgraded and dnsmasq is (correctly) uninstalled.

The catch is, the upgrade script fails to comment out the dns=dnsmasq line in /etc/NetworkManager/NetworkManager.conf. So, even though the dnsmasq daemon is not present anymore on the system, /etc/resolv.conf still expects it to be.

Henrique
  • 697
  • 7
  • 15
  • THIS IS SO AWESOME! – metadings Oct 17 '15 at 23:33
  • 1
    OMG this solved my DNS problems I have had for the past 3 years! If you have dnsmasq and dnsmasq-base installed, NM will put 127.0.0.1 in /etc/resolv.conf instead of 127.0.1.1. I simply uninstalled dnsmasq (and enabled NM) and everything works just fine. – user1129682 Oct 19 '15 at 12:11
  • 5
    Future Googlers should note that you have to sudo service network-manager restart for this to take effect. – timelmer Jan 23 '17 at 21:13
  • Good point on service network-manager restart! – Henrique Feb 01 '19 at 21:42
8

It's actually really easy.

just open your interfaces conf file --> sudo vi /etc/network/interfaces

and under your interface (probably eth0) you will see all the usual config.

address 192.168.22.71
netmask 255.255.255.0
gateway 192.168.22.1

After gateway just add 'dns-nameservers 8.8.8.8 8.8.8.9' or whatever nameserver you're going to use.

So your config should be:

address 192.168.22.71
netmask 255.255.255.0
gateway 192.168.22.1
dns-nameservers 8.8.8.8 8.8.8.9

then just do a 'sudo service networking restart' and you're good to go!

sprut
  • 97
  • 1
  • 2
2

I'm using Pop!OS, but I think my solution could be applicable to Ubuntu users as well. For me 2 issues were involved.

First, systemd-resolved was not configured to use mdns. So this should be enabled by editing /etc/systemd/resolved.conf and enabling option MulticastDNS=yes

after that change systemd-resolved must be restarted.

systemctl restart systemd-resolved.service

Then check if configuration was updated by systemd-resolve --status

It should have

Global
       LLMNR setting: no
MulticastDNS setting: yes

but if you check the particular interface, it will have multicast disabled.

      Current Scopes: none
DefaultRoute setting: no
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: no

The problem is that enabling MulticastDNS cannot be done from (at least mine) UI network interface configurator, so you have to do nmcli command line config.

nmcli connection edit enp4s0

you are interested in property connection.mdns you could get more info on that by

describe connection.mdns   

so set connection.mdns reslove (or what ever you prefer)

then save persistent quit now mdns should be operational

Pablo Bianchi
  • 15,657
madabrowski
  • 191
  • 1
  • 2
1

This issue can be related to systemd-resolve does not forward DNS requests to stated DNS server

Newer systemd-resolved refuses to resolve simple names via DNS, i.e. myhost and will only resolve myhost.somedomain.com via DNS.

This change is by design. Bypass/remove systemd-resolved if you use simple hostnames.

Create a working /etc/resolv.conf and chattr +i /etc/resolv.conf so that systemd tools don't mess with it, optionally remove systemd-resolved with apt.

The reason is that systemd-resolved presumes your intranet's DNS server is on the Internet, and provides no mechanism to indicate that it is not.

teknopaul
  • 2,027
  • 16
  • 18
  • I have this problem with a recent install of Ubuntu 23.10. One work-around to the issue with "simple host names" that seems legit to me is to provide the ".local" (pseudo?) domain name - so whereas "ping pi3b" didn't work for me on my intranet, now "ping pi3b.local" does. – Rob Cranfill Oct 20 '23 at 22:15
1

Run:

sudo systemd-resolve --flush-caches
Eliah Kagan
  • 117,780