This is a very popular question, with a collection of standard possible answers, all of which, IMO, are pretty hacky. I for one have always had problems getting Ubuntu to respect the DNS settings I set up in NetworkManager -- in particular setting static DNS servers with "Automatic (DHCP) addresses only" -- and today I finally figured out what was ACTUALLY WRONG.
The problem is in the interaction between resolvconf and NetworkManager. resolvconf has this file called
/etc/resolvconf/interface-order. At least on my systems, NetworkManager isn't in this file at all (except that it's covered by the * wild card at the end). So what happens is, dhclient's most recent report to resolvconf takes precedence over anything NetworkManager has to say.
Thus, at least in my case, the actual answer was to add
at or near the top of
(Yes, I know many people just say "uninstall resolvconf", which seems like a bad idea in and of itself, to me. But more than that, at least wily and xenial consider resolvconf a vital part of the system [i.e., ubuntu-minimal depends on it], so it would be difficult to keep your system in a consistent, updated state without resolvconf.)
Upon request I can provide more detail about how I figured this out. (EDIT: apparently I didn't do so when it was requested, sorry. At this point I don't remember much more detail than what I say next:) In a nutshell, I replaced the resolvconf executable with a shell wrapper around it which dumped its arguments, input, output and stderr to files; and added set -x to resolvconf's update scripts.
(EDIT: I can say that what I mean by the first part is that I used sudo to move the actual resolvconf executable, which could be found using the which command or the type command. Then create a shell script that ultimately just executes the moved resolvconf, but also echos the arguments to some file, and uses shell redirection to send stdin, stdout, and stderr to various other files. I don't recall where "resolvconf's update scripts" are and can't currently easily check. I think many Linux geeks can figure out what I mean; perhaps some good samaritan will provide even more detail in a comment.)