DHCP allows configuration of IP range with "descending" IPs

Please follow the below template, it will help us to help you!

Expected Behaviour:

DHCP config should not accept that "From" configuration is a higher IP address than the "To" IP address (descending), but only "ascending".

Actual Behaviour:

Hi there,
this is more a FYI for the developers, not sure you want DHCP config allow it the way below:
Just enabled the Pi-Hole DHCP server, with following settings:
From 192.168.2.101
To 192.168.2.51
Router (gateway) IP address
Router 192.168.2.1

Now, I renewed the IP on my client and got a
192.168.2.93
back!

So, I thought this is wrong (because my "from" address starts at .100), but when I checked the config I noticed that my "To" address was .51, so the range was configured incorrectly
192.168.2.101-192.168.2.51

Pi-hole Version v4.0 Web Interface Version v4.0 FTL Version v4.0

Debug Token:

not required.

@DL6ER does dnsmasq care about the order of to and from? I didn't see any mention of that in the man page.

I don't really see the issue so far.

is in between 192.168.2.101 and 192.168.2.51 (regardless if you look forward or backward in this interval).

Note that the DHCP server does not hand out the IP address sequentially. Instead, it calculates a hash value from the device's MAC address and assigns an IP address from this. The effect is that the order in which your connecting devices to your network does not matter, for example your Android phone will always get this 93 address regardless how many devices are already connected and in which order they got connected. I think this is, in general, a good approach to ensure some pseudo-static IP behavior.

This can be disabled to have addresses being handed out sequentially if this is desired (you will have to manually set a line, but we will assist you with it is necessary). Note that the pseudo-static IP system does obviously only work if you connect much less devices that there are available IP addresses (e.g., 30 devices for 50 addresses may already be a bit tight).

There is a mechanism in option.c that detects if the start IP is larger than the end IP. If this is the case, they are swapped internally to fix the range:

if (ntohl(new->start.s_addr) > ntohl(new->end.s_addr))
{
	struct in_addr tmp = new->start;
	new->start = new->end;
	new->end = tmp;
}

No warning is printed when they are swapped.

4 Likes

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