Kea

ISC Kea DHCP
フリーのDHCPサーバとして利用されているISC DHCP Serverの後継ソフト。
リース情報の保持にRDBも利用出来る様になった上、
REST APIによるアプリケーション制御も出来る様になった。

従来はfailover機能が実装されていなかったが、v1.4.0で実装された。

インストール

0. 事前準備
KeaにはBoostライブラリを利用している為、関連するライブラリを導入しておく。

# zypper install log4cplus log4cplus-devel boost-devel libboost_system-devel
# tar zxvf kea-1.6.1.tar.gz
# cd kea-1.6.1
# ./configure --prefix=/usr/local/kea-1.6.1 --enable-shell --with-openssl --with-mysql=/usr/bin/mysql_config
# make
# make install
# ln -s /usr/local/kea-1.6.1 /usr/local/kea
# ln -s /usr/local/kea/etc/kea /etc/kea
# mkdir /var/log/kea



1. 起動準備
プログラム起動用のサービスファイルを作成する。
実行ユーザはrootそのままにしておく。必要に応じてパーミッション変更も実施する。

  • /usr/lib/systemd/system/kea-ctrl.service
    [Unit]
    Description=ISC Kea CTRL Agent
    Documentation=man:kea-ctrl-agent(8)
    Wants=network-online.target
    After=network-online.target time-sync.target
     
    [Service]
    Type=simple
    Restart=on-failure
    EnvironmentFile=-/etc/sysconfig/kea
    ExecStartPre=/usr/local/kea/sbin/kea-ctrl-agent -t ${CONFIG_CTRL}
    ExecStart=/usr/local/kea/sbin/kea-ctrl-agent -c ${CONFIG_CTRL}
    ExecReload=/bin/kill -HUP $MAINPID
    ExecStop=/bin/kill -SIGTERM $MAINPID
     
    [Install]
    WantedBy=kea-dhcp4.service
    WantedBy=kea-dhcp6.service

 

  • /usr/lib/systemd/system/kea-dhcp4.service
    [Unit]
    Description=ISC Kea DHCPv4 Server
    Documentation=man:kea-dhcp4(8)
    Wants=network-online.target
    After=network-online.target time-sync.target
     
    [Service]
    Type=simple
    Restart=on-failure
    EnvironmentFile=-/etc/sysconfig/kea
    ExecStartPre=/usr/local/kea/sbin/kea-dhcp4 -t ${CONFIG_DHCP4}
    ExecStart=/usr/local/kea/sbin/kea-dhcp4 -c ${CONFIG_DHCP4}
    ExecReload=/bin/kill -HUP $MAINPID
    ExecStop=/bin/kill -SIGTERM $MAINPID
     
    [Install]
    WantedBy=multi-user.target

 

  • /usr/lib/systemd/system/kea-dhcp6.service
    [Unit]
    Description=ISC Kea DHCPv6 Server
    Documentation=man:kea-dhcp6(8)
    Wants=network-online.target
    After=network-online.target time-sync.target
     
    [Service]
    Type=simple
    Restart=on-failure
    EnvironmentFile=-/etc/sysconfig/kea
    ExecStartPre=/usr/local/kea/sbin/kea-dhcp6 -t ${CONFIG_DHCP6}
    ExecStart=/usr/local/kea/sbin/kea-dhcp6 -c ${CONFIG_DHCP6}
    ExecReload=/bin/kill -HUP $MAINPID
    ExecStop=/bin/kill -SIGTERM $MAINPID
     
    [Install]
    WantedBy=multi-user.target

 

  • /etc/sysconfig/kea
    ## Type:        string
    ## Default:     /usr/local/kea/etc/kea/kea-ctrl-agent.conf
    #
    # This is a basic configuration for the Kea Control Agent.
    # Specify kea-ctrl-agent configuration file.
    #
    CONFIG_CTRL="/etc/kea/kea-ctrl-agent.conf"
     
    ## Type:        string
    ## Default:     /usr/local/kea/etc/kea/kea-dhcp4.conf
    #
    # This is a basic configuration for the Kea DHCPv4 server.
    # Specify kea-dhcp4 configuration file.
    #
    CONFIG_DHCP4="/etc/kea/kea-dhcp4.conf"
     
    ## Type:        string
    ## Default:     /usr/local/kea/etc/kea/kea-dhcp6.conf
    #
    # This is a basic configuration for the Kea DHCPv6 server.
    # Specify kea-dhcp6 configuration file.
    #
    CONFIG_DHCP6="/etc/kea/kea-dhcp6.conf"
     
    ## Type:        string
    ## Default:     /usr/local/kea/var/run
    #
    # The value as passed into the build configure script.
    # That this value may be overridden at runtime by 
    # setting the environment variable KEA_PIDFILE_DIR,
    # although this is intended primarily for testing purposes.
    #
    KEA_PIDFILE_DIR="/var/run"

 

  • /etc/logrotate.d/kea
    /var/log/kea/*.log {
        missingok
        ifempty
        sharedscripts
        postrotate
            systemctl restart kea-ctrl  > /dev/null 2>&1 || true
            systemctl restart kea-dhcp4 > /dev/null 2>&1 || true
        endscript
    }


2. DB準備
リース情報の格納にRDBを使う場合はデータベースの作成を行う。
Kea DHCPでは、MySQL・PostgreSQL・Cassandra・LDAPなどを利用可能。
下記はバックエンドにMySQLを利用した場合の設定例

MariaDB [(none)]> create database kea_db;
MariaDB [(none)]> create user 'kea_user'@'%' identified by 'kea_pass';
MariaDB [(none)]> grant all on kea_db.* to 'kea_user'@'%';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit;
 
# vi /etc/my.cnf
---
※下記を追記
"log_bin_trust_function_creators = 1"
# /usr/local/kea/sbin/kea-admin db-init mysql -h 127.0.0.1 -u kea_user -p kea_pass -n kea_db -d /usr/local/kea/share/kea/scripts


コンフィグ

A. シングル構成・別セグメント待受
詳細はマニュアルに書かれているので割愛。
下記はクライアントセグメントの外にDHCPサーバを設置し、複数セグメントのDHCPサーバを集約管理する時の設定。
 
・DHCPサーバ 構成情報

IPアドレス10.0.0.1
ネットワーク10.0.0.0/24
インターフェースeth0 (1NIC構成)

 
・DHCPクライアント IP払出し情報

ネットワーク10.10.0.0/24
デフォルトルート10.10.0.254
IP払い出し範囲10.10.0.100~10.10.0.200
プライマリDNS10.0.0.10
セカンダリDNS10.0.0.20

 
・補足
DHCPクライアントとDHCPサーバが別セグメントになり、DHCP DISCOVERがDHCPサーバまで届かなくなるので、
クライアントのデフォルトルートとなるルータに、DHCPリレー設定を入れておく。

 

 /etc/kea/keactrl.conf

 

 /etc/kea/kea-ctrl-agent.conf

 

 /etc/kea/kea-dhcp4.conf