【HCIA】简易的两个VLAN分别使用DHCP分配IP

前言

之前我们通过 静态ip地址实现了Vlan间通信 ,现在我们添加一个常用的DHCP功能。

文章目录

  • 前言
  • [1. 配置交换机](#1. 配置交换机)
  • [2. 接口模式](#2. 接口模式)
  • [3. 全局模式](#3. 全局模式)
  • 后记
  • 修改记录

1. 配置交换机

首先,使用DHCP,需要先启动DHCP服务:

shell 复制代码
[Huawei]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.

2. 接口模式

我们将VLAN10设置为接口模式的dhcp,首先我们进入vlanif10,选择dchp的模式:

vlanif 就是 vlan interface 的缩写

shell 复制代码
[Huawei]interface Vlanif 10
[Huawei-Vlanif10]dhcp select ?
  global     Local server 
  interface  Interface server pool 
  relay      DHCP relay 
[Huawei-Vlanif10]ip address 192.168.10.254 24
[Huawei-Vlanif10]dhcp select interface

假设我们需要排除一部分高的地址,将ip地址限制在100以内,我们在分配ip的时候应该排除:

shell 复制代码
[Huawei-Vlanif10]dhcp server excluded-ip-address 192.168.10.101 192.168.10.253

接下来我们配置dns-list:

shell 复制代码
[Huawei-Vlanif10]dhcp server dns-list 8.8.8.8

最后,我们查看一下我们的Vlanif配置:

shell 复制代码
[Huawei-Vlanif10]display this
#
interface Vlanif10
 ip address 192.168.10.254 255.255.255.0
 dhcp select interface
 dhcp server excluded-ip-address 192.168.10.101 192.168.10.253
 dhcp server dns-list 8.8.8.8
#
return

这个时候,我们不要忘记给实际的接口与Vlan 10关联:

shell 复制代码
[Huawei]interface GigabitEthernet 0/0/1
[Huawei-GigabitEthernet0/0/1]port link-type access
[Huawei-GigabitEthernet0/0/1]port default vlan 10

此时,我们把 PC1 切换到 DHCP 分配 IPv4 :

我们可以敲命令行来刷新IP:

cmd 复制代码
PC>ipconfig /renew

IP Configuration


Link local IPv6 address...........: fe80::5689:98ff:febb:3c16
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.10.97
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.10.254
Physical address..................: 54-89-98-BB-3C-16
DNS server........................: 8.8.8.8

3. 全局模式

我们除了可以在某个接口配置DHCP Server,还可以全局配置,然后接口去对应这个全局的DHCP Server。我们回到系统视图:

shell 复制代码
[Huawei]dhcp enable

然后我们配置全局的DHCP,需要优先配置IP地址池,进入它对应的视图:

shell 复制代码
[Huawei]ip pool 20
[Huawei-ip-pool-20]network 192.168.20.0 mask 24
[Huawei-ip-pool-20]gateway-list 192.168.20.254
[Huawei-ip-pool-20]dns-list 8.8.8.8
[Huawei-ip-pool-20]excluded-ip-address 192.168.20.100 192.168.20.253
[Huawei-ip-pool-20]lease day 10

我们可以看到,这种全局的地址池,因为本身没有ip,所以要先配置自身的ip地址,然后再配置网关、DNS列表、租期等内容

然后我们进入Vlanif20,选择Global模式

shell 复制代码
[Huawei]interface Vlanif 20
[Huawei-Vlanif20]ip address 192.168.20.254 24
[Huawei-Vlanif20]dhcp select global
[Huawei-Vlanif20]display this
#
interface Vlanif20
 ip address 192.168.20.254 255.255.255.0
 dhcp select global
#
return
[Huawei-Vlanif20]quit
[Huawei]interface g0/0/2
[Huawei-GigabitEthernet0/0/2]port link-type access
[Huawei-GigabitEthernet0/0/2]port default vlan 20
[Huawei-GigabitEthernet0/0/2]quit
[Huawei]quit
<Huawei>save
The current configuration will be written to the device.
Are you sure to continue?[Y/N]Y
Now saving the current configuration to the slot 0.
Save the configuration successfully.

此时,我们把 PC2 切换到 DHCP 分配 IPv4 :


后记

文中有任何错误、遗漏,烦请各位老铁在评论区指出,共同学习进步。

修改记录

更新日期 修改内容
2025年4月21日 完成初稿
相关推荐
流浪00115 小时前
计算机网络篇3:端口号与 socket:数据到达主机后,如何找到目标进程?
计算机网络·udp·tcp·端口·网络字节序
欣欣之王来了1 天前
5G网络基础:5G的核心特性,eMBB、uRLLC、mMTC的应用场景
网络·学习·计算机网络·安全·教程
道尔柯南1 天前
从 0 到 1 理解计算机网络:从网络基础到 Socket 编程
网络·计算机网络
沙漠之主4 天前
计算机二级考试备考全攻略:从报名到通关
计算机网络·面试
欣欣之王来了4 天前
5G的行业应用:工业互联网、车联网、智慧医疗中的网络支撑
网络·学习·计算机网络·安全·教程
geng_geng_geng6 天前
计算机网络:物理层
计算机网络
wusam7 天前
计算机网络第二章习题解答
服务器·网络·计算机网络
ZhangJun957 天前
三次握手、四次挥手的具体细节和流程详解,附加思考题
tcp/ip·计算机网络·云计算
郝学胜-神的一滴7 天前
游戏引擎原理与实践 02:揭开3A游戏背后的技术面纱
开发语言·计算机网络·程序人生·游戏·游戏引擎
geng_geng_geng8 天前
计算机网络:概述
计算机网络