#035 · 2024-03-10✓ PASS
DHCP 配置
DHCP 动态主机配置协议实验,在 Cisco 路由器上配置 DHCP 服务器实现 IP 地址自动分配。
实验原理
DHCP(Dynamic Host Configuration Protocol)基于 UDP 协议,使用端口 67(服务器)和 68(客户端),自动为网络设备分配 IP、子网掩码、网关、DNS 等参数。
DHCP 工作流程(DORA)
| 步骤 | 消息 | 方向 | 说明 |
|---|---|---|---|
| 1 | Discover | 客户端 → 广播 | 寻找 DHCP 服务器 |
| 2 | Offer | 服务器 → 客户端 | 提供 IP 地址租约 |
| 3 | Request | 客户端 → 服务器 | 确认使用该 IP |
| 4 | Acknowledge | 服务器 → 客户端 | 最终确认,租约生效 |
DHCP vs 静态 IP
| 方式 | 优点 | 缺点 |
|---|---|---|
| DHCP | 自动化、减少配置错误、便于管理 | 依赖 DHCP 服务器可用性 |
| 静态 IP | 固定不变、适合服务器 | 手动配置繁琐、易出错 |
Cisco 路由器 DHCP 配置
基础配置
Router> enable
Router# configure terminal
# 排除静态地址(网关、服务器等)
Router(config)# ip dhcp excluded-address 192.168.1.1 192.168.1.10
# 创建 DHCP 地址池
Router(config)# ip dhcp pool LAN
Router(dhcp-config)# network 192.168.1.0 255.255.255.0
Router(dhcp-config)# default-router 192.168.1.1
Router(dhcp-config)# dns-server 8.8.8.8 114.114.114.114
Router(dhcp-config)# lease 7 # 租约 7 天
Router(dhcp-config)# domain-name local.lan
Router(dhcp-config)# exit
DHCP 中继(跨子网)
当 DHCP 服务器与客户端不在同一广播域时,需在网关接口配置中继:
Router(config)# interface GigabitEthernet0/1
Router(config-if)# ip helper-address 192.168.100.10 # DHCP 服务器地址
Router(config-if)# exit
路由器接口作为 DHCP 客户端
Router(config)# interface GigabitEthernet0/1
Router(config-if)# ip address dhcp # 从 ISP 获取 IP
Router(config-if)# no shutdown
验证命令
| 命令 | 查看内容 |
|---|---|
show ip dhcp binding | IP-MAC 地址绑定表 |
show ip dhcp pool | 地址池使用统计 |
show ip dhcp conflict | 地址冲突记录 |
show dhcp lease | 租约详细信息 |
ipconfig /all (Windows) 或 ip a (Linux) | 客户端 IP 信息 |