ISC-KeaでDHCP

By siteadministrator, 11 7月, 2020

ISC-DHCPをずっと使ってきたが、固定(特定アドレス)の払い出しの管理が面倒となってきたため、なるべくデータベースで管理できるKeaを選択した。特にFail Over対応のISC-DHCPの2つのサーバーに同じ設定を書き込むのが面倒になってきたための理由です。同時にIPv6の本格運用も目的です。ただし、Fail SafeとするためにはmariaDBもHA化していといけないので、先は長い。

インストール

Debian 10 BusterにはISC-KEA DHCP Serverのパッケージは含まれていない。

  1. ISCのマニュアルからaptのsources.listに対象リポジトリを追加する。
  2. SIDのパッケージソースからパッケージを作成する。
  3. SIDのパッケージをそのまま使用する。
  4. Gitレポジトリからソースをダウンロードし、ビルドする。

1の場合

apt install kea isc-kea-dhcp4-server isc-kea-dhcp6-server isc-kea-admin

3の場合

apt install -t unstable kea isc-kea-dhcp4-server isc-kea-dhcp6-server isc-kea-admin

2の場合は、ここを参照のこと

1は少々怖い、3は依存関係が不安、4も依存関係が面倒が理痛で、今回は慣れている2を選択した。

事前設定

リース済みアドレスの管理や特定IPを割当する場合にデータベースを利用する場合には、MariaDB(PostgreSQL、MySQLも利用可能)を以下の様に設定する。

MariaDBのセットアップは終了しているものとする。

Kea用のデータベースを作成する。

echo 'CREATE DATABASE データベース名' | mysql -u root

Kea用DBにスキーマーにオブジェクトを作成する。

kea-admin db-init mysql -h DBサーバーホスト -u DBユーザー -p DBパスワード -n DB名

Checking if there is a database initialized already. Please ignore errors.
Verifying create permissions for kea
MySQL Version is:
Initializing database using script /usr/share/kea/scripts/mysql/dhcpdb_create.mysql

mysql returned status code 0
Database version reported after initialization: 9.3

ユーザーのアクセス権は、管理方法により設定すること。

セットアップ

DHCP4(IPv4)のセットアップ

vi /etc/kea/kea-dhcp4.conf 

{
    "Dhcp4": {
        "interfaces-config": {
            "interfaces": [ "ens11/192.168.2.31" ]
        },

 

        "control-socket": {
            "socket-type": "unix",
            "socket-name": "/tmp/kea4-ctrl-socket"
        },
        "lease-database": {
             "type": "mysql",
             "name": "データベース名",
             "user": "DBユーザー名",
             "password": "DBパスワード",
             "host": "データベースIPアドレス",
             "port": 3306
        },
         "hosts-database": {
             "type": "mysql",
             "name": "データベース名",
             "user": "DBユーザー名",
             "password": "DBパスワード",
             "host": "データベースIPアドレス",
             "port": 3306
         },
        "renew-timer": 900,
        "rebind-timer": 1800,
        "valid-lifetime": 3600,
        "option-data": [
            {
                "name": "domain-name-servers",
                "data": "192.168.0.29, 192.168.0.30, 192.168.0.31"
            },

            {
                "name": "domain-search",
                "data": "ドメイン名"
            }
        ],
        "subnet4": [
            {
                "subnet": "192.168.0.0/24",

                "pools": [ { "pool": "192.168.0.65 - 192.168.0.128" } ],

                "option-data": [
                    {
                        // For each IPv4 subnet you most likely need to specify at
                        // least one router.
                        "name": "routers",
                        "data": "192.168.0.10"
                    }
                ]
            },
            {
                "subnet": "192.168.2.0/24",

                "pools": [ { "pool": "192.168.2.65 - 192.168.2.128" } ],

                "option-data": [
                    {
                        // For each IPv4 subnet you most likely need to specify at
                        // least one router.
                        "name": "routers",
                        "data": "192.168.2.10"
                    }
                ]
            },
            {
                "subnet": "192.168.10.0/24",

                "pools": [ { "pool": "192.168.10.65 - 192.168.10.128" } ],

                "option-data": [
                    {
                        // For each IPv4 subnet you most likely need to specify at
                        // least one router.
                        "name": "routers",
                        "data": "192.168.10.10"
                    }
                ]
            }
        ],

        "loggers": [
        {
            // This section affects kea-dhcp4, which is the base logger for DHCPv4
            // component. It tells DHCPv4 server to write all log messages (on
            // severity INFO or more) to a file.
            "name": "kea-dhcp4",
            "output_options": [
                {
                    "output": "/var/log/kea/kea-dhcp4.log"

                }
            ],
            "severity": "INFO",

            "debuglevel": 0
        }
      ]
    }
}

DHCP6(IPv6)のセットアップ

IPv6サーバーのセットアップは初めてなので、ISCサイトのKeaの設定サンプルで動作させてみた。

IPv6のアドレス空間は広大で、アドレス設計も面倒なので、もっと良いやり方はあるのだろうが、基本的に以下の設定とし、IPv4との整合性を持たせた。

IPv4: 192.168.0.1 → IPv6: 2001:db8:1::192.168.0.1

vi /etc/kea/kea-dhcp6.conf

{
    # DHCPv6 configuration starts on the next line
    "Dhcp6": {

        "server-id": {
            "type": "LLT",
            "identifier": "XXXXXXXXXXXXX",
            "persist": false
        },

        # First we set up global values
        "valid-lifetime": 4000,
        "renew-timer": 1000,
        "rebind-timer": 2000,
        "preferred-lifetime": 3000,

        # Next we set up the interfaces to be used by the server.
        "interfaces-config": {
            "interfaces": [ "ens11" ]
        },

        "lease-database": {
             "type": "mysql",
             "name": "データベース名",
             "user": "DBユーザー名",
             "password": "DBパスワード",
             "host": "データベースIPアドレス",
             "port": 3306
        },
         "hosts-database": {
             "type": "mysql",
             "name": "データベース名",
             "user": "DBユーザー名",
             "password": "DBパスワード",
             "host": "データベースIPアドレス",
             "port": 3306

        # Finally, we list the subnets from which we will be leasing addresses.
        "subnet6": [
            {
                "subnet": "2001:db8:1::/64",
                "pools": [
                    {
                    "pool": "2001:db8:1::192.168.2.65/122"
                    }
                ],
                "option-data": [
                    // You can specify additional options here that are subnet
                    // specific. Also, you can override global options here.
                    {
                        "name": "dns-servers",
                        "data": "2001:db8:1::c0a8:21f"
                    }
                ]
            }
        ],
        "loggers": [
            {
                "name": "kea-dhcp6",
                "output_options": [
                    {
                        "output": "/var/log/kea/kea-dhcp6.log"
                    }
                ],
        "severity": "DEBUG",
            "debuglevel": 99
            }
        ]
        # DHCPv6 configuration ends with the next line
    }
}

Log設定については、最初全く動作(リースしているのか、クライアントが取得できていないのか分からなかったため、)Debugモードで動作させている。

実行する。

keactrl start

以上のセットアップでステータスを確認する。

keactrl status

DHCPv4 server: active
DHCPv6 server: active
DHCP DDNS: inactive
Control Agent: active

しかしながら、Dhcp6のLogを見ると

Server could not select subnet for this client

との表記があり、"subnet6″で設定されたサブネットに配布されていない状態であったため、interfaceの設定を追記した。

{
    # DHCPv6 configuration starts on the next line
    "Dhcp6": {

        "server-id": {
            "type": "LLT",
            "identifier": "XXXXXXXXXXXXX",
            "persist": false
        },

        # First we set up global values
        "valid-lifetime": 4000,
        "renew-timer": 1000,
        "rebind-timer": 2000,
        "preferred-lifetime": 3000,

        # Next we set up the interfaces to be used by the server.
        "interfaces-config": {
            "interfaces": [ "ens11" ]
        },

        "lease-database": {
             "type": "mysql",
             "name": "データベース名",
             "user": "DBユーザー名",
             "password": "DBパスワード",
             "host": "データベースIPアドレス",
             "port": 3306
        },
         "hosts-database": {
             "type": "mysql",
             "name": "データベース名",
             "user": "DBユーザー名",
             "password": "DBパスワード",
             "host": "データベースIPアドレス",
             "port": 3306

        # Finally, we list the subnets from which we will be leasing addresses.
        "subnet6": [
            {
                "subnet": "2001:db8:1::/64",
                 "id": 1,
                 "interface": "ens11",
                "pools": [
                    {
                    "pool": "2001:db8:1::192.168.2.65/122"
                    }
                ],
                "option-data": [
                    // You can specify additional options here that are subnet
                    // specific. Also, you can override global options here.
                    {
                        "name": "dns-servers",
                        "data": "2001:db8:1::c0a8:21f"
                    }
                ]
            }
        ],
        "loggers": [
            {
                "name": "kea-dhcp6",
                "output_options": [
                    {
                        "output": "/var/log/kea/kea-dhcp6.log"
                    }
                ],
        "severity": "INFO",
            "debuglevel": 0
            }
        ]
        # DHCPv6 configuration ends with the next line
    }
}

UIについて

Kea DHCP Serverはデータベースをバックエンドと出来き、DHCPに比べ比較的高速(DBを利用するよりCSVの方がかなり速いらしい)なのでだが、これをコントロールするUIが限られている(2020/7/1現在)。主な(見つけられた)ものとして、

  1. kea-anterius
  2. stork
  3. keakeeper

くらいなのだが、kea-anteriusは起動するが期待する動作をしない。keakeeperは試していない。

storkは、バージョン0.7.0では対応データベースがPostgreSQL一択で、keakeeperはドキュメントにはウェブサーバーがApache一択?(Nginxでも動作はするのでだろうが・・・ドキュメントには記載がない)ため、試していない。

リースIPはMySQLのUIやSQLで確認することとした。

Host Reservationsも同様に、SQLを実行することで運用することとした。SQL文は、ここを参考にした。

Keaのデータベースを見ると、様々なテーブルがあり、リースアドレスの表示やリザーブアドレスの払い出し以外にもプールアドレスレンジの設定等、現在Configファイルに記載していることの大半をDBで管理できるのでは?と思うのだが、ドキュメントを隅々まで読んだり、ソースをみれは分かるのでろうが、現時点では使用方法が不明である。

このため、今回はstorkを試した。ただやはり、Postgresしか対応していない。Railsでの作成のようなので、MySQL対応も比較的簡単に出来そうではあるが、バージョンアップの度に変更するのは面倒なので、ここではPosgresを使用する。

データベースの準備

apt install postgresql

Postgresに接続し、テーブルを作成する。

psql postgres

ここから、Postgresでの作業

postgres=# CREATE USER ユーザー名 WITH PASSWORD 'パスワード';

CREATE ROLE

postgres=# CREATE DATABASE stork;

CREATE DATABASE

postgres=# GRANT ALL PRIVILEGES ON DATABASE stork TO ユーザー名;

GRANT

postgres=# \c ユーザー名

You are now connected to database "ユーザー名" as user "ユーザー名".

stork=# create extension pgcrypto;

CREATE EXTENSION

インストール

curl -1sLf 'https://dl.cloudsmith.io/public/isc/stork/cfg/setup/bash.deb.sh' | sudo bash

エージェント

apt install isc-stork-agent

サーバー

apt install isc-stork-server

設定ファイルを編集する。

vi /etc/stork/server.env

# database settings
STORK_DATABASE_HOST=PostgreSQL稼働サーバーのIPアドレス
STORK_DATABASE_PORT=PostgreSQLのポート
STORK_DATABASE_NAME=stork
STORK_DATABASE_USER_NAME=ユーザー名
# empty password is set to avoid prompting user for password to database
STORK_DATABASE_PASSWORD=パスワード

# ReST API settings
# STORK_REST_HOST=
# STORK_REST_PORT=
# STORK_REST_TLS_CERTIFICATE=
# STORK_REST_TLS_PRIVATE_KEY=
# STORK_REST_TLS_CA_CERTIFICATE=
STORK_REST_STATIC_FILES_DIR=/usr/share/stork/www

Nginxの設定

サンプルファイルをコピーする。

cp /usr/share/stork/examples/nginx-stork.conf /etc/nginx/sites-available/

内容を編集する。

vi /etc/nginx/sites-available/nginx-stork.conf

Nginxに反映させる

ln -s /etc/nginx/sites-available/nginx-stork.conf /etc/nginx/sites-enabled/stork

service nginx restart

 

 

 

タグ

コメント