dhcpとは、Dynamic Host Configuration Protocolの略で、クライアントPCでIPアドレスを自動取得するという設定を行なうと、クライアントがIPアドレスを必要とした時点でIPアドレス割り当て要求の為のブロードキャストを行ないます。
DHCPサーバがこのブロードキャストを認識すると、発信したPCにIPアドレスを貸し出します。
dhcp機能は、最近のルータにほとんど存在していますが、あえてLinuxで構築する場合を紹介します。
# yum -y install dhcp |
![]() |
dhcpサービスでIPアドレスを固定付与する場合、NICのMACアドレスが必要になります |
サービスが使用する設定ファイルのディレクトリを確認
# cat /etc/init.d/dhcpd | grep config | grep dhcpd.conf
# config: /etc/dhcp/dhcpd.conf
バージョンによって、「/etc/dhcp/dhcpd.conf」「/etc/dhcpd.conf」だったりするので注意
設定ファイルの作成
上記で確認した設定ファイルを新規に作成します。
# vi /etc/dhcp/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
not authoritative;
log-facility local7;
not authoritative;
自分のネットワーク及びネットマスクを設定
subnet 192.168.1.0 netmask 255.255.255.0 {
デフォルトゲートウェイを設定(ルータのアドレス)
option routers 192.168.1.1;
ネットマスクを設定
option subnet-mask 255.255.255.0;
ドメイン名を設定
option domain-name "kajuhome.com";
ネームサーバのIPアドレスを設定(複数指定したい場合は「,」で区切る)
option domain-name-servers 192.168.1.5;
クライアントに割り当てるIPアドレスの範囲を指定(10〜19の10個を割り当てる)
range dynamic-bootp 192.168.1.10 192.168.1.19;
デフォルトリース時間(秒)
default-lease-time 21600;
最大リース時間(秒)
max-lease-time 43200;
ここから下は、特定のPCに固定のIPアドレスを割り当てたい時に指定します。
下記の例はクライアントホスト名"client1"のMACアドレス12:34:56:78:AB:CD;
にIPアドレス"192.168.1.10"を割り当てます。
host client1 {
MACアドレスを設定する
hardware ethernet 12:34:56:78:AB:CD;
割り当てたいIPアドレスを設定する
fixed-address 192.168.1.10;
}
}
|
dhcpを起動する # /etc/rc.d/init.d/dhcpd start dhcpd を起動中: [ OK ] |
起動時にdhcpを起動する # chkconfig dhcpd on 設定内容を確認 # chkconfig --list dhcpd dhcpd 0:オフ 1:オフ 2:オン 3:オン 4:オン 5:オン 6:オフ |
クライアントのネットワークの設定を以下の様にします。
『client1』よりWindowsのコマンドプロンプトを起動します 下記の「Connection-specific DNS Suffix」は、 DNSサーバの構築(BIND)を行なっている為、サーバ名が「kajuhome.com」になっています Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. IPアドレスの確認をします C:\Documents and Settings\client1>ipconfig /all Windows IP Configuration Ethernet adapter ローカル エリア接続: Connection-specific DNS Suffix . : kajuhome.com Description . . . . . . . . . . . : Intel(R) PRO/1000 Network Connection Physical Address. . . . . . . . . : 12-34-56-78-AB-CD Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.1.10 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1 DHCP Server . . . . . . . . . . . : 192.168.1.5 DNS Servers . . . . . . . . . . . : 192.168.1.5 Lease Obtained. . . . . . . . . . : 2005年7月14日 16:31:28 Lease Expires . . . . . . . . . . : 2005年7月14日 22:31:28 C:\Documents and Settings\client1> |
『client2』よりWindowsのコマンドプロンプトを起動します 下記の「Connection-specific DNS Suffix」は、 DNSサーバの構築(BIND)を行なっている為、サーバ名が「kajuhome.com」になっています Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. IPアドレスの確認をします C:\Documents and Settings\client2>ipconfig /all Windows IP Configuration Ethernet adapter ローカル エリア接続: Connection-specific DNS Suffix . : kajuhome.com Description . . . . . . . . . . . : AMD PCNET Family PCI Ethernet Adapter Physical Address. . . . . . . . . : 00-0C-xx-xx-xx-xx Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.1.12 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1 DHCP Server . . . . . . . . . . . : 192.168.1.5 DNS Servers . . . . . . . . . . . : 192.168.1.5 Lease Obtained. . . . . . . . . . : 2006年6月14日 15:04:12 Lease Expires . . . . . . . . . . : 2006年6月14日 21:04:12 C:\Documents and Settings\client2> |