Newb Q: How to pull DNSMASQ config into Pi Hole for DHCP reservations

Trying to confirm how to "import" my DNSMASQ.CONF entries, used for DNS and DHCP, into Pi-Hole.

Today I installed Pi-Hole on a Ubuntu 18.04 server. My plan is to transition to Pi-hole for DNS and, eventually, DHCP. I was running BIND and DHCPD on Ubuntu 16.04. Prior to learning about Pi-Hole, I was planning to move to DNSMASQ so I had prepared a DNSMASQ.CONF file (but never used it in the heat of battle).

I have Pi-Hole running and serving DNS. I have edited the DHCPD.CONF file on the "old" server that is still serving DHCP to point clients to DNS on the Pi-Hole server. This all seems to be working fine. I can see the activity in the web interface.

My question is: when I am ready to start using Pi-Hole as my DHCP server, what do I need to so that Pi-Hole will "pick-up" my DNSMASQ configuration? I use a large number of IP address reservations (all configured in that DNSMASQ.CONF file) and I do not want to re-enter them.

From what I have read here, I believe I can place my old DNSMASQ.CONF file in the /etc/dnsmasq.d/ directory but I am unclear on whether there is a specific file naming protocol and how the make the system ingest this file. I get the feeling it must be something simple . . . do I just restart? Or will it be ingested when I enable DHCP? I don't want to mess this up.

Thank you!

Welcome to the Pi-hole community, @ECM56.

Pi-hole is running a tailored version of dnsmasq FTL DNS ( pihole-FTL ), but configuration is very much the same as with the plain vanilla version. As such, its configuration options are identical to dnsmasq's options.

There are a few caveats, however (click for details)

Since Pi-hole is also configuring the dnsmasq part at its own discretion, you have to make sure your settings won't collide with Pi-hole. Pi-hole's own settings will likely overrule yours, but they may lead to unexpected behavious as well.

Pi-hole is striving to make installation and maintenance as easy as possible for standard home users who can be only mildly computer literate.
As such, Pi-hole assumes that you are running a single subnet for your home network.
If your intended network setup comprises several subnets, you could cater for them as usual, in all ways dnsmasq (and your gateway/router/switch, of course) allows, but don't expect these settings to be supported or even reflected fully in Pi-hole's UI.

Some valid dnsmasq configuration settings may even compromise the UI in ways that'll force you to stick with editing the dnsmasq files manually, forfeiting the use of Pi-holes admin panel for lease configuration.

For that reason, I would recommend using your router's DHCP server instead of Pi-hole's for more complex network setups.

Also, while Pi-hole is using the very same configuration files as dnsmasq, the binary has changed. This means you won't be able to run dnsmasq commands or to use all of dnsmasq options on Pi-hole's replacement binary.

And finally, you should be aware that Pi-hole may alter its configuration files, e.g. based on user interaction via UI, command line (i.e. during a pihole -r reconfiguration) or updating (i.e. pihole -up).


Now that you've been properly cautioned:
As you assumed, Pi-hole's dnsmasq configuration is located in a bunch of files in /etc/dnsmasq.d/
Read more at What files does Pi-hole use? (which covers not only dnsmasq files).

Before trying to import or rather reuse your static leases:
Please make sure that DHCP is disabled on Pi-hole.

A. Prepare a static lease conf

First, you'd have to separate your static IP address assignments from the rest of your legacy dnsmasq configuration into a separate file.

You could then copy that file into Pi-hole's standard static lease file name (note that normally custom configurations should go into custom files, but here we are trying to reuse an existing config):
/etc/dnsmasq.d/04-pihole-static-dhcp.conf

You can check whether your dnsmasq configuration is syntactically correct by running

 pihole-FTL dnsmasq-test

Sort out errrors until this results in syntax check OK.


B. Check Pi-hole's UI for possible misalignments

On a client machine, open a browser and go to Pi-hole's DHCP panel under Settings | DHCP.

Even though DHCP is disabled, Pi-hole will populate the Static DHCP leases configuration section in the lower half of the screen from its 04-pihole-static-dhcp.conf.

Check that the lines there make sense, i.e. an entry should match its heading. If things are mixed up, your configuration contains extra parameters that are not handled by Pi-hole's UI.


C. Enable DHCP

If everything in B. looks ok, you are almost done.

On Pi-hole's DHCP panel, configure and enable DHCP and press Save to restart Pi-Hole as your DHCP server with your existing static leases.


However, if you encounter misalignments in step B, you have two choices:

1. Recommended: Edit `04-pihole-static-dhcp.conf` to get rid of your extra settings.

Make your lines conform to
dhcp-host=MA:CA:DD:RE:SS,192.168.1.100,laptop
where you replace MAC, IP and name with your correct settings, of course.

This will allow you to edit static leases via Pi-holes DHCP panel further on.

When finished editing, resume with step B.


2. If you are desperate for your extra settings, you can try and keep them.

BUT: You should refrain from using Pi-hole's DHCP panel UI in the future, and take extra precaution when enabling or disabling DHCP.

Before starting DHCP, you have to move 04-pihole-static-dhcp.conf to another location, e.g. your home directory. Otherwise, if you'd enable DHCP and Save those settings, your static lease file may get corrupted.
So move it out of the way, then configure DHCP, enable it and press Save.
Copy 04-pihole-static-dhcp.conf back into /etc/dnsmasq.d/, but this time, use a different name like 04-static-lease-migration.conf and restart Pi-hole's DNS:

sudo pihole restartdns

Verify with:

sudo pihole status

If this doesn't show you the green lights, you have introduced conflicts in dnsmasq's configuration that you have to deal with.
If everything else fails, move or delete 04-static-lease-migration.conf and restart Pi-hole.

In that case, rethink if you really need those extra options or whether your router would be better equipped to handle your DCHP configuration.


2 Likes

OK, thank you!

I have a flat, single subnet network. My primary concern is being able to maintain the reserved IP addresses. I understand I can put them in 04-pihole-static-dhcp.conf. Does that file use the same format as dnsmasq.conf for reserved IP address assignment?

i.e.,
#Always give the host with Ethernet address 11:22:33:44:55:66
#the name fred and IP address 192.168.0.60 and lease time 45 minutes
#dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m

Edit: I think you confirmed this - I didn't see how some of the links in your message were working.

Oh, I see a couple of additional question:

I have cnames in that file for some of the hosts, can those stay in that file or will they need to go somewhere else?

I notice the order of the IP address and name are different in the example you provided. I think the example I quoted (above) was from the dnsmasq.conf file that is part of that package . . . does that sequence matter or is it smart enough to figure it out?

Thanks again!

Yes, as pihole-FTL is dnsmasq with a few extra tweaks - I have addded a link to dnsmasq's man pages to my above post.

And yes, you can always click the black triangle lines in a Pi-hole forum post as this one right here...

...for more details :wink:


Any valid dnsmasq configuration can be applied to Pi-hole as long as you take the above caveats into consideration. You'll have to try how well Pi-hole's DHCP UI will agree with your specific options.

Refer to the dsnmasq documentation as linked in my post above.
In addition, the dnsmasq-test from step A above will tell you whether your configuration is syntactically correct.

It is sensitive to that sequence in the conf file. When I used my file with the sequence shown in the dnsmasq.conf sample file (#dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m) the syntax checker reported OK but when I looked in the UI, the IP address and hostnames were backwards (hostname in the ip address column and ip address in the host name column).

Good call to use the syntax checker but also check the UI.

After further reading I found the syntax for a dhcp-host entry is documented differently in different locations - when shown as an "option" (for example, at: Man page of DNSMASQ) the IP address goes before the hostname. The example file (for example, at: dnsmasq/dnsmasq.conf.example at master · imp/dnsmasq · GitHub) shows the hostname going before the IP address. This is what was confusing me.

Thank you!

If you read that man page carefully, you'll notice that while the dhcp-host option's parameters are listed in a certain order (most of them optional), the examples that follow do not strictly rely on that order, and indeed give a host name before an IP address (e.g. "(..) dhcp-host=lap,192.168.0.199 tells dnsmasq to always allocate the machine lap (..)").

I agree that's a bit confusing.

That's why I included syntax checking in step A followed by UI verification in step B in my initial answer :wink:

The main thing to understand here is:
Pi-hole will work with a valid dnsmasq configuration.

It just may not display that configuration's equivalent very well in its UI, as that is made for a simple, straight-forward use case - and initating a Save from a misaligned UI may produce unintended results.

I cannot possibly know the result for any chosen combination of options.
As an advanced user, you have to try out yourself, with the specific options that suit your needs.
The few steps I provided in my initial post will allow you to do so in a controlled manner, but the decision whether you use Pi-hole's UI or pihole-FTL's (aka dnsmasq's) configuration files or a different DHCP server altogether is yours in the end.

I copied all my dhcp-host and cname lines from my dnsmasq.conf file to '04-pihole-static-dhcp.conf'.

As part of this process, I corrected the sequence so that the IP address appeared before the hostname as shown here: Man page of DNSMASQ.

I copied all my DHCP (dnsmasq) options to a file that I named '03-pihole-dnsmasq-options.conf'.

Per your recommendation, I performed a "sudo pihole restartdns" and then a "sudo pihole status". That gave me a red mark. I guessed it was one of my options but to make sure, I deleted '03-pihole-dnsmasq-options.conf' from dnsmasq.d and retried "sudo pihole restartdns" and then "sudo pihole status". This time it reported that it was working.

I copied '03-pihole-dnsmasq-options.conf' back into dnsmasq.d and commented out all the option lines except a couple that I thought were totally innocuous. Three or four cycles of uncommenting the options, retrying "sudo pihole restartdns" and then "sudo pihole status" and I had isolated the one offending option line - it was the dhcp-range option which I use to make the entire range static [dhcp-range=192.168.1.0,static].

I now have the dhcp-range commented out and when I restart DNS everything seems to be working fine. I see there is a spot on the UI to establish the range but I don't know where that setting it stored and, more importantly, whether it will accept the static keyword. The idea, and the way I ran it with dhcpd on my old Ubuntu server, is that I only allowed static entries. I would like to do that again with pihole if possible.

And, again, many thanks for the assistance!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.