I have a CentOS system that retrieves its upstream DNS servers via DHCP.

I want to run DNSMasq on this box and use it as a server to resolve some hostnames for development.

The problem is when my system starts, the upstream DNS servers are loaded into /etc/resolv.conf and THEN the DNS1 entry from my ifcfg-enp0s3 setup gets loaded. That's a problem because when I query for the internal dev names, it tries to go out to the upstream DNS server instead of checking DNSMasq first. I need the DNSMasq server to be at the TOP of the /etc/resolv.conf and the dhcp loaded ones at the bottom of the resolv.conf so that DNSMasq will work properly.

Any simple way to do that?

  • Yes, this does appear to be the same problem, but it was not resolved in that question. I am close to figuring it out. Should I kill this question (not sure how) and post the response over there or just leave a detailed solution here once I figure it out? – alfreema Aug 13 '17 at 22:28
  • Okay, once I figure it out (I am stuck at one point), I will post the solution and then we can figure out whether to collapse them or make a link in that one to this one. – alfreema Aug 14 '17 at 1:54

Yes, there is a simple way to do that. Add line to /etc/dhcp/dhclient.conf, example below, prepends DNS server to the resolver list.

prepend domain-name-servers ;

The prepend statement

prepend [ option declaration ] ;

If for some set of options the client should use a value you supply, and then use the values supplied by the server, if any, these values can be defined in the prepend statement. The prepend statement can only be used for options which allow more than one value to be given. This restriction is not enforced - if you ignore it, the behaviour will be unpredictable.

See dhclient man page

  • I don't have an /etc/dhcp/dhclient.conf. I do have: /etc/dhcp/dhclient.d/ folder and in it is a chrony.sh file. Should I just create it? – alfreema Aug 13 '17 at 21:58
  • To get some insight, I ran ps awx | grep dhcli and it came back with this: [root@localhost dhcp]# ps awx | grep dhcli 967 ? S 0:00 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-enp0s3.pid -lf /var/lib/NetworkManager/dhclient-9a03d168-3a40-4319-b33b-7bdd74811fd6-enp0s3.lease -cf /var/lib/NetworkManager/dhclient-enp0s3.conf enp0s3 – alfreema Aug 13 '17 at 22:05
  • 1
    Ah looks like here: /var/lib/NetworkManager/dhclient-enp0s3.conf – alfreema Aug 13 '17 at 22:06
  • 1
    Steve, you had the correct answer with one tweak: Please modify your answer to include the ; after the example prepend statement -- that missing ; gave me fits. :) – alfreema Aug 14 '17 at 18:08
  • 1
    Apologies, done. – steve Aug 14 '17 at 18:12

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