Kea DHCP server

Kea DHCP server is the new DHCP server from ISC. Their documentation is good in some parts and absolutely horrible in most parts. Kea adds a database back end to make things easier maintain and configure but they don’t have any documentation about configuring database back end. It took me forever to find bits and pieces of information to get mine up and running. Looking back at mine now I wish I had done even more fine tuning but I can do a rolling upgrade next maintenance window.

So let us talk about configuring and getting this up and running. I am going to use Red Hat Enterprise Server 7.3 because we are a Red Hat shop. CentOS would probably work just as good. The default repositories don’t have Kea so we need to enable EPEL repositories. To enable EPEL repos you need to enable the “optional” and “extras” subscription channels. Then download the rpm for EPEL and install.

subscription-manager repos –enable rhel-7-server-opotional-rpms
subscription-manager repos –enable rhel-7-server-extras-rpms
rpm -i epel-release-latest-7.noarch.rpm

Now lets install Kea and MariaDB server

yum install mariadb-server kea

From here you can probably do your normal setup stuff like change boot parameters (I hate “quiet” and “rhgb” what was Red Hat thinking), setup chrony, update, and many others.

Now lets work on the configuration. This is where the documentation sucks. There is no documentation on the proper way to setup the system with a MariaDB backend. The first thing to do is setup MariaDB database for Kea. This is pretty easy with the included MySQL sql file provided with Kea but not documented.

mysql -u root -p kea_dhcp < /usr/share/kea/scripts/mysql/dhcpdb_create.mysql

I would also add a user in MariaDB for Kea to use for connections.

Lets modify the kea.conf file to use our database. The kea.conf file is in JSON format. Lets backup our conf file and start modifying. You can use any text editor you want. There is a lot changes to the configuration file so I like using Atom for big configuration files. In my situation I have several subnets that my DHCP server takes care of. I also only use DHCP v4. There are DHCP v6 options in the configuration file but I don’t use them. I also define options in the configuration file that can be defined in one of the database tables and have a relationships pointing to other tables but I am still trying to figure out these configurations. One step at time and I will figure it out.

I am not going to show my whole config but here is some …

# DHCPv4 configuration starts here.
"Dhcp4": {
  # Add names of interfaces to listen on.
  "interfaces-config": {
    "interfaces": [ "*" ]
  },
  "lease-database": {
    "type": "mysql",
    "name": "kea_dhcp",
    "host": "localhost", 
    "user": "kea_admin", 
    "password": "secret" 
  }, 
  "hosts-database" : { 
    "type": "mysql", 
    "name": "kea_dhcp", 
    "host": "localhost", 
    "user": "kea_admin", 
    "password": "secret" 
  },

The above code is to setup the database connection information for the lease database and the host database. All of the desktops on the network have static address, there are not any dynamic addresses.

"option-data": [
  {
    "name": "domain-name-servers",
    "code": 6,
    "space": "dhcp4",
    "csv-format": true,
    "data": "10.2.11.1,10.2.11.2"
  }
],
"expired-leases-processing": {
  "reclaim-timer-wait-time": 10,
  "flush-reclaimed-timer-wait-time": 25,
  "hold-reclaimed-time": 3600,
  "max-reclaim-leases": 100,
  "max-reclaim-time": 250,
  "unwarned-reclaim-cycles": 5
},
"valid-lifetime": 4000,

 

The settings above are global options that affect all systems on the network. In the DNS option, the name is linked to the “code”. The code is defined in the documentation. There are many codes for different options. In this case “6” is “domain-name-servers”. “space” means this setting is for dhcp4 networks. The other options are self explanatory for DHCP people. I am not teaching DHCP in this article maybe later.

"subnet4": [
{
  "subnet": "10.3.0.0/16",
  "id": 1001,
  "option-data": [
    {
      "name": "routers",
      "code": 3,
      "data": "10.3.0.1"
    },
    {
      "name": "broadcast-address",
      "code": 28,
      "data": "10.3.255.255"
    }
  ]
},
{
  "subnet": "10.4.0.0/16",
  "id": 1002,
  "option-data": [
   {
     "name": "routers",
     "code": 3,
     "data": "10.4.0.1"
   },
   {
     "name": "broadcast-address",
     "code": 28,
     "data": "10.4.255.255"
   }
  ]
},

 

The above configuration is for the individual networks. Subnet4 is for subnets on IPv4 network. The first subnet has an “id” declaration. This has to be a integer and must be unique to that subnet. When we get to importing DHCP host you will see. “option-data” is configuration for this particular network.

Now let us get to the hard part. Entering static host is no simple task but I have created a stored procedure that makes things a lot easier. Its not totally my stored procedure but I took somebody else’s stored procedure and made some modifications to suit my needs.

use dhcpdata;

DELIMITER //
CREATE PROCEDURE insert_host(
  IN ipv4_reservation VARCHAR(20),
  IN hostname VARCHAR(50),
  IN identifier_type VARCHAR(50),
  IN identifier_value VARCHAR(50),
  IN dhcp4_subnet_id INT(10),
  IN next_server VARCHAR(20),
  IN server_hostname VARCHAR(50),
  IN boot_file_name VARCHAR(50)
)
BEGIN
INSERT INTO hosts (dhcp_identifier,
                   dhcp_identifier_type,
                   dhcp4_subnet_id,
                   ipv4_address,
                   hostname,
                   dhcp4_next_server,
                   dhcp4_server_hostname,
                   dhcp4_boot_file_name)
VALUES (UNHEX(REPLACE(identifier_value, ':', '')),
  (SELECT type FROM host_identifier_type WHERE name=identifier_type),
        dhcp4_subnet_id,
        INET_ATON(ipv4_reservation),
        hostname,
        INET_ATON(next_server),
        server_hostname,
        boot_file_name);
END //
DELIMITER ;

Now you can just make a call to the procedure and insert hosts. Lets talk about the procedure. “insert_host” is the procedure name. The first argument is the IP address. Next is the hostname. Then the identifier type which is “hw-address” for mac address. The identifier value is the mac address with colons. Now the dhcp4_subnet_id is that unique integer I meantioned above when declaring the subnets. The next 3 arguments can be null it depends on your network. “next_server” is the next argument, it has something to do with the bootstrap process of the client. “server_hostname” is next, this the dhcp server hostname. The last argument is the file location of the client boot process.

Just run the stored procedure to add a client and your ready to start the service and start using your DHCP server. There several different ways to setup Kea but this way served my purposes for my network.