0

There are many (IMHO, too many) places to configure the DNS server(s) used and I am not sure about the relationship between them. A few questions are: Which configurations are only queried conditionally (For example, if I understand correctly, the systemd configuration is not queried if the corresponding service is not running)? Which configurations override which? What is the recommended way to configure DNS?

To name a few places to configure the DNS server(along with some other information I know about them, which should kindly be corrected if there is any misunderstanding),

  1. Write in /etc/resolv.conf and use chattr to force it to remain persistent after reboot (I think this one is discouraged)
  2. resolvconf. Config in the various files in /etc/resolvconf/resolv.conf.d. Use resolvconf -a to add a DNS and resolvconf -u to update it
  3. systemd-resolve(d), a unit of systemd. Config in /etc/systemd/resolvd.conf. It uses the address 127.0.0.53 as the dummy DNS solver in /etc/resolv.conf. The real resolv.conf is found in /var/run/systemd/resolve/resolv.conf. In newer versions (since which version?), systemd-resolve --status can be used to query the current DNS status.
  4. /etc/network/interfaces. This one is related to /etc/systemd/system/network-online.target.wants/networking.service
  5. Network-Manager, a component that drives the network configuration context menu in GUI. If an interface is configured in /etc/network/interfaces, it will refuse to manage it again (shown as not managed in the GUI context menu).

I am running Ubuntu 18.04 LTS with Unity desktop environment.

  • I would probably broke down the question, and investigate (and ask) it into smaller bits to make the whole picture. Too many questions asked here. – Rui F Ribeiro Jun 8 '18 at 7:32
  • 1
    It all depend on what you want to do ... – Kiwy Jun 8 '18 at 7:33
  • @RuiFRibeiro I believe I am most interested in "Which one overrides which". – Weijun Zhou Jun 8 '18 at 7:49
  • Ultimately your answer is in grep '^hosts:' /etc/nsswitch.conf. Whatever this says is where your DNS comes from. – Patrick Jun 8 '18 at 12:47
  • 1
    They did not appear all overnight, you have to take into account history: from ancient times unix systems used /etc/resolv.conf then (not necessarily strictly in this order), resolvconf was created to allow easily to change the DNS when you change the network, graphical interfaces like Network Manager appeared to help people that prefer GUI over CLI, and then systemd appeared with later its systemd-resolve process. – Patrick Mevzek Jun 10 '18 at 23:25
1

What is the recommended way to configure DNS?

...

I am running Ubuntu 18.04 LTS with Unity desktop environment.

Where possible, it would be recommended for you to use this one:

5. Network-Manager, a component that drives the network configuration context menu in GUI.

For example, this is what the official Ubuntu Desktop Guide says. I have not verified this is up to date, but I have no reason to doubt it.

https://help.ubuntu.com/lts/ubuntu-help/net-manual.html.en

If your network doesn’t automatically assign network settings to your computer, you may have to manually enter the settings yourself. This topic assumes that you already know the correct settings to use. If not, you may need to ask your network administrator or look at the settings of your router or network switch.

To manually set your network settings:

...

7. In the DNS section ...


On most systems, the only place the system will look is the contents of /etc/resolv.conf. (But there may be various different systems which edit the contents of this file).

As pointed out by Patrick, on some systems there will be a higher-priority plugin seen in grep '^hosts:' /etc/nsswitch.conf. dns is the standard glibc plugin which reads /etc/resolv.conf.

In particular, if you have resolve before dns, this refers to systemd-resolved. It will try to access systemd-resolved before using the DNS server in /etc/resolv.conf.

As you point out, it's possible to look at the DNS servers, if any, which systemd-resolved might query, by running systemd-resolve --status.

As you point out, the NetworkManager method is not expected to be compatible with manual edits to /etc/resolv.conf (as NetworkManager will edit this file itself). Of course if you block NetworkManager from editing /etc/resolv.conf, the NetworkManager method will not work.

  • Thank you for your detailed information. What is the position of /etc/network/interfaces among the others? Another thing is that, while I know that /etc/resolv.conf is the only place the system will look up in most cases, it is not an deal place to do configuration because it is often overwritten by other configuration components. – Weijun Zhou Jun 11 '18 at 6:23
  • @WeijunZhou More generally, it is recommended you only use one configuration method to set DNS servers (with manual editing being one method), so you don't have to worry about conflicts per se. resolvconf was used to provide an intermediary configuration system that accepted information from multiple configuration systems e.g. DHCP client, VPN software, and PPP (for modems). But if you use NetworkManager, that effectively does the same thing. Nowadays, if you have to fiddle with resolvconf, it suggests you're doing something weird and obscure. – sourcejedi Jun 11 '18 at 8:26
  • /etc/network/interfaces and resolvconf are not systemd-resolve, do not have their own NSS module for nsswitch. Therefore they edit resolv.conf. /etc/network/interfaces (ifupdown) is one of the configuration systems that resolvconf knows how to intercept automatically when you install resolvconf. – sourcejedi Jun 11 '18 at 8:27
  • Thank you very much for your further explanation. That makes it clearer. – Weijun Zhou Jun 12 '18 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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