How to use Edge DHCP service for subnets behind DLR
9 enero, 2016 por
Bacalov, Damian

Since NSX version 6.2.1, you can configure DHCP pools in an Edge for networks behind DLR.

If you have the latest version of vSphere Client (6.0.0 or newest), you can do this directly from the console filling the form below:

dhcp_6.0.0

But if you have vSphere Client version 5.5 or older, this cannot be done. If you see the form, it has the “Subnet Mask” parameter missing.

dhcp_5.5.0

And if you try to submit the form without the parameter, you get an error:

dhcp_invalid_config

Using NSX API

You can configure this pools using the NSX API. In this article, I will show how to do it using Firefox with RestClient add-on.

Prerequisites

Before we start, we need:

  • NSX Manager URL (https://nsxHost/)
  • NSX Manager administrative credentials
  • The id of the Edge we want configure
  • Desired network dhcp pools data

You can find the Edge Id in the vSphere Client as you can see in the following image:

edge-id

Creating the API call content

In this example we will create two DHCP pools for the networks 10.0.1.0/24 and 10.0.2.0/24 in both cases, the “.1” address is the default gateway. In order to do that, we need to create an XML like the following:

<dhcp>
    <enabled>true</enabled>
    <staticBindings />
    <ipPools>
        <ipPool>
            <autoConfigureDNS>false</autoConfigureDNS>
            <defaultGateway>10.0.1.1</defaultGateway>
            <primaryNameServer>8.8.8.8</primaryNameServer>
            <secondaryNameServer>8.8.4.4</secondaryNameServer>
            <leaseTime>86400</leaseTime>
            <subnetMask>255.255.255.0</subnetMask>
            <ipRange>10.0.1.50-10.0.1.100</ipRange>
            <allowHugeRange>false</allowHugeRange>
        </ipPool>
        <ipPool>
            <autoConfigureDNS>false</autoConfigureDNS>
            <defaultGateway>10.0.2.1</defaultGateway>
            <primaryNameServer>8.8.8.8</primaryNameServer>
            <secondaryNameServer>8.8.4.4</secondaryNameServer>
            <leaseTime>86400</leaseTime>
            <subnetMask>255.255.255.0</subnetMask>
            <ipRange>10.0.2.50-10.0.2.100</ipRange>
            <allowHugeRange>false</allowHugeRange>
        </ipPool>
    </ipPools>
    <logging>
        <enable>true</enable>
        <logLevel>info</logLevel>
    </logging>
</dhcp>

Using RestClient

In the RestClient, we add a Basic Authentication and add the proper credentials.

basic_authentication

Add the Content-Type header and set xml:

ContentType

Add the Accept header and set xml:

Accept

Select the PUT Method, paste the XML with the configuration in the Body and set the URL to:
https://{nsxHost}/api/4.0/edges/{edge-Id}/dhcp/config
We need to replate “{nsxHost}” for the actual NSX host and “{edge-Id}” for the Id of the Edge.

Click “send” and that’s it. The new configuration is up and running.

IMPORTANT

If you have something configured in the Edge DHCP service, first you need to get the current configuration and add the new pools nodes in the XML.

To get the current configuration, you need to use the GET method (instead of PUT).

DHCP Relay

The last thing to do is to set the DHCP Relay in the Logical Router and set the appropriate firewall rules, but you can do this using vSphere Client.