LS-GL: debian: DHCP サーバ


家庭内 LAN 向け DHCP サーバをたてる。

インストールするパッケージは?

相変わらず debian は良くわかっていない。
apt-cache で探す。
ude:~# apt-cache search dpcpd
ude:~# apt-cache search dpcp
ude:~# apt-cache search DHCP
autodns-dhcp - Automatic DNS updates for DHCP
backuppc - high-performance, enterprise-grade system for backing up PCs
bootp - server for the bootp protocol with DHCP support
dhcp - DHCP server for automatic IP address assignment
dhcp-client - DHCP Client
	:
ude:~#
dhcp パッケージをインストールすれば良さそう。

dhcp のインストール

ude:~# apt-get install dhcp
Reading Package Lists... Done
Building Dependency Tree... Done
The following NEW packages will be installed:
  dhcp
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 114kB of archives.
After unpacking 336kB of additional disk space will be used.
Get:1 http://ftp.jp.debian.org sarge/main dhcp 2.0pl5-19.1sarge2 [114kB]
Fetched 114kB in 1s (112kB/s)
Selecting previously deselected package dhcp.
(Reading database ... 11010 files and directories currently installed.)
Unpacking dhcp (from .../dhcp_2.0pl5-19.1sarge2_arm.deb) ...
Setting up dhcp (2.0pl5-19.1sarge2) ...
Generating /etc/default/dhcp...

Please note that if you are installing the DHCP server for the first
time you need to configure it first. Please stop (/etc/init.d/dhcp
stop) the DHCP server daemon, edit /etc/dhcpd.conf to suit your needs
and particular configuration, and restart the DHCP server daemon
(/etc/init.d/dhcp start).

You also need to edit /etc/default/dhcp to specify the interfaces dhcpd
should listen to. By default it listens to eth0.

NOTE: dhcpd's messages are being sent to syslog. Look there for
diagnostics messages.

Starting DHCP server: dhcpd failed to start - check syslog for diagnostics.

ude:~#

dhcp の設定

/etc/dhcpd.conf と /etc/default/dhcp との設定が必要。

DHCP サーバの停止

ude:~# /etc/init.d/dhcp stop
Stopping DHCP server: dhcp.
ude:~#

/etc/dhcpd.conf

内向きサーバから持ってくる
ude:~# mv /etc/dhcpd.conf{,.orig}
ude:~# ftp fs.yamasita.jp
Connected to giga.yamasita.jp.
220 ProFTPD 1.2.10 Server (ProFTPD Default Installation) [192.168.1.32]
Name (fs.yamasita.jp:yasunari):
331 Password required for yasunari.
Password:
230 User yasunari logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> lcd /
Local directory now /
ftp> get /etc/dhcpd.conf
local: ./etc/dhcpd.conf remote: /etc/dhcpd.conf
200 PORT command successful
150 Opening BINARY mode data connection for /etc/dhcpd.conf (3526 bytes)
226 Transfer complete.
3526 bytes received in 0.01 secs (466.7 kB/s)
ftp> bye
221 Goodbye.
ude:~#

/etc/default/dhcp

the interfaces dhcpd should listen to. は、、、
ude:~# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:16:01:35:06:7A
          inet addr:192.168.1.38  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:470435 errors:0 dropped:0 overruns:0 frame:0
          TX packets:78905 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:512
          RX bytes:678002760 (646.5 MiB)  TX bytes:5744023 (5.4 MiB)
          Interrupt:21

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

ude:~#
eth0。
ude:~# cd /etc/default/
ude:/etc/default# mv dhcp{,.orig}
ude:/etc/default# cp dhcp.orig dhcp
ude:/etc/default# vi dhcp
	:
ude:/etc/default# diff dhcp.orig dhcp
11c11
< INTERFACES=""
---
> INTERFACES="eth0"
ude:/etc/default#

DHCP サーバの起動

ude:/etc/default# /etc/init.d/dhcp start
Starting DHCP server: dhcpd failed to start - check syslog for diagnostics.
ude:/etc/default#
おや?
syslog を見てみる
ude:/etc/default# pushd /var/log/
ude:/var/log# less daemon.log
	:
	:
Jan 18 22:25:00 ude dhcpd: No subnet declaration for eth0 (192.168.1.38).
Jan 18 22:25:01 ude dhcpd: Please write a subnet declaration in your dhcpd.conf file for the
Jan 18 22:25:01 ude dhcpd: network segment to which interface eth0 is attached.
Jan 18 22:25:01 ude dhcpd: exiting.
Jan 18 22:33:04 ude dhcpd: /etc/dhcpd.conf line 1: expecting a parameter or declaration.
Jan 18 22:33:04 ude dhcpd: ddns-update-style
Jan 18 22:33:04 ude dhcpd: ^
Jan 18 22:33:04 ude dhcpd: Configuration file errors encountered -- exiting
Jan 18 22:33:04 ude dhcpd: exiting.
(END)
ががぁー。dhcpd.conf の書式が違うのかぁ、、、

/etc/dhcpd.conf の編集

ddns-update-style の記述を消す。

DHCP サーバの再起動

ude:/etc# /etc/init.d/dhcp start
Starting DHCP server: dhcpd.
ude:/etc#
今度はうまく行った。

動作確認

DHCP クライアントの Windows PC を起動する
ude:/etc# tail -f /var/log/daemon.log
	:
Jan 18 22:44:54 ude dhcpd: DHCPDISCOVER from 08:00:46:e0:xx:yy via eth0
Jan 18 22:44:54 ude dhcpd: DHCPOFFER on 192.168.1.29 to 08:00:46:e0:xx:yy via eth0
Jan 18 22:44:54 ude dhcpd: DHCPDISCOVER from 08:00:46:e0:xx:yy via eth0
Jan 18 22:44:54 ude dhcpd: DHCPOFFER on 192.168.1.29 to 08:00:46:e0:xx:yy via eth0
Jan 18 22:44:54 ude dhcpd: DHCPREQUEST for 192.168.1.29 from 08:00:46:e0:xx:yy via eth0
Jan 18 22:44:54 ude dhcpd: DHCPACK on 192.168.1.29 to 08:00:46:e0:xx:yy via eth0
(一部伏せ字)
きちんと 192.168.1.29 を割り当てたようだ。
DHCP サーバ化、完了


LS-GL: debian: rsync のインストール
ハックの記録
LinkStation/玄箱 をハックしよう

LS-GL: debian: デフォルトエディタ

Copyright (C) 2007 Yasunari Yamashita. All Rights Reserved.
yasunari @ yamasita.jp 山下康成@京都府向日市