16

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?
  • to add fixed entries to resolv.conf, always or as a fallback when there's no DHCP-lease-obtained nameserver?
  • to make decisions about relative order in the file?

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

3
  • 5
    I uninstall resolvconf in servers...unix.stackexchange.com/questions/286195/… Mar 9 '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 7: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 7:48
3

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.

3
  • 1
    +1, but this only explains how to do part of what I asked about.
    – einpoklum
    Jun 12 '18 at 7:32
  • But my /etc/resolvconf/resolv.conf.d/head file also contains "DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN"
    – ospider
    Nov 16 '20 at 5:55
  • base in the resolv eco system means put it between head and tail?
    – Timo
    May 19 at 7:47
0

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 .

5
  • 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 . 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 . Aug 14 '17 at 6: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. Aug 17 '20 at 11:16

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.