To have various IP ranges in the same subnet and assign the IP Address depending of the device type that sends the request.

Simon Hobson dhcp1 at thehobsons.co.uk
Thu Aug 1 12:27:31 UTC 2019


Juan Antonio García Moreno <jagarcia at emergya.com> wrote:

> This is the situation:
> 
> - I have a network wired and WIFI.
> - I have the ISC DHCP Server that assign IP address statically with "fixed-address" and dinamically from a pool address with "range".
> 
> I would know if I can to have, for example, 3 ranges and assign the IP Address depending of the device type that request the IP.
> 
> For example:
> 
> - Static IP to devices that I want by MAC.
> - POOL1 to LAPTOP.
> - POOL2 to Smartphones.
> - POOL3 to Tablets or Watches.
> 
> How could I discriminate the request and assign the IP from POOL1, POOL2 or POOL3 depending if the device is a LAPTOP, a Smartphone or a Tablet?
> 
> Can I do this?
> 
> What would be the best way to do it?

Can you do it - yes
What is the best way - it depends !

Firstly, a few details ...
Are these ranges in the same subnet, or do you have multiple subnets on the same network ? It doesn't really matter, but it changes a couple of details.
Do devices come and go as they please, or do you have some system for registering/knowing about them ? This does make a big difference !

The basic process is that you need to classify the devices and allocate them to an appropriate class. The basic structure is like this :

class laptop {
  match <some logic to identify them>
}
class smartphone {
  match <some logic again>
}
class tablet {
  match <some more logic>
}

subnet blah {
  subnet specific options ...
  pool {
    allow members of "laptop" ;
    range ...
    range specific options
  }
  pool {
    allow members of "smartphone" ;
    range ...
    range specific options
  }
  pool {
    allow members of "tablet" ;
    range ...
    range specific options
  }
}

How this works is that each requests gets passed through the classification logic and clients get put into a class. Membership of the class is then used to determine which pool(s) the client is permitted to use, and hence what address range is used. As Sten said, the hard part is the classification logic ...

What Sten is doing is as described in the manual (man dhcpd.conf) section under subclassing. So your "laptop" class might look like :
class "laptop" {
  match pick-first-value (option dhcp-client-identifier, hardware);
}
subclass "laptop" 1:aa:bb:cc:dd:ee:ff ;
subclass "laptop" 1:ff:ee:dd:cc:bb:aa ;
...
This works if you know (in advance, or at least as they are "registered" onto the network) the client ID and/or MAC address for each device, it doesn't work if devices can just come and go as they please.

You could try doing it by manufacturer like this :
class "laptop" {
  match if substring(hardware,1,3)=aa:bb:cc;
}
which would match all devices where the MAC address starts with aa:bb:cc. This quickly becomes unwieldy given the number of manufacturers, all with multiple blocks of MAC addresses (check the man page, the "or" construct might not be correct) :
class "laptop" {
  match if substring(hardware,1,3)=aa:bb:cc
     or if substring(hardware,1,3)=ff:ee:dd
     or ... ;
}

Another factor to consider is the execution time. All classes are evaluated for all requests (a client may belong to more than one class), and if each one had a long list of "if ... or ... or ..." statements to match, then it would increase CPU load on a busy server.

That should give you some ideas to work on, then come back when you've either decided it's going to be too much effort :D, or you've got more specific queries.



More information about the dhcp-users mailing list