Suppose I have a bunch of hosts set up like this:
host host2 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.2; }
host host3 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.3; }
# etc ...
subnet 192.168.1.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 8.8.8.8, 8.8.4.4;
# Unknown test clients get this pool.
pool {
max-lease-time 1800; # 30 minutes
range 192.168.1.100 192.168.1.250;
allow unknown-clients;
}
# MyHosts nodes get this pool
pool {
max-lease-time 1800;
range 192.168.1.1 192.168.1.20;
allow members of MyHosts;
deny unknown-clients;
}
}
I want to put these into a class and assign them to a pool so that I can ensure that only those hosts are allowed on that pool.
I tried defining them as:
class "MyHosts" {
host host2 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.2; }
host host3 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.3; }
}
But this gave an error "host declarations not allowed here".
How do I do it?
Best Answer
As you discovered, you cannot declare
host
s inside aclass
. Theclass
declaration can only containmatch
ormatch if
statements. If you want to group your client requests into classes using theclass
construct, you could do it something like this:In the above, the
match
statement in theclass
declares that subclasses will be matched by thehardware
attribute. (hardware
evaluates to the concatenation of the hardware type and the MAC address of the client; for ethernet clients, the hardware type is 1, thus the1:
prefix in the data string of thesubclass
statements.)When a client is a member of a subclass, it is also a member of the parent class, so now you can use
allow
anddeny
clauses in yourpool
declarations to ensure that members ofMyHosts
are assigned IPs from the desired pool, e.g.: