[Dnsmasq-discuss] Safe to use static DHCP allocations within dynamic range?

Carlos Carvalho carlos at fisica.ufpr.br
Sat Oct 17 02:21:33 BST 2015


Ed W (lists at wildgooses.com) wrote on Thu, Oct 15, 2015 at 08:39:18AM BRT:
> Hi, I'm not quite clear from the manual pages, so can I please get a
> definitive answer:
> 
> - Am I safe to use to assign a static IP allocation using --dhcp-host
> options, *within* an IP range allocated using --dhcp-range ?
> 
> Specifically, whilst I realise that dnsmasq will first ping to see if an IP
> is unused:
> - Will there be a hard mask on the IP being handed out dynamically as a
> result of the --dhcp-host option?
> - ie if the static allocated device is missing from the network for some
> long period of time, am I "safe" from having a dynamic device "pinch" my
> static IP?

Good question; this is not written in the manual. I think it should be
explicitly stated there.

>From my reading of the source the answer is yes. The response to the client is
built by the function dhcp_reply() in file rfc2131.c. We see that all possible
answers to DHCPDISCOVER and DHCPREQUEST check for !config_find_by_address().
This function, in file dhcp.c, checks if the address has been manually
configured by dhcp-host, as seen in options.c. Note that a dhcp-host
declaration can have a lease time but config_find_by_address() doesn't
take time into account, so static declarations are never given dynamically.

I didn't check the IPv6 case but the strategy will surely be the same.

> Corner case:
> - What happens if there is currently a lease allocated to IP w.x.y.z, and I
> setup a static --dhcp-host allocation for that IP and a *different* mac, ie
> this lease needs to be booted off.

You cannot, this is illegal. If you give a lease to a client you have to abide
by your promise. The correct procedure is to make the client deconfigure the
interface (as is done in a proper reboot or shutdown). It'll then send a
message to the dhcp server releasing the address. From this moment the lease no
longer exists, and you can reconfigure the dhcp server with the static
declaration. If the client comes back and requests the address the server will
deny it. The client will then start the procedure from the beginning
(dhcpdiscover) and will receive an available address.



More information about the Dnsmasq-discuss mailing list