(Installation and Configuration)
Created: 2020-09-29 Tue 22:32
{ "Dhcp4": { "interfaces-config": { "interfaces": [ "eth0" ] }, "control-socket": { "socket-type": "unix", "socket-name": "/tmp/kea-dhcp4.socket" }, [...]
//
) is ignored./*
and */
is
ignored. This commenting can span multiple lines.<?include "file.json"?>
.When working with KEA, it helps to have an editor that understands the JSON format, can check the syntax and can highlight and reformat JSON data
= VIM
ESC-X json-mode<enter>
CTRL+c-CTRL+f
vim
, syntax highlighting for JSON can be enabled in the
command mode with : set syntax=json
/etc/kea/
/usr/local/etc/kea
on
FreeBSDkea-ctrl-agent.conf
- Kea control agentkea-dhcp-ddns.conf
- Kea dynamic DNS updaterkea-dhcp4.conf
- Kea DHCPv4 serverkea-dhcp6.conf
- Kea DHCPv6 serverkeactrl.conf
- configuration file for keactrl
script (not in
JSON format){ "Dhcp4": { "interfaces-config": { "interfaces": [ "eth0" ] }, "control-socket": { "socket-type": "unix", "socket-name": "/tmp/kea-dhcp4.socket" }, [...]
[...] "lease-database": { "type": "memfile", "lfc-interval": 3600 }, [...]
[...] "renew-timer": 900, "rebind-timer": 1800, "valid-lifetime": 3600, [...]
routers
)[...] "subnet4": [ { "subnet": "192.0.2.0/24", "pools": [ { "pool": "192.0.2.100 - 192.0.2.200" } ], "option-data": [ { "name": "routers", "data": "192.0.2.1" } ] } ] }, [...]
[...] "Logging": { "loggers": [ { "name": "kea-dhcp4", "output_options": [ { "output": "/var/log/kea-dhcp4.log" } ], "severity": "INFO", "debuglevel": 0 } ] } }
-t
(test) parameter# kea-dhcp4 -t /etc/kea/kea-dhcp4.conf Syntax check failed with: /etc/kea/kea-dhcp4.conf:33.9: syntax error, unexpected }
# kea-dhcp4 -t /etc/kea/kea-dhcp4.conf INFO [kea-dhcp4.dhcpsrv/51] DHCPSRV_CFGMGR_ADD_IFACE listening on interface server-eth0 INFO [kea-dhcp4.dhcpsrv/51] DHCPSRV_CFGMGR_SOCKET_TYPE_DEFAULT "dhcp-socket-type" not specified, using default socket type raw INFO [kea-dhcp4.dhcpsrv/51] DHCPSRV_CFGMGR_NEW_SUBNET4 a new subnet has been added to configuration: 192.0.2.0/24 with params: t1=900, t2=1800, valid-lifetime=3600
keactrl
is a shell script that can be used to control the Kea
servicessystemd
, runit
or s6
keactrl
lists the location of the
configuration files and the Kea binaries# This is a configuration file for keactrl script which controls # the startup, shutdown, reconfiguration and gathering the status # of the Kea's processes. # Note that control agent must be launched after servers and netconf last. # prefix holds the location where the Kea is installed. prefix=/usr/local # Location of Kea configuration files. kea_dhcp4_config_file=${prefix}/etc/kea/kea-dhcp4.conf kea_dhcp6_config_file=${prefix}/etc/kea/kea-dhcp6.conf kea_dhcp_ddns_config_file=${prefix}/etc/kea/kea-dhcp-ddns.conf kea_ctrl_agent_config_file=${prefix}/etc/kea/kea-ctrl-agent.conf kea_netconf_config_file=${prefix}/etc/kea/kea-netconf.conf # Location of Kea binaries. exec_prefix=${prefix} dhcp4_srv=${exec_prefix}/sbin/kea-dhcp4 dhcp6_srv=${exec_prefix}/sbin/kea-dhcp6 dhcp_ddns_srv=${exec_prefix}/sbin/kea-dhcp-ddns ctrl_agent_srv=${exec_prefix}/sbin/kea-ctrl-agent netconf_srv=${exec_prefix}/sbin/kea-netconf [...]
[...] # Start DHCPv4 server? dhcp4=yes # Start DHCPv6 server? dhcp6=yes # Start DHCP DDNS server? dhcp_ddns=no # Start Control Agent? ctrl_agent=yes # Start Netconf? netconf=no # Be verbose? kea_verbose=no
keactrl
, the script can be
used to start the Kea server moduleskeactrl start INFO/keactrl: Starting /opt/kea/sbin/kea-dhcp4 -c /opt/kea/etc/kea/kea-dhcp4.conf INFO/keactrl: Starting /opt/kea/sbin/kea-ctrl-agent -c /opt/kea/etc/kea/kea-ctrl-agent.conf
keactrl
offers a status overview of the currently configured modules# keactrl status DHCPv4 server: active DHCPv6 server: inactive DHCP DDNS: inactive Control Agent: active Kea DHCPv4 configuration file: /opt/kea/etc/kea/kea-dhcp4.conf Kea DHCPv6 configuration file: /opt/kea/etc/kea/kea-dhcp6.conf Kea DHCP DDNS configuration file: /opt/kea/etc/kea/kea-dhcp-ddns.conf Kea Control Agent configuration file: /opt/kea/etc/kea/kea-ctrl-agent.conf keactrl configuration file: /opt/kea/etc/kea/keactrl.conf
keactrl
can be used to reload the configuration into the Kea
processes# keactrl reload INFO/keactrl: Reloading kea-dhcp4... INFO/keactrl: Reloading kea-ctrl-agent...
keactrl
can also be used to stop all configured Kea modules# keactrl stop INFO/keactrl: Stopping kea-dhcp4... INFO/keactrl: kea-dhcp6 isn't running. INFO/keactrl: kea-dhcp-ddns isn't running. INFO/keactrl: Stopping kea-ctrl-agent...
# systemctl start kea-dhcp4
# systemctl status kea-dhcp4 ● kea-dhcp4.service - Kea DHCPv4 Server Loaded: loaded (/usr/lib/systemd/system/kea-dhcp4.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2018-12-06 10:13:26 UTC; 4s ago Docs: man:kea-dhcp4(8) Main PID: 63 (kea-dhcp4) Tasks: 1 (limit: 1144) Memory: 1.9M CGroup: /machine.slice/libpod-2e3e4a67333cf94630baa9c268ae84f8e77353abf14b074ed2ef9d73bc6e4f53.scope/system.slice/kea-dhcp4.service └─63 /usr/sbin/kea-dhcp4 -c /etc/kea/kea-dhcp4.conf Dec 06 10:13:26 2e3e4a67333c systemd[1]: Started Kea DHCPv4 Server. Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.674 INFO [kea-dhcp4.dhcp4/63] DHCP4_STARTING Kea DHCPv4 server version 1.3.0 starting Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.676 INFO [kea-dhcp4.dhcpsrv/63] DHCPSRV_CFGMGR_ADD_IFACE listening on interface server-eth0 Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.676 INFO [kea-dhcp4.dhcpsrv/63] DHCPSRV_CFGMGR_SOCKET_TYPE_DEFAULT "dhcp-socket-type" not specified , using default socke> Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.677 INFO [kea-dhcp4.dhcpsrv/63] DHCPSRV_CFGMGR_NEW_SUBNET4 a new subnet has been added to configuration: 192.0.2.0/24 wit> Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.677 INFO [kea-dhcp4.dhcp4/63] DHCP4_CONFIG_COMPLETE DHCPv4 server has completed configuration: added IPv4 subnets: 1; DDN> Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.677 INFO [kea-dhcp4.dhcpsrv/63] DHCPSRV_MEMFILE_DB opening memory file lease database: lfc-interval=3600 type=memfile uni> Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.679 INFO [kea-dhcp4.dhcpsrv/63] DHCPSRV_MEMFILE_LEASE_FILE_LOAD loading leases from file /var/lib/kea/kea-leases4.csv Dec 06 10:13:26 2e3e4a67333c kea-dhcp4[63]: 2018-12-06 10:13:26.680 INFO [kea-dhcp4.dhcpsrv/63] DHCPSRV_MEMFILE_LFC_SETUP setting up the Lease File Cleanup interval to 3600 sec
dhclient
Create a new shell script in /usr/local/sbin/dhclient-debug.sh
with the lines below
#!/bin/sh env
Execute the dhclient
tool with this script
dhclient -sf /usr/local/sbin/dhclient-debug.sh
perfdhcp
127.0.0.1
Port 8000
kea-ctrl-agent.conf
jq
can be used to pretty print the output# kea-shell --service dhcp4 --host 127.0.0.1 --port 8000 version-get | jq [ { "arguments": { "extended": "1.7.10-git\ngit 9bade6ae294f570976e7614e84a76a34ac4915b1\nlinked with:\nlog4cplus 1.2.2\nLibreSSL 3.2.1\ndatabase:\nPostgreSQL backend 6.1, library 120003\ nMemfile backend 2.1" }, "result": 0, "text": "1.7.10-git" } ]
curl
toolconfig-get
command to the DHCPv4 server[kea-server]# curl -X POST -H "Content-Type: application/json" \ -d '{ "command": "config-get", "service": [ "dhcp4" ] }' \ http://127.0.0.1:8000/
jq
can be used to
pretty-print the output[kea-server]# curl -X POST -H "Content-Type: application/json" \ -d '{ "command": "config-get", "service": [ "dhcp4" ] }' \ http://127.0.0.1:8000/ | jq
jq
can be used to filter specific parts of the configuration. The
jq
filter ".[0].arguments"
can be used to produce a valid KEA
configuration file.
[kea-server]# curl -X POST -H "Content-Type: application/json" \ -d '{ "command": "config-get", "service": [ "dhcp4" ] }' \ http://127.0.0.1:8000/ | jq ".[0].arguments.Dhcp4.loggers"
Result:
[ { "debuglevel": 0, "name": "kea-dhcp4", "output_options": [ { "output": "/opt/kea/var/log/kea-dhcp4.log" } ], "severity": "INFO" } ]
list-commands
command returns the API commands available for
a specific KEA module[kea-server]# curl -X POST -H "Content-Type: application/json" \ -d '{ "command": "list-commands", "service": [ "dhcp4" ] }' \ http://127.0.0.1:8000/ | jq
curl -s -X POST -H "Content-Type: application/json" \ -d '{ "command": "config-get", "service": [ "dhcp4" ] }' \ http://127.0.0.1:8000/ | jq ".[0]" > kea-dhcp4.tmp
command
and service
informationresult
from the JSON file{ "command": "config-set", "service": [ "dhcp4" ], "arguments": { "Logging": { "loggers": [ { "severity": "INFO", "output_options": [ [...]
[kea-server]# curl -s -X POST -H "Content-Type: application/json" \ -d @kea-dhcp4.tmp http://127.0.0.1:8000/ | jq [ { "result": 0, "text": "Configuration successful." } ]
config-write
command (be careful, any
comments in the file will be gone and the formatting will be
different)[kea-server]# curl -s -X POST -H "Content-Type: application/json" \ -d '{ "command": "config-write", "arguments": { "filename": "/etc/kea/kea-dhcp4-new.json" }, "service": [ "dhcp4" ] }' \ http://127.0.0.1:8000/ | jq [ { "arguments": { "filename": "/etc/kea/kea-dhcp4-new.json", "size": 3248 }, "result": 0, "text": "Configuration written to /etc/kea/kea-dhcp4-new.json successful" } ]
kea-dhcp6.conf
keactrl
script
or through systemd (on Linux)kea-dhcp6-serverid
in
the /var/lib/kea
directory (the path is system/distribution dependent)