Host IPv4 address when Pi-hole is DHCP server

I'm a bit confused about setting the Pi's IP as static when using its DHCP server. Should we make a reservation in PiHole's DHCP table? Or should we configure the network of the Pi to use a static IP, not DHCP (in netplan config, if using Ubuntu).

I went the first route. I have disabled DHCP on my router, and enabled the one in PiHole. Seems to be working for the other clients. My Pi had already had an IP that it got before disabling the router's DHCP (192.x.x.116). So in the PiHole DHCP address reservation, I've set the same IP (192.x.x.116) to the MAC of the Raspberry.
But I'm just realising that by default PiHole's DHCP range is 192.x.x.201 to 192.x.x.251. So my ...116 is outside this range. Can it be reserved ? Should I go the manual route of netplan config?


Solved:

A DHCP server must be configured with static IP for its interfaces. A DHCP server cannot serve itself, but only other machines on the network. This is valid for any DHCP server in the world.

from StackOverflow.

So I have setup a static IP in /etc/netplan/50-cloud-init.yaml of the PI. I have also added there the nameservers to use, which I suppose will override the pihole config. I have to dig deeper into this but for now it's not too important

Yes.
A DHCP server may hand out IPv4 addresses from its DHCP range or -for specific identifiable clients- from its DHCP lease reservations .


Technically, nothing prevents a DHCP server to run on a system that acquires its IPv4 address via DHCP.

Your router would be a prime example for that: It acquires its public IPv4 from one of your ISP's DHCP servers while acting as a DHCP server for your private network at the same time (however, note that this is a slightly different use case, as multiple network interfaces and networks are involved).

It would depend whether that would work in a given configuration (click for details)

A machine will broadcast for a DHCP server to acquire an IPv4 address, and a DHCP server has to provide its own source IP address.

If Pi-hole is the only DHCP server on the link, it may not been up yet during that initial broadcast. Without a reply, the machine would assign itself a link-local IPv4 address (range 169.254.0.0/16).
It would then depend on both the DHCP server as well as the DHCP client software whether a broadcast would be repeated at a later time and whether that would work when only a link-local IPv4 address is available.

If another DHCP server would be active on the same link, the DHCP client on Pi-hole's host could acquire its IPv4 by a DHCP lease through that other DHCP server.
This may be an option, e.g. if you cannot switch off your DHCP server on your router: Limit your router's DHCP range to just accomodate your Pi-hole host machine's IP(s), and configure your router's DHCP for fixed IP addresses / DHCP lease reservations for Pi-hole.
If you do not limit your router's DHCP range and don't configure DHCP lease reservations, your Pi-hole host machine may pick up different random IP addresses during reboot.

By setting a static IP address on-device, you would avoid all of the above potential issues.

The one disadvantage of setting a static IP on-device would only occur if you'd change your router:
If your new router configures a different subnet (e.g. 192.168.1.0/24 vs. 192.168.178.0/24), you wouldn't be able to access your Pi-hole host anymore.
For headless Pi-hole systems, this would also mean you may not be able to reconfigure it for the new network once the new router is active. You'd either had to do so before installing the new router, or you'd have to configure your new router for the existing subnet. Note that not all routers may allow you to do so.


That said, setting a static IP on-device would be the preferred approach.

Thank you, @Bucking_Horn ! That's very clear!

Thanks for the headsup regarding the static IP when changing the router ! Will keep in mind. Luckily my RPi is still in my house, so not 100% headless - can always hookup monitor & keyboard.

This clears it all for me, I've set it up as static and now with a clear mind that I know what's going on.

I just have an additional curiosity, if that's ok with you to share:

Supposing we had to go the route with 1 address in the router's DHCP, that's reserved to the RPi. Can a different device snatch this IP if the RPi is not online at the time? If so, would the RPi knock it off once it comes online?

Thanks for sharing !

No, not if the router has indeed been configured with a DHCP lease reservation for the Pi-hole host machine.

DHCP lease reservations may be labeled as fixed or static IP address assignments in your router, or anything similar expressing that a specific network client (as usually identified by a specific network adpater's MAC) will always receive the same specific IP address.

1 Like

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