dhcpdをインストールする


……というわけで、PS3を設置する時にDHCPでアドレスを取得するように設定してみたところ
なぜかブロードバンドルータDHCPサーバが上手く機能していないことが発覚したので、
面倒になって自宅BSDサーバにdhcpdをインストールすることにしました。
ちなみに上記現象はDHCPサーバの設定自体を間違えていたとかそういう次元ではなく、
工場出荷時状態に戻したところで同様の問題が発生しているという事態に陥っていたため、
この際だからここの記事のネタにしてしまえと今回の作業に至った次第です。


今回は超手堅くisc-dhcpdをインストールすることにします。
いざというときのリファレンスも多いし、ほぼデファクトスタンダードですしね。
というわけで早速インストール開始。
まずはportsからisc-dhcpdを捜し出してきてインストールします。

# cd /usr/ports/net/isc-dhcpd31-server
# make install clean

makeする際のオプションは

の3つを指定することにします。個人的にはPARANOIAとJAILは被ってるんじゃないか……
と思っていたんですが、rc.confに書き込む設定項目の具体的な機能を調べるに当たって
ソースコードを軽く読み流したところ、どうやらJAILはFTPDなんかによくあるchrootのことのようです。
つまり或る特定のディレクトリをさも/であるかのように見せかける……というアレです。


さてさて。インストール時に「rc.confにこれを加えておけ」と幾つか表示されるので、
次はこれらを/etc/rc.confに追加します。

#
#### dhcpd settings
#
dhcpd_enable="YES"                          # dhcpd enabled?
dhcpd_flags="-q"                            # command option(s)
dhcpd_conf="/usr/local/etc/dhcpd.conf"      # configuration file
dhcpd_ifaces=""                             # ethernet interface(s)
dhcpd_withumask="022"                       # file creation mask
#
#### dhcpd chroot settings
#
dhcpd_chuser_enable="YES"                   # runs w/o privileges?
dhcpd_withuser="dhcpd"                      # user name to run as
dhcpd_withgroup="dhcpd"                     # group name to run as
dhcpd_chroot_enable="YES"                   # runs chrooted?
dhcpd_devfs_enable="YES"                  # use devfs if available?
#dhcpd_makedev_enable="YES"                # use MAKEDEV instead?
dhcpd_rootdir="/var/db/dhcpd"               # directory to run in
#dhcpd_includedir=""               # directory with config-files to include
#dhcpd_flags="-early_chroot"                 # needs full root

部分的に僕が入れたコメントも混じってます。
とりあえず意図的に外したのは

#dhcpd_makedev_enable="YES"                # use MAKEDEV instead?
#dhcpd_includedir=""               # directory with config-files to include
#dhcpd_flags="-early_chroot"                 # needs full root

の3つ。dhcpd_devfs_enableとdhcpd_makedev_enableはどちらか片方のみを
受け入れる事になっているようなので、今回はmakedev_enableを外すことにしました。
残る2つ……dhcpd_includedirはchroot時にデフォルト以外に
chrootされたディレクトリの下にコピーするディレクトリを指定する項目です。
dhcpd_flagsはchrootする際に設定するフラグを書き込んでおく項目で、
デフォルトの"early_chroot"はdhcpd_rootdirが定義されている場合に、
起動時にオプションの解釈を終えたら即chrootするようになるようです。


さて、次はdhcpdの設定ファイルを書き換えます。
今回の方針は

  • 192.168.2.100-200を提供する。サブネットマスクは24ビット
  • 静的に提供するアドレスはなし

……という極めて単純なものだったので、特に説明も入れずにサクッと紹介。
そうそう、インストール直後は/usr/local/etc/dhcpd.conf.sampleしかないので
これを/usr/local/etc/dhcpd.confにコピーしてから作業を行います。

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "local.privatenet";
option domain-name-servers 192.168.2.254;

default-lease-time 3600;
max-lease-time 86400;

# Use this to enble / disable dynamic dns updates globally.
ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# ad-hoc DNS update scheme - set to "none" to disable dynamic DNS updates.
#ddns-update-style ad-hoc;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local0;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

# A slightly different configuration for an internal subnet.
subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.100 192.168.2.200;
  option domain-name-servers 192.168.2.1
  option domain-name "local.privatenet";
  option routers 192.168.2.1;
  option broadcast-address 192.168.2.255;
  default-lease-time 3600;
  max-lease-time 86400;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
#  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}
#
#shared-network 224-29 {
#  subnet 10.17.224.0 netmask 255.255.255.0 {
#    option routers rtr-224.example.org;
#  }
#  subnet 10.0.29.0 netmask 255.255.255.0 {
#    option routers rtr-29.example.org;
#  }
#  pool {
#    allow members of "foo";
#    range 10.17.224.10 10.17.224.250;
#  }
#  pool {
#    deny members of "foo";
#    range 10.0.29.10 10.0.29.230;
#  }
#}

こんな感じ。実を言うと後半の'class'のあたりからは丸ごと削除してしまっても構いません。
個人的に興味がある設定項目だったのでコメントとして残してあるだけです。


後は起動させて動作確認すれば設定完了です。

# /usr/local/etc/rc.d/isc-dhcpd start
Starting dhcpd.
#

これで起動完了。動作確認は実際にIPアドレスを取得してみればはっきりします。
Windows端末でIPアドレスを自動的に取得するように設定した上で……

>ipconfig /renew

Windows IP Configuration


Ethernet adapter ローカル エリア接続:

        Connection-specific DNS Suffix  . : local.privatenet
        IP Address. . . . . . . . . . . . : 192.168.2.100
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.2.1

>ipconfig /all

 --------------------------- 略 -------------------------------

Ethernet adapter ローカル エリア接続:

        Connection-specific DNS Suffix  . : local.privatenet
        Description . . . . . . . . . . . : Realtek RTL8168C(P)/8111C(P) PCI-E Gigabit Ethernet NIC
        Physical Address. . . . . . . . . : 00-24-1D-8D-02-DC
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.168.2.100
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.2.1
        DHCP Server . . . . . . . . . . . : 192.168.2.254
        DNS Servers . . . . . . . . . . . : 192.168.2.1
                                            192.168.2.254
        Lease Obtained. . . . . . . . . . : 2009年9月28日 0:06:56
        Lease Expires . . . . . . . . . . : 2009年9月28日 1:06:56

無事にアドレスが取れたようです。
これで今後は携帯ゲーム機・据え置きゲーム機は全てDHCPIPアドレスを取得してくれば
大いなる無駄な手間は省けそうです。良かった良かった(笑