当前位置:   article > 正文

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

ip address dhcp-alloc

前言

命令功能

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

  1. <Huawei>system-view
  2. Enter system view, return user view with Ctrl+Z.
  3. [Huawei]undo info-center enable //关闭信息中心提示
  4. Info: Information center is disabled.
  5. [Huawei]sysname CORE //命名设备
  6. [CORE]vlan batch 10 //创建vlan10
  7. Info: This operation may take a few seconds. Please wait for a moment...done.
  8. [CORE]dhcp enable //开启DHCP服务
  9. Info: The operation may take a few seconds. Please wait for a moment.done.
  10. [CORE]interface Vlanif 10 //进入三层虚拟接口vlanif10
  11. [CORE-Vlanif10]ip address 192.168.10.254 24 //配置IP地址
  12. [CORE-Vlanif10]dhcp select global //选择DHCP的方式是全局方式
  13. [CORE-Vlanif10]quit
  14. [CORE]ip pool test //创建名为“test”的地址池名
  15. Info:It's successful to create an IP address pool.
  16. [CORE-ip-pool-test]network 192.168.10.0 mask 24 //宣告网段
  17. [CORE-ip-pool-test]gateway-list 192.168.10.254 //配置网关
  18. [CORE-ip-pool-test]dns-list 114.114.114.114 //配置DNS
  19. [CORE-ip-pool-test]quit
  20. [CORE]interface GigabitEthernet 0/0/1 //进入G0/0/1端口
  21. [CORE-GigabitEthernet0/0/1]port link-type access //设置链路类型为access
  22. [CORE-GigabitEthernet0/0/1]port default vlan 10 //使得该端口属于vlan10
  23. [CORE-GigabitEthernet0/0/1]quit
  24. [CORE]interface GigabitEthernet 0/0/2
  25. [CORE-GigabitEthernet0/0/2]port link-type trunk //设置链路类型是trunk
  26. [CORE-GigabitEthernet0/0/2]port trunk allow-pass vlan 10 //允许vlan10通过
  27. [CORE-GigabitEthernet0/0/2]quit
  28. [CORE]interface GigabitEthernet 0/0/3
  29. [CORE-GigabitEthernet0/0/3]port link-type trunk
  30. [CORE-GigabitEthernet0/0/3]port trunk allow-pass vlan all //允许所有vlan通过
  31. [CORE-GigabitEthernet0/0/3]quit
  32. [CORE]

test01

  1. <Huawei>system-view
  2. Enter system view, return user view with Ctrl+Z.
  3. [Huawei]undo info-center enable
  4. Info: Information center is disabled.
  5. [Huawei]sysname test01
  6. [test01]dhcp enable //开启DHCP服务
  7. Info: The operation may take a few seconds. Please wait for a moment.done.
  8. [test01]interface Vlanif 1
  9. [test01-Vlanif1]ip address dhcp-alloc //开启接口下的DHCP Client功能
  10. [test01-Vlanif1]quit
  11. [test01]display interface Vlanif 1
  12. Vlanif1 current state : UP
  13. Line protocol current state : UP
  14. Last line protocol up time : 2020-01-08 21:40:22 UTC-08:00
  15. Description:
  16. Route Port,The Maximum Transmit Unit is 1500
  17. Internet Address is allocated by DHCP, 192.168.10.253/24
  18. //此时已经获取了IP地址,192.168.10.253
  19. IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 4c1f-cc92-4bf0
  20. Current system time: 2020-01-08 21:40:24-08:00
  21. Input bandwidth utilization : --
  22. Output bandwidth utilization : --
  23. [test01]

test02

  1. <Huawei>system-view
  2. Enter system view, return user view with Ctrl+Z.
  3. [Huawei]undo info-center enable
  4. Info: Information center is disabled.
  5. [Huawei]sysname test02
  6. [test02]dhcp enable
  7. Info: The operation may take a few seconds. Please wait for a moment.done.
  8. [test02]vlan batch 10
  9. Info: This operation may take a few seconds. Please wait for a moment...done.
  10. [test02]interface Vlanif 10
  11. [test02-Vlanif10]ip address dhcp-alloc
  12. [test02-Vlanif10]quit
  13. [test02]interface Ethernet0/0/1
  14. [test02-Ethernet0/0/1]port link-type trunk
  15. [test02-Ethernet0/0/1]port trunk allow-pass vlan 10
  16. [test02-Ethernet0/0/1]quit
  17. [test02]display interface Vlanif 10
  18. Vlanif10 current state : UP
  19. Line protocol current state : UP
  20. Last line protocol up time : 2020-01-08 21:43:31 UTC-08:00
  21. Description:
  22. Route Port,The Maximum Transmit Unit is 1500
  23. Internet Address is allocated by DHCP, 192.168.10.252/24
  24. //此时已经获取了IP地址,192.168.10.252
  25. IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 4c1f-cc12-7082
  26. Current system time: 2020-01-08 21:45:50-08:00
  27. Input bandwidth utilization : --
  28. Output bandwidth utilization : --

test03

  1. [Huawei]undo info-center enable
  2. Info: Information center is disabled.
  3. [Huawei]dhcp enable
  4. Info: The operation may take a few seconds. Please wait for a moment.done.
  5. [Huawei]vlan batch 10
  6. Info: This operation may take a few seconds. Please wait for a moment...done.
  7. [Huawei]sysname test03
  8. [test03]interface Ethernet0/0/1
  9. [test03-Ethernet0/0/1]port link-type trunk
  10. [test03-Ethernet0/0/1]port trunk allow-pass vlan all
  11. [test03-Ethernet0/0/1]quit
  12. [test03]interface Vlanif 10
  13. [test03-Vlanif10]ip address dhcp-alloc
  14. [test03-Vlanif10]quit
  15. [test03]display interface Vlanif 10
  16. Vlanif10 current state : UP
  17. Line protocol current state : UP
  18. Last line protocol up time : 2020-01-08 21:54:14 UTC-08:00
  19. Description:
  20. Route Port,The Maximum Transmit Unit is 1500
  21. Internet Address is allocated by DHCP, 192.168.10.251/24
  22. //获取到了核心的地址池地址,192.168.10.251
  23. IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 4c1f-ccf6-754f
  24. Current system time: 2020-01-08 21:54:15-08:00
  25. Input bandwidth utilization : --
  26. Output bandwidth utilization : --
  27. [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即可获得一个管理地址。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/245026
推荐阅读
相关标签
  

闽ICP备14008679号