23

I the old days, resolv.conf was static and you edited it yourself.

Later on, the DHCP client would rewrite it, using some static entries and what it got from the DHCP lease.

These days, some distributions - like mine (Linux Mint 18.1) have a /etc/resolv.conf.d mechanism with several subdirectories of scripts, and, well, I can't make heads and tails of it.

What's the right way, then, to...

  • indicate that I want to use or not-use the DNS server(s) obtained in the DHCP lease?
  • add fixed entries to resolv.conf, always or as a fallback when there's no DHCP-lease-obtained nameserver?
  • make decisions about relative order in the file?

I don't mind writing some scripts of my own if I have to, I just don't want to "work against" the existing mechanism or do duplicate work.

einpoklum
  • 9,515
  • 5
    I uninstall resolvconf in servers...http://unix.stackexchange.com/questions/286195/how-do-i-figure-out-where-wrong-local-dns-results-are-coming-from – Rui F Ribeiro Mar 09 '17 at 21:01
  • You can also configure dhclient to ignore/replace DHCP DNS info; I'm not sure there's a mechanism in /etc/resolv.conf.d to do this (but I don't use Mint, and don't have those scripts). – dirkt Mar 10 '17 at 07:43
  • @dirkt: Actually, at the moment, the only entry that goes into my /etc/resolv.conf is the localhost (which runs dnsmasq), so it's not clear to me how dnsmasq, the resolv.conf.d mechanism and the DHCP client interact. – einpoklum Mar 10 '17 at 07:48

2 Answers2

10

The answer is simple, The resolv.conf.d folder exists in /etc/resolvconf/ and contains head/base/original and tail files. each of them if edited will update the resolv.conf file in /etc/

lets say you want to put some static DNS address at the beginning of resolv.conf in /etc/ (because on every reboot it auto resets to its default settings) you need to edit the head file in /etc/resolvconf/resolv.conf.d/ and type in for example:

nameserver 1.1.1.1
nameserver 1.0.0.1

after that restart the resolvconf service using:

sudo service resolvconf restart

now cat resolv.conf in /etc/ and you'll see the new changes.

same thing applies if you want to put stuff at the bottom of the file, you use tail instead of head in /etc/resolvconf/resolv.conf.d/

P.S: this is 100% tested and working Ubuntu and Debian

Edit: I already answered the last two bullets of your question, now concerning the first bullet which talks about how not to use the DNS address provided by DHCP. It really depends on which DNS software/package you have installed, thus I recommend you to check this Post, and make sure you read the one below it as well in-case you have dnsmasq.

ospider
  • 113
Viktova
  • 285
2

resolve.conf and some mechanism like these are exists from past years till now . There is command line dhclient , resolvconf which handle this file , However in recent year Linux introduce new interface for configuration NetworkManager by the name of nmcli . This is rich command to manage every persistent network configuration ( not run time ) . you can use some thing like :

$ nmcli connection modify eth0 ipv4.dns 8.8.8.8

This command will be overwrite resolv.conf file . In RHCA it's recommend won't edit resolv.conf by the hand and use its commands . About resolvconf directory you have mentioned , I can say that there can be some services have their own conf for DNS so they use it their own conf like OpenVpn . You can check /etc/nsswitch file also for getting more information about resolving .

xhienne
  • 17,793
  • 2
  • 53
  • 69
  • I don't believe this actually answers my question. – einpoklum Aug 13 '17 at 20:06
  • Well maybe this is my miss understood about your question but nsswitch file is one your answer . – Ali Ghasempour Aug 13 '17 at 20:09
  • I believe @einpoklum wants to have control on the order of the DNS servers in resolv.conf (see man resolv.conf), not on the order of the means used for resolving (man nsswitch.conf). But your answer is interesting nonetheless. – xhienne Aug 13 '17 at 22:11
  • Thank you for your interest . As far as I know resolv.conf is sequential file and its resolve priority is from up to down . – Ali Ghasempour Aug 14 '17 at 06:25
  • @AliGhasempour you got that correct. but with the design-challenged interactions of now 5-6 different tools it is very very hard to maintain a technically correct order of resolv.conf. uninstalling / disabling all the tools of course works but still puts you at risk if some software reenables them. – Florian Heigl Aug 17 '20 at 11:16