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

Linux DHCP 伺服器快速配置實戰 (RHEL/CentOS 為例)

編輯:伺服器綜合

環境準備

  • 系統:RHEL 4 / CentOS 等紅帽系
  • 安裝光碟:第 4 盤含 dhcp-3.0.1-12_EL.i386.rpm

1. 安裝軟體包

mount /dev/cdrom /media/cdrom/
rpm -ivh /media/cdrom/RedHat/RPMS/dhcp-3.0.1-12_EL.i386.rpm

2. 配置檔案解析與編輯

# 複製樣本
cp /usr/share/doc/dhcp-3.0.1/dhcpd.conf.sample /etc/dhcpd.conf
vim /etc/dhcpd.conf

核心配置範例 (單網段 10.0.0.0/8)

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

subnet 10.0.0.0 netmask 255.0.0.0 {
    # --- default gateway
    option routers "10.0.0.1";
    option subnet-mask "255.0.0.0";
    # 可選項 (依需求取消註解)
    # option nis-domain "domain.org";
    # option domain-name "domain.org";
    # option domain-name-servers 10.0.0.1;
    # option time-offset -18000; # Eastern Standard Time
    # option ntp-servers 192.168.1.1;
    # option netbios-name-servers 192.168.1.1;
    # option netbios-node-type 2;

    range dynamic-bootp 10.0.0.100 10.0.0.200;
    default-lease-time 21600;
    max-lease-time 43200;

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

3. 多網卡介面綁定 (關鍵)

編輯 /etc/sysconfig/dhcpd:

DHCPDARGS="eth0 eth1"   # 指定 dhcpd 監聽的介面,空白則監聽所有

4. 啟動服務

service dhcpd start
# 設定開機自啟
chkconfig dhcpd on

5. 客戶端驗證

客戶端網卡設定為「自動獲取 IP 位址」,重新啟用網卡或重啟機器,執行 ipconfig /all (Windows) 或 ifconfig (Linux) 確認已取得正確 IP、閘道、DNS。

關鍵提醒

  • 確保 ddns-update-style 設定與 DNS 整合策略一致。
  • range 範圍勿與靜態 IP、排除範圍衝突。
  • 防火牆需開放 **UDP 67/68** 埠。
  • 多網段環境請參考「多 subnet / shared-network」進階配置。
Copyright © Windows教程網 All Rights Reserved