Raspberry Pi BrusterにDHCPサーバーを設定する

2019-06-20にリリースされたRaspbian BusterにDHCPサーバーをインストールしてみたのでメモ。
isc-dhcp-server が動作しました。

Raspbian Buster

Raspberry Pi3にRaspbian Buster Lite をインストールしました。

Raspbianダウンロードサイト

pi@raspi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

DHCPサーバ isc-dhcp-serverのインストール

$ sudo apt install isc-dhcp-server

バージョン

$ sudo dpkg -l | grep dhcp
ii  dhcpcd5                        1:7.0.8-0.1+rpt1            armhf        DHCPv4, IPv6RA and DHCPv6 client with IPv4LL support
ii  isc-dhcp-client                4.4.1-2                     armhf        DHCP client for automatically obtaining an IP address
ii  isc-dhcp-common                4.4.1-2                     armhf        common manpages relevant to all of the isc-dhcp packages
ii  isc-dhcp-server                4.4.1-2                     armhf        ISC DHCP server for automatic IP address assignment

/etc/dhcp/dhcpd.conf の編集

$ sudo vi /etc/dhcp/dhcpd.conf
# コメントアウト
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

# コメントを外す
authoritative;

# 割り当てるアドレス範囲追加
subnet 192.168.12.0 netmask 255.255.255.0 {
 range 192.168.12.3 192.168.12.99;
 option routers 192.168.12.1;
 option domain-name-servers 192.168.12.1, 192.168.12.2;
 ignore declines;
}

/etc/default/isc-dhcp-server の編集

$ sudo vi /etc/default/isc-dhcp-server
# eth0を使用
INTERFACESv4="eth0"

起動コマンド

Start/Stop/restart daemon
$ sudo systemctl start isc-dhcp-server.service
$ sudo systemctl stop isc-dhcp-server.service
$ sudo systemctl restart isc-dhcp-server.service

Enable/Disable service
$ sudo systemctl enable isc-dhcp-server.serice
$ sudo systemctl disable isc-dhcp-server.serice

Check status
$ sudo systemctl status isc-dhcp-server.service

$ sudo systemctl status -l | grep dhcpd

IPアドレスのリースの確認

/var/lib/dhcp/dhcpd.leases に記録されています。

$cat /var/lib/dhcp/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.4.1

# authoring-byte-order entry is generated, DO NOT DELETE
authoring-byte-order little-endian;

lease 192.168.12.3 {
  starts 1 2019/07/01 06:29:12;
  ends 1 2019/07/01 06:39:12;
  tstp 1 2019/07/01 06:39:12;
  cltt 1 2019/07/01 06:29:12;
  binding state active;
  next binding state free;
  rewind binding state free;
  hardware ethernet ec:f4:bb:33:ce:1c;
  uid "\001\354\364\3327\523.";
  set vendor-class-identifier = "MSFT 5.0";
  client-hostname "Foo-HogeHoge123";
}
server-duid "\000\001\000\001$\254g\014\123'\967<\227(";

lease 192.168.12.3 {
  starts 1 2019/07/01 06:29:12;
  ends 1 2019/07/01 06:39:12;
  tstp 1 2019/07/01 06:39:12;
  cltt 1 2019/07/01 06:29:12;
  binding state free;
  hardware ethernet ec:f4:bb:33:ce:1c;
  uid "\001\354\364\3327\523.";
  set vendor-class-identifier = "MSFT 5.0";
}