DHCP 動態分配 IP 服務

參考資訊

  • pinfo dhcpd.conf
  • Red Hat Linux 網路及系統管理指南 2nd Edition (學貫, 986-7693-68-X)

所需套件

  • dhcp-3.0pl2-6.14 (Redhat Enterprise Linux 3 ES)

動態分配 IP 可以讓管理者集中控管 IP 的使用狀況和發佈的範圍,而在 Client 端也不用記住自己的 IP 位址,對於一般操作者來說選是一件不錯的服務。

靜態設定 IP 和動態取得在於前者需要了解當地的網路資訊而設定,這些資訊如:IP、Gateway、DNS、Netmask ... 等等資訊,而若是不知道的話就會無法和網路連結;後者在於使用者的電腦會直接去跟 DHCP Servre 取得網路資訊,這些資訊也包含了網域的設定,而 DHCP Server 收到 Client 的要求之後就會發佈一組未使用的 IP 下去,如此一來就不用每次都很麻煩的設定了。

套件查尋

查看系統是否已安裝了 dhcp 套件,如果沒有就安裝一下。

[root@rhel200 root]# rpm -qa | grep dhcp
dhcp-3.0pl2-6.14
[root@rhel200 root]#

編輯設定檔 (/etc/dhcpd.conf)

/etc/dhcpd.conf 其是要靠人工一個字一個 key 出來似乎太強人所難,所幸在安好 dhcp 套件之後會連範例檔都一起安裝上去,所以我們可以把範例檔直接拿來修改既可。

[root@rhel200 root]# cd /etc/
[root@rhel200 etc]# cp /usr/share/doc/dhcp-3.0pl2/dhcpd.conf.sample ./dhcpd.conf

dhcp 的範例檔是放在 /usr/share/doc/dhcp-3.0pl2/dhcpd.conf.sample,把他複製到 /etc 下並更名為 dhcpd.conf 就可以了,接下來就來開始編輯了。

[root@rhel200 etc]# vi /etc/dhcpd.conf
__________________________________________________________ ddns-update-style interim; ignore client-updates; # 以下 subnet 先指定是那一個區段 subnet 192.168.1.0 netmask 255.255.255.0 { # --- 預設閘道 (gateway) option routers 192.168.1.1; option subnet-mask 255.255.255.0; # --- 設定 nis domain, 用不到所以註解 # option nis-domain "abc.com.tw"; # --- 設定 domain option domain-name "abc.com.tw"; # --- 設定 DNS Server option domain-name-servers 192.168.2.69; 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; # --- 設定 DHCP 分發的 IP 範圍 range dynamic-bootp 192.168.1.100 192.168.1.200; 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 12:34:56:78:AB:CD; # fixed-address 207.175.42.254; # } }
__________________________________________________________
[root@rhel200 etc]#

設定好之後就可以啟動 DHCP 的服務了。

[root@rhel200 etc]# service dhcpd start
Starting dhcpd: [ OK ]
[root@rhel200 etc]#

Client 設定

  • Windows 設定:開啟網路卡的 TCP/IP 內容,設定為自動取得 IP 既可。

  • Linux 設定:使用 netconfig 來設定為 dhcp,再重新啟動網路服務既可。
[root@mirror root]# netconfig
[root@mirror root]#

設定完成之後再重新啟動網路服務。

[root@mirror root]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Setting network parameters: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@mirror root]#

02/28/2005

Index