萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 網路安全 >  >> 路由器知識 >> 路由器設定 >> Cisco 思科路由器

Cisco 路由器 DHCP Server 配置範例:地址池、閘道、DNS、租期、排除地址一鍵部署

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 ipOption 3,客戶端預設閘道
dns-server ip1 ip2 ...Option 6,DNS 伺服器 (最多 8 個)
domain-name nameOption 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 流程)

進階場景

  • 多 VLAN DHCP:每個 VLAN 介面配置 ip helper-address ,DHCP Server 依 giaddr 選擇對應 Pool。
  • 靜態綁定 (MAC-IP 固定):host 192.168.2.50 255.255.255.0 → hardware-address 0011.2233.4455 → client-name printer1。
  • DHCP Relay Agent:ip helper-address 192.168.100.10 在 L3 介面下,轉發 DHCP 請求至集中 Server。
copyright © 萬盛學電腦網 all rights reserved