dhcpd.conf logical hierachy

Simon Hobson dhcp1 at thehobsons.co.uk
Thu Oct 19 09:15:43 UTC 2017


Narcis Garcia <informatica at actiu.net> wrote:

> subnet 172.16.0.0 netmask 255.255.0.0 { # For eth0=172.16.20.100
>        ...
>        pool {
>                range 172.16.20.150 172.16.20.189;
>                allow unknown-clients;
>        }
> }
> subnet 192.168.2.0 netmask 255.255.255.0 { # For eth0=172.16.20.100
>        ...
>        pool {
>                range 192.168.2.3 192.168.2.199;
>                allow unknown-clients;
>        }
> }
> host printer_1 {
>        hardware ethernet 00:11:22:33:44:55;
>        fixed-address 172.16.20.201;
> }
> host printer_2 {
>        hardware ethernet 22:33:44:55:66:77;
>        fixed-address 192.168.2.220;
> }

That's it - almost, lets ignore the 192.168.2.0 subnet for the moment.

The server will automagically "do the right thing" in terms of matching a fixed-address with the appropriate subnet. So printer 1 will automatically be associated with the 172.16.0.0 subnet and inherit the appropriate options (eg routers).

To be a bit more precise ...
It's not the fixed-address declaration that links them, it's the fact the the device is connected to the appropriate network.

As I said earlier, when the DHCP packets come in, the server will determine where the client is based on either the interface (if it's directly connected), or using the GI-Addr field if the packet has been relayed. So it gets a packet from printer 1, find that it's directly attached to eth0, and associates it with the 172.16.0.0 subnet - at which point, all the options defined for that subnet will get applied.

The server will also find the host statement matching it's hardware address, and will assign it the fixed-address as this is valid for the subnet. If any options are defined for the host (or an enclosing group) then these will over-ride anything configured for the subnet.
IIRC, if the fixed-address is not valid for the subnet (eg someone has moved printer 1 to a different network also served by this DHCP server), then the fixed-address will be ignored but the rest of the host statement will be applied. You can also specify multiple addresses for the fixed-address statement and the server will pick one that is valid for the network the device is attached to.

No, about that 192.168.2.0 subnet. Your comment says that this is also attached to eth0.
If this is the case, then you need to wrap the two subnets in a shared network statement - this is exactly the situation the shared network is designed to deal with, 2 (or more) IP subnets on the same physical network (or to be precise, collision domain).
However, if it is the other side of a router and the packets are being relayed to the server, then this is not a shared network.
It's important to correctly define the network so what the DHCP server knows about matches the actual network topology.



More information about the dhcp-users mailing list