华为华三交换机通过ip address dhcp-alloc命令使接口动态获取IP地址

前言

命令功能

ip address dhcp-alloc命令用来开启接口下的DHCP Client功能。

undo ip address dhcp-alloc命令用来关闭接口下的DHCP Client功能。

缺省情况下,接口下DHCP Client功能处于关闭状态。

应用场景

为了使Switch的接口通过DHCP协议动态获取IP地址,可以在接口上配置DHCP Client功能。DHCP Client可以使用DHCP协议向Server请求分配一个IP地址。DHCP Client主要包含两个过程:

  • 向Server发送DHCP请求报文
  • 处理Server返回的DHCP响应报文

DHCP Client在使用DHCP协议获取IP地址时,先向Server发送DHCP请求报文,Server接收到请求报文后,将返回DHCP响应报文。DHCP Client从接收到响应报文中可以获取所分配到的IP地址的相关信息。

注意事项

设备接口下获取地址的方式有两种,一种是静态配置(执行命令ip address),一种是通过动态方式获取(执行命令ip address dhcp-alloc)。静态配置的优先级高,静态方式的配置会覆盖动态方式的配置。如果执行命令ip address dhcp-alloc成功获取到IP地址后,再执行命令undo ip address会删除动态获取的IP地址以及动态方式的配置信息。如果执行命令ip address dhcp-alloc没有申请到地址,再执行命令undo ip address不会删除动态方式的配置信息。

拓补图

实验过程

我们按照图示的链路类型,模拟了三台交换机,然后不同的方式下均获取到了IP地址。

CORE-test01: test1的交换机以ACCESS的方式接入了vlan10

CORE-test02:两端都以trunk的方式互联,并且允许vlan10通过

CORE-test03:两端都以trunk的方式互联,允许所有vlan通过。

CORE


<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable //关闭信息中心提示
Info: Information center is disabled.
[Huawei]sysname CORE	//命名设备
[CORE]vlan batch 10 //创建vlan10
Info: This operation may take a few seconds. Please wait for a moment...done.

[CORE]dhcp enable //开启DHCP服务
Info: The operation may take a few seconds. Please wait for a moment.done.	
[CORE]interface Vlanif 10	 //进入三层虚拟接口vlanif10
[CORE-Vlanif10]ip address 192.168.10.254 24	 //配置IP地址
[CORE-Vlanif10]dhcp select global //选择DHCP的方式是全局方式
[CORE-Vlanif10]quit 

[CORE]ip pool test //创建名为“test”的地址池名
Info:It's successful to create an IP address pool.	
[CORE-ip-pool-test]network 192.168.10.0 mask 24 //宣告网段
[CORE-ip-pool-test]gateway-list 192.168.10.254 //配置网关
[CORE-ip-pool-test]dns-list  114.114.114.114 //配置DNS
[CORE-ip-pool-test]quit 

[CORE]interface GigabitEthernet 0/0/1	//进入G0/0/1端口
[CORE-GigabitEthernet0/0/1]port link-type access 	//设置链路类型为access
[CORE-GigabitEthernet0/0/1]port default vlan 10	//使得该端口属于vlan10
[CORE-GigabitEthernet0/0/1]quit 

[CORE]interface GigabitEthernet 0/0/2
[CORE-GigabitEthernet0/0/2]port link-type trunk //设置链路类型是trunk
[CORE-GigabitEthernet0/0/2]port trunk allow-pass vlan 10	//允许vlan10通过
[CORE-GigabitEthernet0/0/2]quit 

[CORE]interface GigabitEthernet 0/0/3	
[CORE-GigabitEthernet0/0/3]port link-type trunk 
[CORE-GigabitEthernet0/0/3]port trunk allow-pass vlan all //允许所有vlan通过
[CORE-GigabitEthernet0/0/3]quit 
[CORE]

test01


<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.	
[Huawei]undo info-center enable 
Info: Information center is disabled.
[Huawei]sysname test01

[test01]dhcp enable //开启DHCP服务
Info: The operation may take a few seconds. Please wait for a moment.done.
[test01]interface Vlanif 1
[test01-Vlanif1]ip address dhcp-alloc //开启接口下的DHCP Client功能
[test01-Vlanif1]quit 




[test01]display interface Vlanif 1
Vlanif1 current state : UP
Line protocol current state : UP
Last line protocol up time : 2020-01-08 21:40:22 UTC-08:00
Description:
Route Port,The Maximum Transmit Unit is 1500
Internet Address is allocated by DHCP, 192.168.10.253/24 
//此时已经获取了IP地址,192.168.10.253
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 4c1f-cc92-4bf0
Current system time: 2020-01-08 21:40:24-08:00
    Input bandwidth utilization  : --
    Output bandwidth utilization : --

[test01]

test02


<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.

[Huawei]undo info-center enable 
Info: Information center is disabled.

[Huawei]sysname test02

[test02]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.

[test02]vlan batch 10
Info: This operation may take a few seconds. Please wait for a moment...done.


[test02]interface Vlanif 10
[test02-Vlanif10]ip address dhcp-alloc 	
[test02-Vlanif10]quit 




[test02]interface Ethernet0/0/1
[test02-Ethernet0/0/1]port link-type trunk 	
[test02-Ethernet0/0/1]port trunk allow-pass vlan 10	
[test02-Ethernet0/0/1]quit 



[test02]display interface Vlanif 10
Vlanif10 current state : UP
Line protocol current state : UP
Last line protocol up time : 2020-01-08 21:43:31 UTC-08:00
Description:
Route Port,The Maximum Transmit Unit is 1500
Internet Address is allocated by DHCP, 192.168.10.252/24
//此时已经获取了IP地址,192.168.10.252
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 4c1f-cc12-7082
Current system time: 2020-01-08 21:45:50-08:00
    Input bandwidth utilization  : --
    Output bandwidth utilization : --


test03


[Huawei]undo info-center enable 
Info: Information center is disabled.

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

[Huawei]vlan batch 10
Info: This operation may take a few seconds. Please wait for a moment...done.
[Huawei]sysname test03

[test03]interface Ethernet0/0/1	
[test03-Ethernet0/0/1]port link-type trunk 	
[test03-Ethernet0/0/1]port trunk allow-pass vlan all	
[test03-Ethernet0/0/1]quit 

[test03]interface Vlanif 10	
[test03-Vlanif10]ip address dhcp-alloc 	
[test03-Vlanif10]quit 





[test03]display interface Vlanif 10
Vlanif10 current state : UP
Line protocol current state : UP
Last line protocol up time : 2020-01-08 21:54:14 UTC-08:00
Description:
Route Port,The Maximum Transmit Unit is 1500
Internet Address is allocated by DHCP, 192.168.10.251/24 
//获取到了核心的地址池地址,192.168.10.251
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 4c1f-ccf6-754f
Current system time: 2020-01-08 21:54:15-08:00
    Input bandwidth utilization  : --
    Output bandwidth utilization : --

[test03]

总结

在实际的网络应用中,可能有以下场景会遇到这条命令。

1:一台完全的傻瓜交换机,我想配置简单一点,且想让它所有端口都能DHCP自动获取IP地址,并且默认的vlanif1也有个可以通信的IP地址,那么我们就可以吧上联端口设置成为ACCESS端口,而傻瓜交换机在全局开启DHCP服务的情况下,使用命令ip address dhcp-alloc。即可完成需求。

2:不想用默认的vlan1,那么以vlan10举例,在需要配置的交换机上,吧所有PC连接的端口批量以ACCESSS端口加入vlan10,然后两端的交换机互联的端口均以trunk的方式放行valn10,在全局开启DHCP服务的情况下,然后在vlanif10里执行这条命令,ip address dhcp-alloc即可获得一个管理地址。

  • 7
    点赞
  • 69
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值