华为华三交换机通过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]
发布了75 篇原创文章 · 获赞 30 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/NeverGUM/article/details/103898638
今日推荐