DHCPサーバー構築(dhcp)

最終更新日: 2009.12.29

<<トップページ <<新着情報 <<質問掲示板 <<アンケート <<リンク集 <<サイト内検索 <<管理人へメール <<Fedoraで自宅サーバー構築

■概要

LinuxサーバーをDHCPサーバーとして、内部のクライアントマシンへIPアドレスを自動的に割当てるようにする。

【前提とするネットワーク条件】
ネットワークアドレス:192.168.1.0/24
LinuxサーバーIPアドレス:192.168.1.1固定
クライアントIPアドレス:192.168.1.2〜192.168.1.254


■DHCPサーバーインストール

[root@centos ~]# yum -y install dhcp ← DHCPサーバーインストール

■DHCPサーバー設定

[root@centos ~]# /bin/cp /usr/share/doc/dhcp-*/dhcpd.conf.sample /etc/dhcpd.conf
 ← DHCPサーバー設定ファイルをサンプルより作成

[root@centos ~]# vi /etc/dhcpd.conf ← DHCPサーバー設定ファイル編集
ddns-update-style interim;
ignore client-updates;
not authoritative; ← 追加(以下のような警告メッセージがログに出力場合の対処)

If this DHCP server is authoritative for that subnet,
please write an `authoritative;' directive either in the
subnet declaration or in some scope that encloses the
subnet declaration - for example, write it at the top
of the dhcpd.conf file.

subnet 192.168.1.0 netmask 255.255.255.0 { ← 自身の環境にあわせて編集

# --- default gateway
        option routers                  192.168.1.1; ← ルーター経由接続環境の場合はルーターのIPアドレスを指定
                                                          PPPoE接続環境の場合はサーバーのIPアドレスを指定
        option subnet-mask              255.255.255.0;

        #option nis-domain              "domain.org"; ← コメントアウト
        #option domain-name             "domain.org"; ← コメントアウト
        option domain-name-servers      192.168.1.1;
 ← ルーター経由接続環境の場合はルーターのIPアドレスを指定
        option domain-name-servers      XXX.XXX.XXX.XXX,XXX.XXX.XXX.XXX;
 ← PPPoE接続環境の場合はプロバイダから通知されたDNSサーバーのIPアドレス(プライマリ,セカンダリ)を指定

        option time-offset              -18000; # Eastern Standard Time
#       option ntp-servers              192.168.1.1;
#       option netbios-name-servers     192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#       option netbios-node-type 2;

        range dynamic-bootp 192.168.1.2 192.168.1.254; ← 割当てるIPアドレスを指定(192.168.1.2〜192.168.1.254)
        default-lease-time 21600;
        max-lease-time 43200;

        # we want the nameserver to appear at a fixed address
        #host ns {
        #       next-server marvin.redhat.com;
        #       hardware ethernet XX:XX:XX:XX:XX:XX;
        #       fixed-address 207.175.42.254;
        #}
        }
}
        以下はホストwin-client1にプライベートIPアドレスを固定で割当てる場合追加
        host win-client1 { ← ホスト名
               hardware ethernet XX:XX:XX:XX:XX:XX; ← win-client1に装着しているネットワークアダプタのMACアドレス※
               fixed-address 192.168.1.10; ← win-client1に固定で割当てるIPアドレス
        }
※ネットワークアダプタのMACアドレスは、「ipconfig /all」(Windowsの場合)、「ifconfig」(Linuxの場合)で確認

■DHCPサーバー起動

[root@centos ~]# /etc/rc.d/init.d/dhcpd start ← DHCPサーバー起動
dhcpd を起動中:                                            [  OK  ]

[root@centos ~]# chkconfig dhcpd on ← DHCPサーバー自動起動設定

[root@centos ~]# chkconfig --list dhcpd ← DHCPサーバー自動起動設定確認
dhcpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off ← ランレベル2〜5のonを確認


■DHCPサーバー確認(クライアントがWindowsの場合)

(1)クライアント側でDHCPサーバーからIPアドレスを自動取得するように設定
「マイ ネットワーク」右クリック⇒「プロパティ」⇒「ローカル エリア接続」⇒「プロパティ」ボタン⇒「インターネットプロトコル(TCP/IP)」⇒「IPアドレスを自動的に取得」、「DNSサーバーのIPアドレスを自動的に取得」にチェック⇒OKボタン押下

(2)クライアント側でのDHCPサーバーからのIPアドレス取得状況確認
C:\Documents and Settings\fedora>ipconfig /all ← IPアドレス割当て状況確認
Ethernet adapter ローカル エリア接続:

        Connection-specific DNS Suffix  . : centossrv.com
        Description . . . . . . . . . . . : ADMtek ADM9511 10/100Mbps Fast Ethernet Adapter
        Physical Address. . . . . . . . . : XX-XX-XX-XX-XX-XX
        Dhcp Enabled. . . . . . . . . . . : Yes ← DHCPサーバーが有効であることを示す
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.168.1.10 ← DHCPサーバーから割り当てられたIPアドレス
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.1.1 ← DHCPサーバーから割り当てられたルーターのIPアドレス
        DHCP Server . . . . . . . . . . . : 192.168.1.1 ← DHCPサーバーのIPアドレス
        DNS Servers . . . . . . . . . . . : XXX.XXX.XXX.XXX ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス
                                            XXX.XXX.XXX.XXX ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス
        Lease Obtained. . . . . . . . . . : 2004年8月30日 0:14:26
        Lease Expires . . . . . . . . . . : 2004年8月30日 6:14:26

■DHCPサーバー確認(クライアントがLinuxの場合)

(1)クライアント側でDHCPサーバーからIPアドレスを自動取得するように設定
[root@client ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 ← ネットワーク設定ファイル編集
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp

[root@client ~]# /etc/rc.d/init.d/network reload ← ネットワーク設定反映
インターフェース eth0を終了中:                             [  OK  ]
ループバックインターフェース を終了中                      [  OK  ]
ネットワークパラメーターを設定中:                          [  OK  ]
ループバックインターフェイスを呼び込み中                   [  OK  ]
インターフェース eth0を活性化中:                           [  OK  ]

(2)クライアント側でのDHCPサーバーからのIPアドレス取得状況確認
[root@client ~]# ifconfig eth0 ← IPアドレス割当て状況確認
eth0      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0 ← DHCPサーバーから割り当てられたIPアドレス
          inet6 addr: fe80::a00:46ff:fe28:e57f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2516 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1725 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3000964 (2.8 Mb)  TX bytes:159154 (155.4 Kb)

[root@client ~]# cat /etc/resolv.conf | grep nameserver ← 問合せ先DNSサーバーのIPアドレス確認
nameserver XXX.XXX.XXX.XXX ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス
nameserver XXX.XXX.XXX.XXX ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス

[root@client  ~]# route -n ← ルーターのIPアドレス確認
Kernel IP routing table
Destination     Gateway       Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0       255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0       255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.1.1   0.0.0.0         UG    0      0        0 eth0 ← DHCPサーバーから割り当てられたルーターのIPアドレス



▲このページのトップへ戻る

LPIロゴ Copyright© 2005-2010 fallenangels, All rights reserved.
ご自由にリンクしてください(連絡は不要です)
本ページへのご意見・ご要望、誤字・脱字・リンク切れ等のご連絡はこちらからお願いします