Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux 架設 DHCP 動態 IP 服務完整設定指南

編輯:關於 Linux

所謂動態 IP 即指 DHCP(Dynamic Host Configuration Protocol)服務。相較於手動配置靜態 IP,在主機數量龐大的區域網路環境中,DHCP 能自動分配、管理 IP 位址,有效避免 IP 衝突與管理負擔。本文將詳細說明如何在 Linux 系統上配置 DHCP 服務。

DHCP 服務架構圖

核心設定檔:/etc/dhcpd.conf

DHCP 服務啟動時會讀取 /etc/dhcpd.conf 設定檔。以下提供一份實際可用的範例供參考:

ddns-update-style interim;
ignore client-updates;

subnet 192.168.25.0 netmask 255.255.255.0 {
    # 預設閘道
    option routers 192.168.25.15;
    option subnet-mask 255.255.255.0;
    # option nis-domain "uc88.domain";
    option domain-name "uc88.domain";
    option domain-name-servers 202.96.128.68, 192.168.25.15;
    option time-offset -18000; # Eastern Standard Time
    # option ntp-servers 192.168.1.1;
    # option netbios-name-servers 192.168.1.1;
    # --- 選擇 point-to-point 節點 (預設為 hybrid),除非非常了解 NetBIOS 否則勿修改
    # option netbios-node-type 2;

    range dynamic-bootp 192.168.25.100 192.168.25.254;
    default-lease-time 259200;
    max-lease-time 518400;

    # 固定 IP 範例(註解掉)
    # host ns {
    #     next-server marvin.redhat.com;
    #     hardware ethernet 12:34:56:78:AB:CD;
    #     fixed-address 207.175.42.254;
    # }
}

設定檔關鍵參數解析

  • 子網路遮罩:255.255.255.0
  • 廣播位址:192.168.25.255
  • 預設閘道:192.168.25.15
  • DNS 伺服器:202.96.128.68、192.168.25.15
  • 動態分配 IP 範圍:192.168.25.100 ~ 192.168.25.254
  • 預設租約時間:259200 秒(3 天)
  • 最大租約時間:518400 秒(6 天)

啟動前準備與服務啟動

  1. 建立租約資料庫檔案(若不存在):
    # touch /var/state/dhcp/dhcpd.leases
  2. 啟動 DHCP 服務:
    # /usr/sbin/dhcpd
    或使用 ntsysv 設定開機自動啟動。
  3. 指定網卡介面啟動(如 eth1):
    # /usr/sbin/dhcpd eth1

驗證客戶端是否取得 IP

  • Windows 98:執行 winipcfg
  • Windows 2000/XP 以上:執行 ipconfig /all

完成上述步驟即可在 Linux 上成功架設 DHCP 動態 IP 服務。雖然過程涉及指令操作,但對熟悉 Linux 的管理員而言屬於基礎配置任務。

Copyright © Windows教程網 All Rights Reserved