当前位置:首页>微思动态 > >详情
全国热线电话 400-881-4699

在线留言

【案例分享】华为三层交换机配置为DHCP服务器

发布作者:微思网络   发布时间:2026-05-18   浏览量:0

 学习目标

· 掌握DHCP全局地址池的配置方法

· 掌握DHCP接口地址池的配置方法

拓扑图


场景

您是公司的网络管理员,公司网络需要配置DHCP业务,将三层交换机SW1配置为DHCP服务器,并配置全局地址池和接口地址池,为接入层设备PC1、PC2分配IP地址。其中PC1和PC2所在的VLAN分别为VLAN1和VLAN2,如以上实验拓扑所示。

SW1配置基于全局的地址池给VLAN1用户分配IP信息。

SW1配置基于接口的地址池给VLAN2用户分配IP信息。

操作步骤

步骤一 实验环境准备。

为了保证实验结果的准确性,确保设备以空配置启动。

按照实验拓扑图进行基础配置以及IP编址。

  • <Huawei>system-view

  • [Huawei]sysname SW1

  • [SW1]vlan 2

  • [SW1-vlan2]quit

  • [SW1]interfaceGigabitEthernet 0/0/1

  • [SW1-GigabitEthernet0/0/1]port link-type access

  • [SW1-GigabitEthernet0/0/1]port default vlan 1

  • [SW1-GigabitEthernet0/0/1]quit

  • [SW1]interfaceGigabitEthernet 0/0/2

  • [SW1-GigabitEthernet0/0/2]port link-type access

  • [SW1-GigabitEthernet0/0/2]port default vlan 2

  • [SW1-GigabitEthernet0/0/2]quit

  • [SW1]interfacevlan 1

  • [SW1-Vlanif1]ip address 10.1.1.254 24

  • [SW1-Vlanif1]quit[SW1]int vlan 2

  • [SW1-Vlanif2]ip address 10.1.2.254 24

  • [SW1-Vlanif2]quit

使用命令display cur、display vlan、display ip interface brief查看确保以上配置正确。

步骤一 启用DHCP功能。

默认情况下,DHCP功能并未启用,在SW1上启用DHCP功能。

  • [SW1]dhcp enable

步骤二 创建全局IP地址池。

在SW1上创建名为pool1的地址池,并配置地址池中地址的起始范围、网关地址、DNS和地址租期。

  • [SW1]ippoolpool1

  • [SW1-ip-pool-pool1]network 10.1.1.0mask 24

  • [SW1-ip-pool-pool1]gateway-list 10.1.1.254

  • [SW1-ip-pool-pool1]leaseday 1 hour 12

  • [SW1-ip-pool-pool1]dns-list 114.114.114.114

  • [SW1-ip-pool-pool1]quit

  • [SW1]

  • [SW1]interfacevlan 1

  • [SW1-Vlanif1]dhcpselectglobal

  • [SW1-Vlanif1]quit

  • [SW1]

在路由器上执行display ip pool name <name>命令,查看配置的IP地址池中的参数。

  • [SW1]displayippoolnamepool1

  • Pool-name : pool1Pool-No : 0

  • Lease : 1 Days 12 Hours 0 Minutes

  • Domain-name : -

  • DNS-server0 : 114.114.114.114

  • NBNS-server0 : -Netbios-type : -

  • Position : LocalStatus : Unlocked

  • Gateway-0 : 10.1.1.254

  • Mask : 255.255.255.0

  • VPNinstance : --

  • -----------------------------------------------------------------------------

  • StartEndTotalUsedIdle(Expired) ConflictDisable

  • ----------------------------------------------------------------------------- 

  •  10.1.1.1 10.1.1.254 253 1 252(0) 0 0

  • -----------------------------------------------------------------------------

验证PC1从SW1上名为pool1的DHCP地址池获取IP地址。

设置PC1通过DHCP方式获取IP地址。

  • PC>ipconfig

  • Linklocal IPv6 address...........: fe80::5689:98ff:fe76:66ac

  • IPv6address.........................: :: / 128

  • IPv6gateway........................: ::

  • IPv4address.........................: 10.1.1.253

  • Subnetmask........................: 255.255.255.0

  • Gateway................................: 10.1.1.254

  • Physicaladdress..................: 54-89-98-76-66-AC

  • DNSserver............................: 114.114.114.114

以上显示PC1已经可以获取到SW1上pool1的地址信息。

步骤三 创建接口地址池。

在SW1 vlanif2接口上执行dhcp select interface命令开启接口的DHCP服务功能,指定从接口地址池分配地址信息。

  • [SW1]interface Vlanif 2

  • [SW1-Vlanif2]dhcp selectinterface

  • [SW1-Vlanif2]dhcp server dns-list114.114.114.114

  • [SW1-Vlanif2]dhcp server lease day1hour12

  • [SW1-Vlanif2]quit

  • [SW1]在SW1上执行display ip pool interface命令,查看配置的接口地址池参数。

  • [SW1]display ip pool interface vlanif2 

  •   Pool-name : vlanif2 

  •   Pool-No : 1 

  •  Lease : 1Days12Hours0Minutes

  • Domain-name : - 

  •  DNS-server0 : 114.114.114.114 

  •  NBNS-server0 : - 

  •  Netbios-type : - 

  • Position : InterfaceStatus : Unlocked 

  •  Gateway-0 : 10.1.2.254

  • Mask : 255.255.255.0 

  •  VPN instance : --

  • -----------------------------------------------------------------------------

  • StartEnd Total Used Idle(Expired) Conflict Disable

  • -----------------------------------------------------------------------------

  • 10.1.2.110.1.2.2542531252(0) 00

  • -----------------------------------------------------------------------------

设置PC2通过自己获取的方式配置IP地址。

验证VLAN2的PC2从接口地址池中分配了新的IP地址。

  • PC2>ipconfig

  • Linklocal IPv6 address...........: fe80::5689:98ff:fe28:323c

  • IPv6address.............................: :: / 128

  • IPv6gateway.............................: ::

  • IPv4address..............................: 10.1.2.253

  • Subnetmask.............................: 255.255.255.0

  • Gateway......................................: 10.1.2.254

  • Physicaladdress.......................: 54-89-98-28-32-3C

  • DNSserver.................................: 114.114.114.114

在上述回显信息,灰色部分表明PC2从接口地址池中获取了IP地址信息。

配置文件

  • [SW1]display current-configuration

  • sysname SW1

  • vlan batch 2

  • dhcp enable

  • ip pool pool1 

  •  gateway-list 10.1.1.254 

  •  network 10.1.1.0 mask 255.255.255.0 

  •  lease day 1 hour 12 minute 0 

  •  dns-list 114.114.114.114



  • interface Vlanif1 

  •  ip address 10.1.1.254 255.255.255.0 

  •  dhcp selectglobal

  •  interface Vlanif2 

  • ip address 10.1.2.254255.255.255.0 

  • dhcp selectinterface 

  • dhcp server lease day1hour12minute0 

  • dhcp server dns-list114.114.114.114



  • interface GigabitEthernet0/0/1 

  • port link-typeaccess

  • interface GigabitEthernet0/0/2 

  • port link-typeaccess 

  • port default vlan 2






返回顶部