Cisco IOS 內建完整 DHCP Server 功能,可為內網客戶端動態分配 IP、閘道、DNS、WPAD 等參數。本文提供標準配置模板,涵蓋介面 IP、排除地址、地址池、選項推送、衝突檢測與綁定查看。
! 1. 介面 IP (內網閘道)
interface GigabitEthernet0/0
ip address 192.168.2.1 255.255.255.0
no shutdown
ip nat inside
! 2. 排除靜態配置設備 IP 範圍 (伺服器、印表機、AP、網管)
ip dhcp excluded-address 192.168.2.1 192.168.2.40
ip dhcp excluded-address 192.168.2.100 192.168.2.160
! 3. 定義地址池
ip dhcp pool VFAST1
network 192.168.2.0 255.255.255.0
default-router 192.168.2.1
dns-server 202.106.196.115 202.106.196.152
domain-name corp.local
lease 2 ! 租期 2 天 (單位:天,可加 hours minutes)
! 選項 150 (IP Phone TFTP Server)
option 150 ip 192.168.2.10
! 選項 252 (WPAD 自動代理)
option 252 ascii "https://wpad.corp.local/wpad.dat"
! 4. 衝突檢測 (Ping 檢查 2 次再分派)
ip dhcp ping packets 2
ip dhcp ping timeout 500
! 5. 綁定資料庫備份 (選擇性,防重啟丟失)
ip dhcp database flash:dhcp_bindings
! 或遠端
! ip dhcp database tftp://192.168.100.50/dhcp_bindings
| 指令 | 說明 |
|---|---|
ip dhcp excluded-address low high | 排除不動態分配的 IP 範圍,可多行疊加 |
network net mask | 定義子網範圍,自動計算可用地址 (排除 network/broadcast) |
default-router ip | Option 3,客戶端預設閘道 |
dns-server ip1 ip2 ... | Option 6,DNS 伺服器 (最多 8 個) |
domain-name name | Option 15,DNS 尾綴 |
lease {days [hours] [minutes] | infinite} | 租期,預設 1 天 |
option code {ip | ascii | hex} value | 推送任意 DHCP 選項 (150 Voice VLAN、252 WPAD、43 Vendor Specific) |
ip dhcp ping packets 2 | 分派前 Ping 檢測次數 (0 關閉,預設 2) |
ip dhcp conflict logging | 記錄衝突 IP 至閃存/遠端,show ip dhcp conflict 查看 |
show ip dhcp binding ! 當前租約清單 (IP、MAC、Lease Expiration、Type)
show ip dhcp pool ! 地址池統計 (Total/Used/Excluded)
show ip dhcp conflict ! 衝突 IP 列表
clear ip dhcp binding * ! 清除所有動態綁定 (謹慎)
clear ip dhcp conflict * ! 清除衝突記錄
debug ip dhcp server events ! 除錯 DHCP 交互 (DORA 流程)
ip helper-address ,DHCP Server 依 giaddr 選擇對應 Pool。host 192.168.2.50 255.255.255.0 → hardware-address 0011.2233.4455 → client-name printer1。ip helper-address 192.168.100.10 在 L3 介面下,轉發 DHCP 請求至集中 Server。