2

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?

2
  • 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
    Commented Aug 13, 2017 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
    Commented Aug 14, 2017 at 1:54

1 Answer 1

5

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

prepend domain-name-servers 1.2.3.4 ;

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

5
  • 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
    Commented Aug 13, 2017 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
    Commented Aug 13, 2017 at 22:05
  • 1
    Ah looks like here: /var/lib/NetworkManager/dhclient-enp0s3.conf
    – alfreema
    Commented Aug 13, 2017 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
    Commented Aug 14, 2017 at 18:08
  • 1
    Apologies, done.
    – steve
    Commented Aug 14, 2017 at 18:12

Not the answer you're looking for? Browse other questions tagged .