路由器配置dhcp自动获取ip命令

【路由器配置dhcp自动获取ip命令】一、DHCP背景
DHCP 服务可为主机自动分配 IP 地址,省去手动静态配置IP地址的麻烦,有效动态分配IP地址
二、 拓扑

路由器配置dhcp自动获取ip命令

文章插图
三、DHCP配置
R1 为 DHCP 服务器,和 R2 同属于 VLAN 10,R3 属于 VLAN 20 。R1、R2 模拟成 PC 机首先进行基本配置R2 上的配置
Router>en
Router#conf t
Router(config)#hostname r2
R2(config)#no ip routing /关闭路由器路由功能,模拟成 PC 机
R2(config)#int e0/0
R2(config-if)#ip add dhcp
R2(config-if)#no shutdown
R3 上的配置
Router>en
Router#conf t
Router(config)#hostname r3
R3(config)#no ip routing
R3(config)#int e0/0
R3(config-if)#ip add dhcp
R3(config-if)#no shutdown
sw1 上的配置
sw1#conf t
sw1(config)#int f0/1
sw1(config-if)#switchport mode access
sw1(config-if)#switchport access vlan 10
sw1(config-if)#int f0/2
sw1(config-if)#switchport mode access
sw1(config-if)#switchport access vlan 10
sw1(config-if)#int f0/3
sw1(config-if)#switchport mode access
sw1(config-if)#switchport access vlan 20
下面进行 DHCP 的配置
R1 上的配置
Router>en
Router#conf t
Router(config)#hostname DHCP
DHCP(config)#int e0/0
DHCP(config-if)#ip add 192.168.1.1 255.255.255.0
DHCP(config)#ip dhcp pool zl_01 /建立 DHCP 池,池名为 zl1
DHCP(dhcp-config)#network 193.168.1.0 255.255.255.0 /指定池所包含的 IP 地址段,和子网掩码
DHCP(dhcp-config)#default-router 193.168.1.254 /指定自动分配的网关
DHCP(dhcp-config)#dns-server 202.101.172.46 /指定自动分配的 DNS
DHCP(dhcp-config)#ip dhcp pool zl_02
DHCP(dhcp-config)#network 192.168.2.0 255.255.255.0
DHCP(dhcp-config)#default-router 192.168.2.254
DHCP(dhcp-config)#dns-server 202.101.172.46
DHCP(dhcp-config)#exit
DHCP(config)#ip dhcp excluded-address 192.168.1.1 193.168.1.100 /保留哪些地址不用来分配
DHCP(config)#ip dhcp excluded-address 192.168.2.1 193.168.2.100
DHCP(config)#ip route 192.168.2.0 255.255.255.0 192.168.1.254 /配置静态路由
sw1(config-if)#int vlan 10
sw1(config-if)#ip add 192.168.1.254 255.255.255.0
sw1(config-if)#no shut
sw1(config-if)#int valn 20
sw1(config-if)#ip add 192.168.2.254 255.255.255.0
sw1(config-if)#ip helper-address 192.168.1.1 /IP helper-address 作用是将 DHCP 请求的广播
数据包转化为单播请求 , 路由器才会响应
sw1(config-if)#no shut
以下是华为数通路由交换方向完整技术分享,欢迎对华为网络技术感兴趣的小伙伴们订阅 。【可在专栏中进行查看订阅】
华为新版HCIA数通路由交换
华为新版HCIP数通路由交换
华为新版HCIE数通路由交换