DHCP简介

定义

动态主机配置协议DHCP(Dynamic Host Configuration Protocol)是一种用于集中对用户IP地址进行动态管理和配置的技术。即使规模较小的网络,通过DHCP也可以使后续增加网络设备变得简单快捷。

DHCP是在BOOTP(BOOTstrap Protocol)基础上发展而来,但BOOTP运行在相对静态(每台主机都有固定的网络连接)的环境中,管理员为每台主机配置专门的BOOTP参数文件,该文件会在相当长的时间内保持不变。DHCP从以下两方面对BOOTP进行了扩展:

  • DHCP允许计算机动态地获取IP地址,而不是静态为每台主机指定地址。
  • DHCP能够分配其他配置参数,例如客户端的启动配置文件,使客户端仅用一个消息就获取它所需要的所有配置信息。

DHCP协议由RFC 2131定义,采用客户端/服务器通信模式,由客户端(DHCP Client)向服务器(DHCP Server)提出配置申请,服务器返回为客户端分配的配置信息。

DHCP可以提供两种地址分配机制,网络管理员可以根据网络需求为不同的主机选择不同的分配策略。

  • 动态分配机制:通过DHCP为主机分配一个有使用期限(这个使用期限通常叫做租期)的IP地址。

    这种分配机制适用于主机需要临时接入网络或者空闲地址数小于网络主机总数且主机不需要永久连接网络的场景。

  • 静态分配机制:网络管理员通过DHCP为指定的主机分配固定的IP地址。

    相比手工静态配置IP地址,通过DHCP方式静态分配机制避免人工配置发生错误,方便管理员统一维护管理。

受益

DHCP受益主要有以下两点:

  • 降低客户端的配置和维护成本

    DHCP易配置部署,对于非技术用户,DHCP能够将客户端与配置相关的操作降至最低,并能够降低远程部署和维护成本。

  • 集中管理

    DHCP服务器可以管理多个网段的配置信息,当某个网段的配置发生变化时,管理员只需要更新DHCP服务器上的相关配置即可。

DHCP简介_第1张图片

组网需求

如图1所示,某企业为办公终端规划了两个网段,网段10.1.1.0/24内PC为员工固定办公终端,网段10.1.2.0/24供企业出差人员临时接入网络。为方便管理员统一,希望企业终端能够自动获取IP地址和DNS服务器IP地址(当用户希望以域名方式访问时需要配置域名解析的DNS服务器)。其中,企业管理者的办公PC(Client_1)由于业务需要,希望使用固定IP地址为10.1.1.100/24。

配置思路

基于接口地址池的DHCP服务器的配置思路如下:

通过在Switch上配置DHCP服务器,实现为企业的两个网段内终端动态分配IP地址和DNS服务器地址。其中,网段10.1.1.0/24内PC为员工固定办公终端,IP地址租期配置为30天,并通过DHCP静态方式为DHCP Client_1分配固定IP地址(10.1.1.100/24);网段10.1.2.0/24供企业出差人员临时接入网络,IP地址租期配置为2天。

操作步骤
  1. 使能DHCP服务

     system-view
    [HUAWEI] sysname Switch
    [Switch] dhcp enable
  2. 配置接口加入VLAN

    # 配置GE0/0/1接口加入VLAN10。

    [Switch] vlan batch 10 to 11
    [Switch] interface gigabitethernet 0/0/1
    [Switch-GigabitEthernet0/0/1] port link-type hybrid
    [Switch-GigabitEthernet0/0/1] port hybrid pvid vlan 10
    [Switch-GigabitEthernet0/0/1] port hybrid untagged vlan 10
    [Switch-GigabitEthernet0/0/1] quit

    # 配置GE0/0/2接口加入VLAN11。

    [Switch] interface gigabitethernet 0/0/2
    [Switch-GigabitEthernet0/0/2] port link-type hybrid
    [Switch-GigabitEthernet0/0/2] port hybrid pvid vlan 11
    [Switch-GigabitEthernet0/0/2] port hybrid untagged vlan 11
    [Switch-GigabitEthernet0/0/2] quit
  3. 配置VLANIF接口IP地址

    # 配置VLANIF10接口地址。

    [Switch] interface vlanif 10
    [Switch-Vlanif10] ip address 10.1.1.1 24
    [Switch-Vlanif10] quit

    # 配置VLANIF11接口地址。

    [Switch] interface vlanif 11
    [Switch-Vlanif11] ip address 10.1.2.1 24
    [Switch-Vlanif11] quit
  4. 配置接口地址池

    # 配置VLANIF10接口下的客户端从接口地址池中获取IP地址和相关网络参数。

    [Switch] interface vlanif 10
    [Switch-Vlanif10] dhcp select interface
    [Switch-Vlanif10] dhcp server gateway-list 10.1.1.1
    [Switch-Vlanif10] dhcp server lease day 30
    [Switch-Vlanif10] dhcp server domain-name example.com
    [Switch-Vlanif10] dhcp server dns-list 10.1.3.1
    [Switch-Vlanif10] dhcp server static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456
    [Switch-Vlanif10] quit

    # 配置VLANIF11接口下的客户端从接口地址池中获取IP地址和相关网络参数。

    [Switch] interface vlanif 11
    [Switch-Vlanif11] dhcp select interface
    [Switch-Vlanif11] dhcp server gateway-list 10.1.2.1
    [Switch-Vlanif11] dhcp server lease day 2
    [Switch-Vlanif11] dhcp server domain-name example.com
    [Switch-Vlanif11] dhcp server dns-list 10.1.3.1
    [Switch-Vlanif11] quit
  5. 配置DHCP数据保存功能,设备发生故障时,可以在系统重启后,执行命令dhcp server database recover,从存储设备文件恢复DHCP数据。

    [Switch] dhcp server database enable
  6. 验证配置结果

    # 在Switch上执行命令display ip pool来查看接口地址池的分配情况,“Used”字段显示已经分配出去的IP地址数量。假设企业员工固定办公终端有100个,出差人员接入3个。

    [Switch] display ip pool interface vlanif10
      Pool-name        : Vlanif10
      Pool-No          : 0
      Lease            : 30 Days 0 Hours 0 Minutes
      Domain-name      : example.com
      DNS-server0      : 10.1.3.1
      NBNS-server0     : -
      Netbios-type     : -
      Position         : Interface
      Status           : Unlocked
      Gateway-0        : 10.1.1.1
      Network          : 10.1.1.0
      Mask             : 255.255.255.0
      VPN instance     : --
      Logging          : Disable
      Conflicted address recycle interval: -
      Address Statistic: Total       :253       Used        :100
                         Idle        :153       Expired     :0
                         Conflict    :0         Disabled     :0
    
     -------------------------------------------------------------------------------
      Network section
             Start           End       Total    Used Idle(Expired) Conflict Disabled
     -------------------------------------------------------------------------------
            10.1.1.1      10.1.1.254     253     100        153(0)       0     0
     -------------------------------------------------------------------------------
    [Switch] display ip pool interface vlanif11
      Pool-name        : Vlanif11
      Pool-No          : 1
      Lease            : 2 Days 0 Hours 0 Minutes
      Domain-name      : example.com
      DNS-server0      : 10.1.3.1
      NBNS-server0     : -
      Netbios-type     : -
      Position         : Interface
      Status           : Unlocked
      Gateway-0        : 10.1.2.1
      Network          : 10.1.2.0
      Mask             : 255.255.255.0
      VPN instance     : --
      Logging          : Disable
      Conflicted address recycle interval: -
      Address Statistic: Total       :253       Used        :3
                         Idle        :250       Expired     :0
                         Conflict    :0         Disabled     :0
    
     -------------------------------------------------------------------------------
      Network section
             Start           End       Total    Used Idle(Expired) Conflict Disabled
     -------------------------------------------------------------------------------
            10.1.1.1      10.1.1.254    253       3        250(0)       0     0
     -------------------------------------------------------------------------------

    在Client_1(操作系统以Windows 7为例)上查看IP地址信息,可以看到Client_1已经获取到IP地址10.1.1.100/24。

    C:\Documents and Settings\Administrator>ipconfig
    
    Windows IP Configuration
    
    
    Ethernet adapter Local Area Connection 2:
    
       Connection-specific DNS Suffix  . :
       IPv4 Address. . . . . . . . . . . : 10.1.1.100
       Subnet Mask . . . . . . . . . . . : 255.255.254.0
       Default Gateway . . . . . . . . . : 10.1.1.1

    在其他DHCP客户端(以10.1.1.0/24网段中操作系统为Windows 7的某终端为例)上查看IP地址信息,可以看到已经成功获取到IP地址。

    C:\Documents and Settings\Administrator>ipconfig
    
    Windows IP Configuration
    
    
    Ethernet adapter Local Area Connection 2:
    
       Connection-specific DNS Suffix  . :
       IPv4 Address. . . . . . . . . . . : 10.1.1.51
       Subnet Mask . . . . . . . . . . . : 255.255.254.0
       Default Gateway . . . . . . . . . : 10.1.1.1

配置文件

Switch的配置文件

#
sysname Switch
#
vlan batch 10 to 11
#
dhcp enable
#
dhcp server database enable
# 
interface Vlanif10
 ip address 10.1.1.1 255.255.255.0
 dhcp select interface
 dhcp server gateway-list 10.1.1.1
 dhcp server static-bind ip-address 10.1.1.100 mac-address 00e0-fc12-3456
 dhcp server lease day 30 hour 0 minute 0
 dhcp server dns-list 10.1.3.1
 dhcp server domain-name example.com
#
interface Vlanif11
 ip address 10.1.2.1 255.255.255.0
 dhcp select interface
 dhcp server gateway-list 10.1.2.1
 dhcp server lease day 2 hour 0 minute 0
 dhcp server dns-list 10.1.3.1
 dhcp server domain-name example.com
#
interface GigabitEthernet0/0/1
 port link-type hybrid
 port hybrid pvid vlan 10
 port hybrid untagged vlan 10
#
interface GigabitEthernet0/0/2
 port link-type hybrid
 port hybrid pvid vlan 11
 port hybrid untagged vlan 11
#
return

你可能感兴趣的:(网络,服务器,运维)