在交换机上配置 DHCP 服务器或中继

请按照以下步骤在交换机上配置 DHCP 服务器或中继。

先决条件

配置 DHCP 服务器或中继之前,请确保满足以下条件:

  • 将在交换机上为其配置 DHCP 服务器的 VLAN 分配给连接到 DHCP 客户端的端口。为此,可将相关的端口配置文件应用于端口。有关端口配置文件的更多信息,请参阅 静态和动态端口配置文件。
  • 交换机具有 静态 IP 配置或附加 IP 配置,以便网络运行 DHCP 服务器。或者,已为 DHCP 服务器或中继配置了 L3 接口。

有关在有线客户端列表中显示 DHCP 客户端属性的信息,请参阅 有线客户端 。

配置 DHCP 服务器

要在交换机上配置 DHCP 服务器:

  1. 导航到左侧菜单上的 交换机 ,然后从列表中单击交换机。
    随即显示交换机详细信息页面。
  2. 在交换机详细信息页面上,向下滚动到 Services 部分中的 DHCP 服务器/中继 磁贴。
    User interface for managing network switches, showing DHCP Server/Relay settings for switch S2-EX1 with red error message: At least one DHCP network is required. Options to enable or disable Campus Fabric Defined, section showing no networks defined, and button to add DHCP network. Navigation panel includes Monitor, Marvis, Clients, Access Points, Switches, WAN Edges, Mist Edges, and Location. Top bar includes Utilities, Save, and Cancel options.
  3. 在 DHCP 服务器/中继 磁贴上,选中 已启用 复选框,然后单击 添加 DHCP 网络。
    将显示 DHCP 服务器/中继配置窗口。
  4. 确保将 服务器 选为配置 类型。
  5. 从网络下拉列表中,为 DHCP 服务器选择网络。
  6. 指定以下字段:
    • IP 开始 — DHCP IP 地址分配池中的起始 IP 地址。

    • IP 端 — DHCP IP 地址分配池中的结束 IP 地址。

    • 网关 — DHCP 客户端的默认网关。通常,它是相应网络的交换机 IRB IP 地址。

    • DNS 服务器 (可选) — 您最多可以添加三个 DNS IP 地址,格式以逗号分隔。

    • DNS 后缀(可选)—您最多可以添加三个以逗号分隔的格式的域后缀。

    Configuration interface for adding a DHCP network with type set to Server, network ID 10 labeled vl10, IP range 10.0.0.100 to 10.0.0.200, gateway 10.0.0.10, DNS servers 8.8.8.8, 8.8.4.4, 1.0.0.1, and DNS suffix test.net, tesing1.net, testing3.net.

    如果未配置 DNS 服务器和 DNS 后缀,Mist 会采用在交换机级别配置的 DNS 服务器和 DNS 后缀来自动生成配置。

  7. 保存更改。

    以下配置将应用于 API /sites/:site-id/devices/device-id:

    DHCP server JSON configuration showing enabled status, VLAN 10 with IP pool from 10.0.0.100 to 10.0.0.200, gateway 10.0.0.10, DNS servers 8.8.8.8, 8.8.4.4, 1.0.0.1, and DNS suffixes test.net, testing1.net, testing3.net.

    检查要推送到以下 API 的相应预期配置: /sites/:site-id/devices/device-id/config_cmd

    DHCP 服务器在 vl10 的 irb.10 接口上启用。以下示例适用于 Junos 交换机:

    地址分配池配置如下所示(适用于 Junos 交换机):

  8. 使用以下 CLI 验证交换机上的配置。以下示例适用于 Junos 交换机:
    Configuration comparison showing changes on a network device. DHCP relay removed and replaced with a local DHCP server setup. Key updates include DHCP server under services for group vl10 using interface irb.10, address assignment pool vl10 for network 10.0.0.0/24 with IP range 10.0.0.100 to 10.0.0.200, DHCP attributes defining name servers 8.8.8.8, 8.8.4.4, 1.0.0.1, router 10.0.0.10, and domain names test.net tesing1.net testing3.net.

    现在,应由 DHCP 服务器为 v110 网络的 DHCP 客户端分配 IP 地址,如下所示:

    DHCP server bindings showing two client IPs, MAC addresses, lease states, expiration times, interfaces, and detailed lease information for troubleshooting.

    以上示例适用于 Junos 交换机。

以下是一些有用的 Junos CLI 命令:

  • show dhcp server binding 或 show dhcp server binding detail—查看 DHCP 服务器绑定信息。

  • show dhcp server statistics— 查看发送/接收的 DHCP 消息统计信息。
  • clear dhcp server binding interface x-x/x/x— 清除特定接口上客户端的 DHCP 客户端绑定。
  • clear dhcp server binding <address>— 清除基于有线客户端的 IP 地址或 MAC 地址的 DHCP 客户端绑定。

配置 DHCP 中继

要在交换机上配置 DHCP 中继,请执行以下操作:

  1. 导航到左侧菜单上的 交换机 ,然后从列表中单击交换机。
    随即显示交换机详细信息页面。
  2. 在交换机详细信息页面上,向下滚动到 Services 部分中的 DHCP 服务器/中继 磁贴。
    User interface for managing network switches, showing DHCP Server/Relay settings for switch S2-EX1 with red error message: At least one DHCP network is required. Options to enable or disable Campus Fabric Defined, section showing no networks defined, and button to add DHCP network. Navigation panel includes Monitor, Marvis, Clients, Access Points, Switches, WAN Edges, Mist Edges, and Location. Top bar includes Utilities, Save, and Cancel options.
  3. 在 DHCP 服务器/中继 磁贴上,选中 已启用 复选框,然后单击 添加 DHCP 网络。
    将显示 DHCP 服务器/中继配置窗口。
  4. 选择 Relay 作为配置 类型。
    DHCP configuration form titled DHCP SERVER / RELAY with error message IPv4 or IPv6 DHCP Servers are required. Includes type selection for Server or Relay, network field with add button, text boxes for IPv4 and IPv6 server addresses with format notes.
  5. 在网络字段中,单击 + 为 DHCP 中继添加网络。
    注意:

    确保为提供 DHCP 服务的 VLAN 配置了相应的第 3 层接口。设备需要此 L3 接口才能处理和转发该 VLAN 的 DHCP 流量。

  6. 在 IPv4 和 IPv6 DHCP 服务器字段中,配置远程 DHCP 服务器的 IP 地址。您最多可以添加三个 IP 地址,格式以逗号分隔。
  7. 保存更改。

    以下配置将应用于 API /sites/:site-id/devices/device-id:JSON configuration showing DHCP enabled with type relay and server IP 192.168.1.1 under site and device-specific paths.

    检查要在以下 API 上推送的相应预期配置: /sites/:site-id/devices/device-id/config_cmd

    配置如下所示(此示例适用于 Junos 交换机):

  8. 使用以下 CLI 验证交换机上的配置。以下示例 CLI 命令适用于 Junos 交换机:
    Configuration snippet showing DHCP relay setup on Junos OS. Server-group vl11 with DHCP server 192.168.1.1 is linked to interface irb.11 under forwarding-options hierarchy.
  9. 确保可从交换机访问远程 DHCP 服务器。以下示例 CLI 命令适用于 Junos 交换机:
    Ping command output showing connectivity test to 192.168.1.1 with 2 packets sent and received, 0 percent packet loss, and round-trip times ranging from 7.553 ms to 16.166 ms.
  10. 验证交换机上的 DHCP 中继绑定。以下示例 CLI 命令适用于 Junos 交换机:
    Output of the command show dhcp relay binding detail on a Juniper device showing details like client IP 11.0.0.218, MAC address d4:20:b0:83:dd:9c, lease state bound, expiration time 2022-06-16 18:46:58 IST, incoming interface irb.11:ge-0/0/8.0, DHCP server IP 192.168.1.3, relay address 11.0.0.10, and session ID 15.

另请参阅: DHCP 中继代理。