DHCP Server with isc-kea

Level: Intermediate Module: TCP/IP & Networking 5 min read Lesson 18 of 66

Overview

  • What you’ll learn: How DHCP works (DORA process), the difference between ISC DHCP and isc-kea, installing and configuring Kea DHCP4 on Ubuntu, subnet declarations, address pools, host reservations, option settings, and lease management.
  • Prerequisites: Lesson 17 – Setting Up BIND 9 DNS Server
  • Estimated reading time: 22 minutes

Introduction

The Dynamic Host Configuration Protocol (DHCP) automates the assignment of IP addresses, subnet masks, default gateways, DNS servers, and other network parameters to devices on a network. Without DHCP, every device would need its network settings configured manually — an impractical approach for networks of any significant size.

Kea is the modern, open-source DHCP server developed by ISC (Internet Systems Consortium) as the successor to the legacy ISC DHCP server. Kea uses a JSON-based configuration format, supports a REST API for management, and can store leases in a database (MySQL, PostgreSQL, or Cassandra) for high-availability deployments.

In this lesson, you will learn how the DHCP protocol works, install and configure Kea DHCP4 on Ubuntu Server, set up address pools and host reservations, and manage DHCP leases.

How DHCP Works — The DORA Process

DHCP uses a four-step process known as DORA (Discover, Offer, Request, Acknowledge) to assign an IP address to a client:

  • Discover: The client broadcasts a DHCPDISCOVER message to find available DHCP servers.
  • Offer: DHCP servers respond with a DHCPOFFER containing a proposed IP address and configuration.
  • Request: The client broadcasts a DHCPREQUEST accepting one offer and informing other servers.
  • Acknowledge: The selected server sends a DHCPACK confirming the lease and configuration.
# Watch DHCP traffic with tcpdump
$ sudo tcpdump -i ens33 -n port 67 or port 68
10:00:01 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request, DISCOVER
10:00:01 IP 192.168.1.1.67 > 255.255.255.255.68: BOOTP/DHCP, Reply, OFFER
10:00:01 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request, REQUEST
10:00:01 IP 192.168.1.1.67 > 255.255.255.255.68: BOOTP/DHCP, Reply, ACK

# DHCP uses UDP ports 67 (server) and 68 (client)
$ ss -uln | grep -E '67|68'
UNCONN  0  0  0.0.0.0:67  0.0.0.0:*
UNCONN  0  0  0.0.0.0:68  0.0.0.0:*

Installing Kea DHCP Server

Kea is available in Ubuntu repositories. The package kea-dhcp4-server provides the IPv4 DHCP server.

# Install Kea DHCP4 server
$ sudo apt update
$ sudo apt install -y kea-dhcp4-server

# Verify the installation
$ kea-dhcp4 -V
2.2.0

# Check the service status
$ sudo systemctl status kea-dhcp4-server
● kea-dhcp4-server.service - Kea DHCPv4 Server
     Loaded: loaded (/lib/systemd/system/kea-dhcp4-server.service; enabled)
     Active: active (running)

# Configuration file location
$ ls /etc/kea/
kea-dhcp4.conf  kea-dhcp6.conf  kea-ctrl-agent.conf

Configuring Kea DHCP4

Kea uses a JSON configuration file. The main configuration for DHCPv4 is /etc/kea/kea-dhcp4.conf. You define interfaces to listen on, subnet declarations, address pools, options, and host reservations.

// /etc/kea/kea-dhcp4.conf
{
  "Dhcp4": {
    // Listen on this interface
    "interfaces-config": {
      "interfaces": ["ens33"]
    },

    // Lease database (memfile is simplest; use MySQL/PostgreSQL for HA)
    "lease-database": {
      "type": "memfile",
      "persist": true,
      "lfc-interval": 3600
    },

    // Default lease time (seconds)
    "valid-lifetime": 43200,
    "renew-timer": 21600,
    "rebind-timer": 37800,

    // Subnet declaration
    "subnet4": [
      {
        "id": 1,
        "subnet": "192.168.1.0/24",
        "pools": [
          { "pool": "192.168.1.100 - 192.168.1.200" }
        ],
        "option-data": [
          { "name": "routers", "data": "192.168.1.1" },
          { "name": "domain-name-servers", "data": "192.168.1.10, 8.8.8.8" },
          { "name": "domain-name", "data": "lab.example.com" },
          { "name": "domain-search", "data": "lab.example.com" }
        ],

        // Static reservations by MAC address
        "reservations": [
          {
            "hw-address": "00:0c:29:aa:bb:cc",
            "ip-address": "192.168.1.20",
            "hostname": "web-server"
          },
          {
            "hw-address": "00:0c:29:dd:ee:ff",
            "ip-address": "192.168.1.30",
            "hostname": "db-server"
          }
        ]
      }
    ]
  }
}

# Validate the configuration
$ kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
INFO  DCTL_CONFIG_FILE Configuration file: /etc/kea/kea-dhcp4.conf
INFO  DHCP4_CONFIG_COMPLETE DHCPv4 server configuration complete.

# Restart to apply
$ sudo systemctl restart kea-dhcp4-server

Managing DHCP Leases

Kea stores lease information in its lease database. With the memfile backend, leases are stored in a CSV file. You can inspect, query, and manage leases using the Kea shell or by examining the lease file directly.

# View the lease file (memfile backend)
$ cat /var/lib/kea/kea-leases4.csv
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id
192.168.1.100,00:0c:29:11:22:33,,43200,1704110400,1,0,0,client1,0,,0
192.168.1.101,00:0c:29:44:55:66,,43200,1704110400,1,0,0,client2,0,,0

# Monitor DHCP activity in the log
$ sudo journalctl -u kea-dhcp4-server -f
DHCP4_LEASE_ALLOC [hwtype=1 00:0c:29:11:22:33] lease 192.168.1.100 allocated
DHCP4_LEASE_ALLOC [hwtype=1 00:0c:29:44:55:66] lease 192.168.1.101 allocated

# Force a client to renew its DHCP lease
$ sudo dhclient -r ens33    # Release current lease
$ sudo dhclient ens33       # Request new lease

# Alternatively with networkctl
$ sudo networkctl renew ens33

Key Takeaways

  • DHCP automates IP address assignment using the DORA process (Discover, Offer, Request, Acknowledge) over UDP ports 67 and 68.
  • Kea is the modern DHCP server from ISC, using JSON configuration and supporting database backends for high availability.
  • Subnet declarations define address pools, DHCP options (gateway, DNS, domain), and lease lifetimes for each network segment.
  • Host reservations map MAC addresses to fixed IP addresses, ensuring critical servers always receive the same address.
  • Validate configurations with kea-dhcp4 -t before restarting, and monitor lease activity through journal logs and the lease file.

What’s Next

In Lesson 19, you will learn Firewall with ufw and iptables — how to control network traffic, define allow and deny rules, and protect your server using both the simplified ufw interface and the powerful iptables framework.

繁體中文

概述

  • 學習目標:DHCP 的運作方式(DORA 過程)、ISC DHCP 與 isc-kea 的區別、在 Ubuntu 上安裝和設定 Kea DHCP4、子網宣告、位址池、主機保留、選項設定和租約管理。
  • 先決條件:第 17 課 – 設定 BIND 9 DNS 伺服器
  • 預計閱讀時間:22 分鐘

簡介

動態主機設定協定(DHCP)自動化了 IP 位址、子網遮罩、預設閘道、DNS 伺服器和其他網路參數到網路上裝置的分配。沒有 DHCP,每台裝置都需要手動設定其網路設定——對於任何有一定規模的網路來說,這是不切實際的方法。

Kea 是由 ISC(網際網路系統聯合會)開發的現代開源 DHCP 伺服器,作為舊版 ISC DHCP 伺服器的繼任者。Kea 使用基於 JSON 的設定格式,支援用於管理的 REST API,並可以將租約儲存在資料庫(MySQL、PostgreSQL 或 Cassandra)中以實現高可用性部署。

在本課程中,您將學習 DHCP 協定的運作方式,在 Ubuntu Server 上安裝和設定 Kea DHCP4,設定位址池和主機保留,並管理 DHCP 租約。

DHCP 的運作方式 — DORA 過程

DHCP 使用稱為 DORA(Discover、Offer、Request、Acknowledge)的四步驟過程來分配 IP 位址給用戶端:

  • Discover:用戶端廣播 DHCPDISCOVER 訊息以尋找可用的 DHCP 伺服器。
  • Offer:DHCP 伺服器回應 DHCPOFFER,包含建議的 IP 位址和設定。
  • Request:用戶端廣播 DHCPREQUEST 接受一個提議並通知其他伺服器。
  • Acknowledge:選定的伺服器發送 DHCPACK 確認租約和設定。

安裝 Kea DHCP 伺服器

Kea 可在 Ubuntu 儲存庫中取得。套件 kea-dhcp4-server 提供 IPv4 DHCP 伺服器。

設定 Kea DHCP4

Kea 使用 JSON 設定檔。DHCPv4 的主要設定位於 /etc/kea/kea-dhcp4.conf。您定義要監聽的介面、子網宣告、位址池、選項和主機保留。

管理 DHCP 租約

Kea 將租約資訊儲存在其租約資料庫中。使用 memfile 後端時,租約儲存在 CSV 檔案中。您可以使用 Kea shell 或直接檢查租約檔案來檢查、查詢和管理租約。

重要觀念

  • DHCP 使用 DORA 過程(Discover、Offer、Request、Acknowledge)透過 UDP 連接埠 67 和 68 自動化 IP 位址分配。
  • Kea 是 ISC 的現代 DHCP 伺服器,使用 JSON 設定並支援資料庫後端以實現高可用性。
  • 子網宣告為每個網路區段定義位址池、DHCP 選項(閘道、DNS、網域)和租約期限。
  • 主機保留將 MAC 位址對應到固定 IP 位址,確保關鍵伺服器始終獲得相同的位址。
  • 重新啟動前使用 kea-dhcp4 -t 驗證設定,並透過日誌和租約檔案監控租約活動。

下一步

在第 19 課中,您將學習使用 ufw 和 iptables 的防火牆——如何控制網路流量、定義允許和拒絕規則,以及使用簡化的 ufw 介面和強大的 iptables 框架來保護您的伺服器。

日本語

概要

  • 学習内容:DHCPの仕組み(DORAプロセス)、ISC DHCPとisc-keaの違い、UbuntuでのKea DHCP4のインストールと設定、サブネット宣言、アドレスプール、ホスト予約、オプション設定、リース管理。
  • 前提条件:レッスン17 – BIND 9 DNSサーバーのセットアップ
  • 推定読了時間:22分

はじめに

動的ホスト構成プロトコル(DHCP)は、ネットワーク上のデバイスへのIPアドレス、サブネットマスク、デフォルトゲートウェイ、DNSサーバー、その他のネットワークパラメータの割り当てを自動化します。DHCPがなければ、すべてのデバイスのネットワーク設定を手動で構成する必要があり、ある程度の規模のネットワークでは実用的ではありません。

KeaはISC(Internet Systems Consortium)がレガシーISC DHCPサーバーの後継として開発した、現代的なオープンソースDHCPサーバーです。KeaはJSONベースの設定形式を使用し、管理用REST APIをサポートし、高可用性デプロイメントのためにデータベース(MySQL、PostgreSQL、Cassandra)にリースを保存できます。

このレッスンでは、DHCPプロトコルの仕組みを学び、Ubuntu ServerにKea DHCP4をインストール・設定し、アドレスプールとホスト予約をセットアップし、DHCPリースを管理します。

DHCPの仕組み — DORAプロセス

DHCPはDORA(Discover、Offer、Request、Acknowledge)として知られる4段階のプロセスを使用して、クライアントにIPアドレスを割り当てます:

  • Discover:クライアントがDHCPDISCOVERメッセージをブロードキャストして、利用可能なDHCPサーバーを検索します。
  • Offer:DHCPサーバーが提案されたIPアドレスと設定を含むDHCPOFFERで応答します。
  • Request:クライアントが1つのオファーを受け入れるDHCPREQUESTをブロードキャストし、他のサーバーに通知します。
  • Acknowledge:選択されたサーバーがリースと設定を確認するDHCPACKを送信します。

Kea DHCPサーバーのインストール

KeaはUbuntuリポジトリで利用できます。kea-dhcp4-serverパッケージがIPv4 DHCPサーバーを提供します。

Kea DHCP4の設定

KeaはJSON設定ファイルを使用します。DHCPv4のメイン設定は/etc/kea/kea-dhcp4.confにあります。リッスンするインターフェース、サブネット宣言、アドレスプール、オプション、ホスト予約を定義します。

DHCPリースの管理

Keaはリース情報をリースデータベースに保存します。memfileバックエンドでは、リースはCSVファイルに保存されます。Keaシェルを使用するか、リースファイルを直接調べることで、リースを検査、クエリ、管理できます。

重要ポイント

  • DHCPはDORAプロセス(Discover、Offer、Request、Acknowledge)を使用してUDPポート67と68経由でIPアドレス割り当てを自動化します。
  • KeaはISCの現代的なDHCPサーバーで、JSON設定を使用し、高可用性のためのデータベースバックエンドをサポートします。
  • サブネット宣言は、各ネットワークセグメントのアドレスプール、DHCPオプション(ゲートウェイ、DNS、ドメイン)、リース期間を定義します。
  • ホスト予約はMACアドレスを固定IPアドレスにマップし、重要なサーバーが常に同じアドレスを受け取ることを保証します。
  • 再起動前にkea-dhcp4 -tで設定を検証し、ジャーナルログとリースファイルでリース活動を監視してください。

次のステップ

レッスン19では、ufwとiptablesによるファイアウォールを学びます——ネットワークトラフィックの制御、許可および拒否ルールの定義、シンプルなufwインターフェースと強力なiptablesフレームワークの両方を使用したサーバーの保護方法を学びます。

You Missed