3.8. Classifying clients in Kea
Kea client classes provide a mechanism for grouping clients based on specific criteria, allowing for granular control over network configuration. You can use this feature to apply special processing rules or assign different DHCP options to clients.
You can create a client class that assigns Voice over IP (VoIP) devices to a specific IP pool to ensures that VoIP phones get different IP addresses than other devices on the network. For example, in IPv4 networks, you can use a substring expression to test for the first 3 octets of their media access control (MAC) address. In IPv6 networks where the MAC address is not a reliable indicator, you can test for a substring of the DHCPv6 vendor class option.
Prerequisites
-
The
kea-dhcp4andkea-dhcp6services are configured and running. -
You are logged in as the
rootuser.
Procedure
If you are configuring an IPv4 network:
Edit the
/etc/kea/kea-dhcp4.conffile, and make the following changes:Add the following client classes to the
Dhcp4parameter:{ "Dhcp4": { ... "client-classes": [ { "name": "VoIP-Phones", "test": "substring(pkt4.mac, 0, 3) == 0x525400" }, { "name": "Others", "test": "not member('VoIP-Phones')" } ], ...In this example, devices with a MAC address starting with
52:54:00match theVoIP-Phonesclient class. Devices that do not match the rule are assigned to theOthersclient class.Assign the client classes to your
pooldefinitions:{ "Dhcp4": { "subnet4": [ { "subnet": "192.0.2.0/24", "pools": [ { "pool": "192.0.2.20 - 192.0.2.100", "client-class": "Others" }, { "pool": "192.0.2.150 - 192.0.2.200", "client-class": "VoIP-Phones" } ], ...Depending on which client class a host matches, Kea assigns an IP from the corresponding pool.
Verify the syntax of the configuration file:
# kea-dhcp4 -t /etc/kea/kea-dhcp4.confIf the command returns
Syntax check failed, fix the errors shown in the report.Restart the
kea-dhcp4service:# systemctl restart kea-dhcp4
If you are configuring an IPv6 network:
Edit the
/etc/kea/kea-dhcp6.conffile, and make the following changes:Add the following client classes to the
Dhcp6parameter:{ "Dhcp6": { ... "client-classes": [ { "name": "VoIP-Phones", "test": "option[16].exists and (substring(option[16].hex, 0, 8) == '00000009')", }, { "name": "Others", "test": "not member('VoIP-Phones')" } ], ...In this example, devices that send a DHCPv6 vendor class option (option 16) where the hexadecimal value begins with
00000009match theVoIP-Phonesclient class. Devices that do not match the rule are assigned to theOthersclient class.Assign the client classes to your
pooldefinitions:{ "Dhcp6": { "subnet6": [ { "subnet": "2001:db8:0:1::/64", "pools": [ { "pool": "2001:db8:0:1::1000 - 2001:db8:0:1::2000", "client-class": "Others" }, { "pool": "2001:db8:0:1::4000 - 2001:db8:0:1::5000", "client-class": "VoIP-Phones" } ], ...Depending on which client class a host matches, Kea assigns an IP from the corresponding pool.
Verify the syntax of the configuration file:
# kea-dhcp6 -t /etc/kea/kea-dhcp6.confIf the command returns
Syntax check failed, fix the errors shown in the report.Restart the
kea-dhcp6service:# systemctl restart kea-dhcp6
Verification
- Connect clients that match the rules in the client classes and verify that Kea assigned an IP from the associated pool.