DEV Community

Leon Nunes
Leon Nunes

Posted on

Setting up Pi-hole to provide DHCP service

I recently setup my raspberry pi as a pi-hole server, however, before this I used to use it as a DNS and DHCP server using dnsmasq, luckily Pi-hole comes with its own fork of dnsmasq which made this process super easy.

Let's get to it.

Firstly, I use archlinux arm so you would need to consult the documentation to install pihole.

If you use Archlinux then follow the steps here
The official documentation is here

Once you have your Pi-hole and your web administration server running you can now begin setting up your DHCP and DNS server, I have used the default Pi-hole blocklists you can choose to use additional ones.

Once you complete your installation open your Web Admin interface for Pi-hole.
Go to Settings => DHCP
alt text

Once you have the DHCP server enabled pi-hole will add its custom configuration to /etc/dnsmasq.d/
Make sure you have conf-dir=/etc/dnsmasq.d/,*.conf
commented out in /etc/dnsmasq.conf

~$ ls /etc/dnsmasq.d/
01-pihole.conf  02-pihole-dhcp.conf  03-pihole-custom.conf
Enter fullscreen mode Exit fullscreen mode

Once you have your dhcp server enabled you can add additional commands by creating a file like

/etc/dnsmasq.d/03-custom.conf

Make sure you restart dnsmasq using

~]$ sudo systemctl restart dnsmasq.service
Enter fullscreen mode Exit fullscreen mode

or

~]$ pihole restartdns
Enter fullscreen mode Exit fullscreen mode

This is how my custom file looks like, since I want to push my raspberry-pi IP's as DNS servers to my clients.

~$ cat /etc/dnsmasq.d/03-pihole-custom.conf 
dhcp-option=option:dns-server,192.168.31.2,192.168.31.3
dhcp-host=medusa-arch.demodomain,192.168.31.4,36h

Enter fullscreen mode Exit fullscreen mode

You can add static hosts using the dhcp-host option like I did above and all the things that dnsmasq supports.

This helps in resolving local domains for example, or to resolve IP addresses to hostnames.

~]$ dig +short a medusa-arch
192.168.31.4

~]$ dig +short -x 192.168.31.4
medusa-arch.demodomain.
Enter fullscreen mode Exit fullscreen mode

Pi-hole basically does most of the heavy lifting using dnsmasq.

I hope this helps, I would be writing up a detailed post on how to install Pihole later.

Thank you for reading.

Top comments (4)

Collapse
 
brandonwallace profile image
brandon_wallace

You might as well add NTP (Network Time Protocol) to the server. It will go along nicely with the other services.

Collapse
 
mediocredevops profile image
Leon Nunes

Hey thanks for your suggestion, just had a small follow up question, I'm sort of new to the whole sysadmin thing, do people often use a NTP server to perform some task?

Collapse
 
brandonwallace profile image
brandon_wallace

An NTP server is used to provide accurate time to all the devices on the network. It is very easy to set up. You can use the ntp or chrony package. There are public NTP server available on the internet just like public DNS servers. Use the NTP servers closest to you.

Thread Thread
 
mediocredevops profile image
Leon Nunes

Thanks I'll set it up with this.