DHCP工作原理 、 DHCP中继代理 、 全局模式DHCP 、 DHCP综合实战 、 三层交换机DHCP

1 案例:基于全局模式的DHCP

1.1 需求

  1. 在路由器上配置基于全局模式的DHCP
  2. DHCP的地址池为 192.168.1.0/24
  3. DHCP的网关地址为 192.168.1.254
  4. DHCP的DNS 为 8.8.8.8
  5. DHCP的租期 为 3天

1.2 方案

使用eNSP搭建实验环境,如图-1所示。

DHCP工作原理 、 DHCP中继代理 、 全局模式DHCP 、 DHCP综合实战 、 三层交换机DHCP图-1

1.3 步骤

实现此案例需要按照如下步骤进行。[hidecontent type=”payshow”]

1)配置PC1/2获得IP地址的方式为“自动获取/DHCP”

2)配置 SW1,确保DHCP客户端与DHCP服务器互通

  1. <Huawei>undo ter
  2. <Huawei>undo terminal mo
  3. <Huawei>undo terminal monitor
  4. [Huawei]sysname SW1
  5. [SW1]vlan 10
  6. [SW1vlan10]quit
  7. [SW1]interface Ethernet0/0/1
  8. [SW1Ethernet0/0/1]port link access
  9. [SW1Ethernet0/0/1]port default vlan 10
  10. [SW1Ethernet0/0/1]quit
  11. [SW1]interface Ethernet0/0/2
  12. [SW1Ethernet0/0/2]port link access
  13. [SW1Ethernet0/0/2]port default vlan 10
  14. [SW1Ethernet0/0/2]quit
  15. [SW1]interface Ethernet0/0/3
  16. [SW1Ethernet0/0/3]port link access
  17. [SW1Ethernet0/0/3]port default vlan 10
  18. [SW1Ethernet0/0/3]quit

3)配置R1,将其配置为 DHCP 服务器

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname R1
  4. [R1]interface GigabitEthernet 0/0/0
  5. [R1GigabitEthernet0/0/0]ip address 192.168.1.254 24
  6. [R1GigabitEthernet0/0/0]quit
  7. [R1]dhcp enable
  8. [R1]ip pool DHCP
  9. [R1ippoolDHCP]network 192.168.1.0 mask 24
  10. [R1ippoolDHCP]gatewaylist 192.168.1.254
  11. [R1ippoolDHCP]dnslist 8.8.8.8
  12. [R1ippoolDHCP]lease day 3
  13. [R1ippoolDHCP]quit
  14. [R1]interface GigabitEthernet 0/0/0
  15. [R1GigabitEthernet0/0/0]dhcp select global
  16. [R1GigabitEthernet0/0/0]quit

4)验证 PC1/2 获得IP地址

2 案例:配置DHCP中继

2.1 需求

  1. 配置DHCP中继,让客户端从DHCP服务器获取地址
  2. 客户机可以ping通R1

2.2 方案

使用eNSP搭建实验环境,如图-2所示。

DHCP工作原理 、 DHCP中继代理 、 全局模式DHCP 、 DHCP综合实战 、 三层交换机DHCP图-2

2.3 步骤

实现此案例需要按照如下步骤进行。

1)配置PC1为DHCP客户端

2)配置 SW1 确保 PC1与 R2(PC1的网关)互通

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname SW1
  4. [SW1]vlan 10
  5. [SW1vlan10]quit
  6. [SW1]interface eth0/0/1
  7. [SW1Ethernet0/0/1]port link access
  8. [SW1Ethernet0/0/1]port default vlan 10
  9. [SW1Ethernet0/0/1]quit
  10. [SW1]interface eth0/0/2
  11. [SW1Ethernet0/0/2]port link access
  12. [SW1Ethernet0/0/2]port default vlan 10
  13. [SW1Ethernet0/0/2]quit

3)配置DHCP中继(R2)

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname R2
  4. [R2]interface gi0/0/1
  5. [R2GigabitEthernet0/0/1]ip address 192.168.1.254 24
  6. [R2GigabitEthernet0/0/1]quit
  7. [R2]interface gi0/0/0
  8. [R2GigabitEthernet0/0/0]ip address 10.10.10.2 24
  9. [R2GigabitEthernet0/0/0]quit
  10. [R2]dhcp enable
  11. [R2]interface gi0/0/01
  12. [R2GigabitEthernet0/0/1]dhcp select relay
  13. [R2GigabitEthernet0/0/1]dhcp relay serverip 10.10.10.1
  14. [R2GigabitEthernet0/0/1]quit

4)配置DHCP服务器(R1)

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname R1
  4. [R1]interface GigabitEthernet 0/0/0
  5. [R1GigabitEthernet0/0/0]ip address 10.10.10.1 24
  6. [R1GigabitEthernet0/0/0]quit
  7. [R1]dhcp enable
  8. [R1]ip pool DHCP
  9. [R1ippoolDHCP]network 192.168.1.0 mask 24
  10. [R1ippoolDHCP]gatewaylist 192.168.1.254
  11. [R1ippoolDHCP]dnslist 8.8.8.8
  12. [R1ippoolDHCP]quit
  13. [R1]interface GigabitEthernet 0/0/0
  14. [R1GigabitEthernet0/0/0]dhcp select global
  15. [R1GigabitEthernet0/0/0]quit
  16. [R1]ip routestatic 192.168.1.0 24 10.10.10.2

5)验证主机自动获取的IP地址

3 案例:交换机配置DHCP服务器

3.1 需求

  1. 配置两个地址池:192.168.1.0/24和192.168.2.0/24
  2. 配置两个VLAN:VLAN 10和VLAN 20
  3. 将四台主机分别加入VLAN
  4. 自动获取IP地址,确保全网互通

3.2 方案

使用eNSP搭建实验环境,如图-3所示。

DHCP工作原理 、 DHCP中继代理 、 全局模式DHCP 、 DHCP综合实战 、 三层交换机DHCP图-3

3.3 步骤

实现此案例需要按照如下步骤进行。

1)配置DHCP客户端

2)配置DHCP客户端与DHCP服务器之间的传输网络(SW1/2/3)

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname SW1
  4. [SW1]vlan batch 10 20
  5. [SW1]interface eth0/0/1
  6. [SW1Ethernet0/0/1]port link access
  7. [SW1Ethernet0/0/1]port default vlan 10
  8. [SW1Ethernet0/0/1]quit
  9. [SW1]interface eth0/0/2
  10. [SW1Ethernet0/0/2]port link access
  11. [SW1Ethernet0/0/2]port default vlan 10
  12. [SW1Ethernet0/0/2]quit
  13. [SW1]interface GigabitEthernet 0/0/1
  14. [SW1GigabitEthernet0/0/1]port link trunk
  15. [SW1GigabitEthernet0/0/1]port trunk allowpass vlan all
  16. [SW1GigabitEthernet0/0/1]quit
  17. <Huawei>undo terminal monitor
  18. <Huawei>systemview
  19. [Huawei]sysname SW2
  20. [SW2]vlan batch 10 20
  21. [SW2]interface eth0/0/1
  22. [SW2Ethernet0/0/1]port link access
  23. [SW2Ethernet0/0/1]port default vlan 20
  24. [SW2Ethernet0/0/1]quit
  25. [SW2]interface eth0/0/2
  26. [SW2Ethernet0/0/2]port link access
  27. [SW2Ethernet0/0/2]port default vlan 20
  28. [SW2Ethernet0/0/2]quit
  29. [SW2]interface GigabitEthernet 0/0/2
  30. [SW2GigabitEthernet0/0/2]port link trunk
  31. [SW2GigabitEthernet0/0/2]port trunk allowpass vlan all
  32. [SW2GigabitEthernet0/0/2]quit
  33. <Huawei>undo terminal monitor
  34. <Huawei>systemview
  35. [Huawei]sysname SW3
  36. [SW3]vlan batch 10 20
  37. [SW3]interface GigabitEthernet 0/0/1
  38. [SW3GigabitEthernet0/0/1]port link trunk
  39. [SW3GigabitEthernet0/0/1]port trunk allowpass vlan all
  40. [SW3GigabitEthernet0/0/1]quit
  41. [SW3]interface GigabitEthernet 0/0/2
  42. [SW3GigabitEthernet0/0/2]port link trunk
  43. [SW3GigabitEthernet0/0/2]port trunk allowpass vlan all
  44. [SW3GigabitEthernet0/0/2]quit

3)配置DHCP服务器

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname SW3
  4. [SW3]vlan 10
  5. [SW3vlan10]quit
  6. [SW3]vlan 20
  7. [SW3vlan20]quit
  8. [SW3]interface Vlanif 10
  9. [SW3Vlanif10]ip address 192.168.1.254 24
  10. [SW3Vlanif10]quit
  11. [SW3]interface Vlanif 20
  12. [SW3Vlanif20]ip address 192.168.2.254 24
  13. [SW3Vlanif20]quit
  14. [SW3]dhcp enable
  15. [SW3]ip pool VLAN10
  16. [SW3ippoolvlan10]network 192.168.1.0 mask 24
  17. [SW3ippoolvlan10]gatewaylist 192.168.1.254
  18. [SW3ippoolvlan10]dnslist 8.8.8.8
  19. [SW3ippoolvlan10]quit
  20. [SW3]ip pool VLAN20
  21. [SW3ippoolvlan20]network 192.168.2.0 mask 24
  22. [SW3ippoolvlan20]gatewaylist 192.168.2.254
  23. [SW3ippoolvlan20]dnslist 8.8.8.8
  24. [SW3ippoolvlan20]quit
  25. [SW3]interface vlanif 10
  26. [SW3Vlanif10]dhcp select global
  27. [SW3Vlanif10]quit
  28. [SW3]interface Vlanif 20
  29. [SW3Vlanif20]dhcp select global
  30. [SW3Vlanif20]quit

4)验证

四台主机可以获得IP地址,并可以互相ping通。

4 案例:DHCP综合实战

4.1 需求

  1. 如图配置设备的IP地址,确保设备之间可以互通
  2. PC1/2的网关位于 SW1,PC4/5的网关位于R2,PC3的网关位于R1
  3. 确保PC获得正确的IP地址,实现PC之间的互通

4.2 方案

使用eNSP搭建实验环境,如图-4所示。

DHCP工作原理 、 DHCP中继代理 、 全局模式DHCP 、 DHCP综合实战 、 三层交换机DHCP图-4

4.3 步骤

实现此案例需要按照如下步骤进行。

1)配置PC1/2/3/4/5为 DHCP客户端

2)配置DHCP客户端与网关设备之间的传输网络-SW2/3/4

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname SW2
  4. [SW2]vlan batch 10 20
  5. [SW2]interface eth0/0/1
  6. [SW2Ethernet0/0/1]port link access
  7. [SW2Ethernet0/0/1]port default vlan 10
  8. [SW2Ethernet0/0/1]quit
  9. [SW2]interface Ethernet0/0/2
  10. [SW2Ethernet0/0/2]port link access
  11. [SW2Ethernet0/0/2]port default vlan 20
  12. [SW2Ethernet0/0/2]quit
  13. [SW2]interface GigabitEthernet 0/0/1
  14. [SW2GigabitEthernet0/0/1]port trunk allowpass vlan all
  15. [SW2GigabitEthernet0/0/1]quit
  16. [SW2]
  17. <Huawei>undo terminal monitor
  18. <Huawei>systemview
  19. [Huawei]sysname SW3
  20. [SW3]vlan 30
  21. [SW3vlan30]quit
  22. [SW3]interface eth0/0/3
  23. [SW3Ethernet0/0/3]port link access
  24. [SW3Ethernet0/0/3]port default vlan 30
  25. [SW3Ethernet0/0/3]quit
  26. [SW3]interface GigabitEthernet 0/0/1
  27. [SW3GigabitEthernet0/0/1]port link access
  28. [SW3GigabitEthernet0/0/1]port default vlan 30
  29. [SW3GigabitEthernet0/0/1]quit
  30. [SW3]
  31. <Huawei>undo terminal monitor
  32. <Huawei>systemview
  33. [Huawei]sysname SW4
  34. [SW4]vlan batch 40 50
  35. [SW4]interface Ethernet0/0/4
  36. [SW4Ethernet0/0/4]port link access
  37. [SW4Ethernet0/0/4]port default vlan 40
  38. [SW4Ethernet0/0/4]quit
  39. [SW4]interface Ethernet0/0/5
  40. [SW4Ethernet0/0/5]port link access
  41. [SW4Ethernet0/0/5]port default vlan 50
  42. [SW4Ethernet0/0/5]quit
  43. [SW4]interface GigabitEthernet 0/0/1
  44. [SW4GigabitEthernet0/0/1]port link trunk
  45. [SW4GigabitEthernet0/0/1]port trunk allowpass vlan all
  46. [SW4GigabitEthernet0/0/1]quit

3)配置 DHCP 客户端的网关

  1. <Huawei>undo terminal monitor
  2. <Huawei>systemview
  3. [Huawei]sysname SW1
  4. [SW1]vlan batch 10 20
  5. [SW1]interface GigabitEthernet 0/0/1
  6. [SW1GigabitEthernet0/0/1]port link trunk
  7. [SW1GigabitEthernet0/0/1]port trunk allowpass vlan all
  8. [SW1GigabitEthernet0/0/1]quit
  9. [SW1]vlan 23
  10. [SW1vlan23]quit
  11. [SW1]interface gi0/0/2
  12. [SW1GigabitEthernet0/0/2]port link access
  13. [SW1GigabitEthernet0/0/2]port default vlan 23
  14. [SW1GigabitEthernet0/0/2]quit
  15. [SW1]interface Vlanif 10
  16. [SW1Vlanif10]ip address 192.168.10.254 24
  17. [SW1Vlanif10]quit
  18. [SW1]interface Vlanif 20
  19. [SW1Vlanif20]ip address 192.168.30.254 24
  20. [SW1Vlanif20]quit
  21. [SW1]interface Vlanif 23
  22. [SW1Vlanif23]ip address 192.168.23.3 24
  23. [SW1Vlanif23]quit
  24. <Huawei>undo terminal monitor
  25. <Huawei>systemview
  26. [Huawei]sysname R1
  27. [R1]interface GigabitEthernet 0/0/0
  28. [R1GigabitEthernet0/0/0]ip address 192.168.30.254 24
  29. [R1GigabitEthernet0/0/0]quit
  30. [R1]interface GigabitEthernet 0/0/1
  31. [R1GigabitEthernet0/0/1]ip address 192.168.12.1 24
  32. [R1GigabitEthernet0/0/1]quit
  33. [R1]interface GigabitEthernet 0/0/2
  34. [R1GigabitEthernet0/0/2]ip address 192.168.23.1 24
  35. [R1GigabitEthernet0/0/2]quit
  36. <Huawei>undo terminal monitor
  37. <Huawei>systemview
  38. [Huawei]sysname R2
  39. [R2]interface GigabitEthernet 0/0/1
  40. [R2GigabitEthernet0/0/1]ip address 192.168.12.2 24
  41. [R2GigabitEthernet0/0/1]quit
  42. [R2]interface GigabitEthernet 0/0/0.4
  43. [R2GigabitEthernet0/0/0.4]dot1q termination vid 40
  44. [R2GigabitEthernet0/0/0.4]arp broadcast enable
  45. [R2GigabitEthernet0/0/0.4]ip address 192.168.40.254 24
  46. [R2GigabitEthernet0/0/0.4]quit
  47. [R2]interface GigabitEthernet 0/0/0.5
  48. [R2GigabitEthernet0/0/0.5]dot1q termination vid 50
  49. [R2GigabitEthernet0/0/0.5]arp broadcast enable
  50. [R2GigabitEthernet0/0/0.5]ip address 192.168.50.254 24
  51. [R2GigabitEthernet0/0/0.5]quit

4)配置 DHCP 服务器

  1. [R1]dhcp enable
  2. [R1]ip pool VLAN10
  3. [R1ippoolVLAN10]network 192.168.10.0 mask 24
  4. [R1ippoolVLAN10]gatewaylist 192.168.10.254
  5. [R1ippoolVLAN10]quit
  6. [R1]ip pool VLAN20
  7. [R1ippoolVLAN20]network 192.168.20.0 mask 24
  8. [R1ippoolVLAN20]gatewaylist 192.168.20.254
  9. [R1ippoolVLAN20]quit
  10. [R1]ip pool VLAN30
  11. [R1ippoolVLAN30]network 192.168.30.0 mask 24
  12. [R1ippoolVLAN30]gatewaylist 192.168.30.254
  13. [R1ippoolVLAN30]quit
  14. [R1]ip pool VLAN40
  15. [R1ippoolVLAN40]network 192.168.40.0 mask 24
  16. [R1ippoolVLAN40]gatewaylist 192.168.40.254
  17. [R1ippoolVLAN40]quit
  18. [R1]ip pool VLAN50
  19. [R1ippoolVLAN50]network 192.168.50.0 mask 24
  20. [R1ippoolVLAN50]gatewaylist 192.168.50.254
  21. [R1ippoolVLAN50]quit
  22. [R1]interface GigabitEthernet 0/0/0
  23. [R1GigabitEthernet0/0/0]dhcp select global
  24. [R1GigabitEthernet0/0/0]quit
  25. [R1]interface GigabitEthernet 0/0/1
  26. [R1GigabitEthernet0/0/1]dhcp select global
  27. [R1GigabitEthernet0/0/1]quit
  28. [R1]interface GigabitEthernet 0/0/2
  29. [R1GigabitEthernet0/0/2]dhcp select global
  30. [R1GigabitEthernet0/0/2]quit
  31. [R1]ip routestatic 192.168.10.0 24 192.168.23.3
  32. [R1]ip routestatic 192.168.20.0 24 192.168.23.3
  33. [R1]ip routestatic 192.168.40.0 24 192.168.12.2
  34. [R1]ip routestatic 192.168.50.0 24 192.168.12.2

5)配置 DHCP 中继

  1. [SW1]dhcp enable
  2. [SW1]interface Vlanif 10
  3. [SW1Vlanif10]dhcp select relay
  4. [SW1Vlanif10]dhcp relay serverip 192.168.23.1
  5. [SW1Vlanif10]quit
  6. [SW1]interface Vlanif 20
  7. [SW1Vlanif20]dhcp select relay
  8. [SW1Vlanif20]dhcp relay serverip 192.168.23.1
  9. [SW1Vlanif20]quit
  10. [SW1]ip routestatic 0.0.0.0 0 192.168.23.1
  11. [R2]dhcp enable
  12. [R2]interface GigabitEthernet 0/0/0.4
  13. [R2GigabitEthernet0/0/0.4]dhcp select relay
  14. [R2GigabitEthernet0/0/0.4]dhcp relay serverip 192.168.12.1
  15. [R2GigabitEthernet0/0/0.4]quit
  16. [R2]interface GigabitEthernet 0/0/0.5
  17. [R2GigabitEthernet0/0/0.5]dhcp select relay
  18. [R2GigabitEthernet0/0/0.5]dhcp relay serverip 192.168.12.1
  19. [R2GigabitEthernet0/0/0.5]quit
  20. [R2]ip routestatic 0.0.0.0 0 192.168.12.1

6)验证 DHCP 客户端获得IP地址

  1. [sw3]vlan 30
  2. [sw3]int e0/0/1
  3. [sw3e0/0/1]port linktype access
  4. [sw3e0/0/1]port default vlan 30
  5. [sw3]int 0/0/2
  6. [sw3e0/0/2]port linktype trunk
  7. [sw3e0/0/2]port trunk allowpass vlan all[/hidecontent]

给TA打赏
共{{data.count}}人
人已打赏
华为数通

OSPFv3配置 、 特殊区域之NSSA 、 OSPF安全认证 、 IPv6协议介绍 、 OSPF 虚链路 、 OSPF 路由汇总

2021-12-27 14:41:07

华为数通

园区网需求分析 、 园区网项目流程 、 技术方案选型 、 服务器部署 、 网络拓扑绘制 、 基础交换网络设计

2021-12-28 13:06:56

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索