XYCOVO CONSOLE KURISU · WEB 渗透 / AI 辅助攻防 ONLINE
#035 · 2024-03-10✓ PASS

DHCP 配置

DHCP 动态主机配置协议实验,在 Cisco 路由器上配置 DHCP 服务器实现 IP 地址自动分配。
csdn网络实验dhcpAUTHOR: KURISU

实验原理

DHCP(Dynamic Host Configuration Protocol)基于 UDP 协议,使用端口 67(服务器)和 68(客户端),自动为网络设备分配 IP、子网掩码、网关、DNS 等参数。

DHCP 工作流程(DORA)

步骤消息方向说明
1Discover客户端 → 广播寻找 DHCP 服务器
2Offer服务器 → 客户端提供 IP 地址租约
3Request客户端 → 服务器确认使用该 IP
4Acknowledge服务器 → 客户端最终确认,租约生效

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 bindingIP-MAC 地址绑定表
show ip dhcp pool地址池使用统计
show ip dhcp conflict地址冲突记录
show dhcp lease租约详细信息
ipconfig /all (Windows) 或 ip a (Linux)客户端 IP 信息
← #034 静态路由实验…#036 Linux 命令实验… →