DHCP自动获取IP地址实验(思科)

华为设备参考:DHCP自动获取IP地址实验(华为)

一,实验目的

路由器搭载DHCP,让PC通过DHCP自动获取IP地址

二,不划分vlan

实验拓扑

配置命令

Switch

Switch>enable

Switch#configure terminal

Switch(config)#int f0/1

Switch(config-if)#switchport mode trunk

Switch(config-if)#end

Switch#show running-config

Router

Router>enable 特权模式

Router#configure terminal 全局配置模式

Router(config)#service dhcp· 启用DHCP服务

Router(config)#ip dhcp pool mypool 创建名为"mypool"的DHCP地址池

Router(dhcp-config)#network 192.168.1.0 255.255.255.0 定义DHCP地址池的网络地址和子网掩码

Router(dhcp-config)#default-router 192.168.1.254 设置默认网关

Router(dhcp-config)#dns-server 114.114.114.114 设置DNS服务器地址

Router(dhcp-config)#exit

Router(config)#ip dhcp excluded-address 192.168.1.1 从DHCP地址池中排除该IP地址

Router(config)#ip dhcp excluded-address 192.168.1.254

Router(config)#int f0/0

Router(config-if)#ip address 192.168.1.1 255.255.255.0 为接口配置IP地址和子网掩码

Router(config-if)#no shutdown 启用接口

Router(config-if)#end

Router#show running-config 显示运行配置

测试结果

PC1 和 PC2 成功获取到 IP 地址

三,划分vlan

实验拓扑

配置命令

Switch

Switch>enable

Switch#configure terminal

Switch(config)#vlan 10 创建vlan10

Switch(config-vlan)#exit

Switch(config)#vlan 20 创建vlan20

Switch(config-vlan)#exit

Switch(config)#int range f0/2-3 进入2,3接口

Switch(config-if-range)#switchport mode access 设为access模式

Switch(config-if-range)#switchport access vlan 10 允许vlan10通过

Switch(config-if-range)#exit

Switch(config)#int range f0/4-5 进入4,5接口

Switch(config-if-range)#switchport mode access 设为access模式

Switch(config-if-range)#switchport access vlan 20 允许vlan20通过

Switch(config-if-range)#exit

Switch(config)#int f0/1

Switch(config-if)#switchport mode trunk 设为trunk模式

Switch(config-if)#end

Switch#show running-config 查看运行配置

Router

Router>enable

Router#configure terminal

Router(config)#int f0/0

Router(config-if)#no shutdown 启用接口

Router(config-if)#int f0/0.10 进入子接口,用于配置VLAN 10

Router(config-subif)#encapsulation dot1Q 10 设置子接口的封装类型为802.1Q,并指定VLAN ID为10

Router(config-subif)#ip address 192.168.10.1 255.255.255.0 为子接口配置IP地址

Router(config-subif)#no shutdown 启用子接口f0/0.10

Router(config-subif)#exit

Router(config)#int f0/0.20 进入子接口,用于配置VLAN 20

Router(config-subif)#encapsulation dot1Q 20 设置子接口的封装类型为802.1Q,并指定VLAN ID为20

Router(config-subif)#ip address 192.168.20.1 255.255.255.0 为子接口f配置IP地址

Router(config-subif)#no shutdown 启用子接口f0/0.20

Router(config-subif)#exit

Router(config)#service dhcp 启用DHCP服务。

Router(config)#ip dhcp pool pool_10 为VLAN 10创建一个名为"pool_10"的DHCP地址池

Router(dhcp-config)#network 192.168.10.1 255.255.255.0 定义DHCP地址池的网络地址

Router(dhcp-config)#default-router 192.168.10.1 设置默认网关

Router(dhcp-config)#dns-server 114.114.114.114 设置DNS服务器地址

Router(dhcp-config)#exit

Router(config)#ip dhcp pool pool_20 为VLAN 20创建一个名为"pool_20"的DHCP地址池

Router(dhcp-config)#network 192.168.20.1 255.255.255.0

Router(dhcp-config)#default-router 192.168.20.1

Router(dhcp-config)#dns-server 114.114.114.114

Router(dhcp-config)#exit

Router(config)#ip dhcp excluded-address 192.168.10.1 从VLAN 10的地址池中排除IP地址

Router(config)#ip dhcp excluded-address 192.168.20.1 从VLAN 20的地址池中排除IP地址

Router(config)#end

Router#show running-config

测试结果

四台 PC 都能成功获取到 IP 地址

相关推荐
是小满满满满吗6 小时前
传输层:udp与tcp协议
linux·服务器·网络
小刘同学++6 小时前
ECB(电子密码本,Electronic Codebook) 和 CBC(密码分组链接,Cipher Block Chaining)区分于用途
网络·ssl
gadiaola7 小时前
【计算机网络】第3章:传输层—TCP 拥塞控制
网络·网络协议·tcp/ip·计算机网络
猎板PCB厚铜专家大族7 小时前
多层PCB技术解析:从材料选型到制造工艺的深度实践
网络·制造
FakeOccupational9 小时前
【碎碎念】宝可梦 Mesh GO : 基于MESH网络的口袋妖怪 宝可梦GO游戏自组网系统
网络·游戏
fei_sun11 小时前
【计算机网络】三报文握手建立TCP连接
网络·tcp/ip·计算机网络
Johny_Zhao11 小时前
2025年6月Docker镜像加速失效终极解决方案
linux·网络·网络安全·docker·信息安全·kubernetes·云计算·containerd·yum源·系统运维
PypYCCcccCc11 小时前
支付系统架构图
java·网络·金融·系统架构
搬码临时工13 小时前
如何把本地服务器变成公网服务器?内网ip网址转换到外网连接访问
运维·服务器·网络·tcp/ip·智能路由器·远程工作·访问公司内网
zzc92113 小时前
MATLAB仿真生成无线通信网络拓扑推理数据集
开发语言·网络·数据库·人工智能·python·深度学习·matlab