[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > Basic infrastructure > Network > DHCP settings for interfacing with a corporate DNS server

# DHCP settings for interfacing with a corporate DNS server


If you want your VMs to resolve names in a private corporate DNS zone, use the [DHCP options](../../vpc/concepts/dhcp-options.md) in the [subnet configuration](../../vpc/operations/subnet-create.md). For example, you can specify a DNS suffix and DNS server for subnet nodes.

To run this scenario, make sure you have a corporate DNS server deployed that is available for the VMs in the cloud. You can also Deploy Active Directory to create an infrastructure with a DNS server:

* Cloud network named `ad-network` with subnets in different [availability zones](../../overview/concepts/geo-scope.md):
    * `ad-subnet-a` (10.1.0.0/16)
    * `ad-subnet-b` (10.2.0.0/16)
    * `ad-subnet-d` (10.3.0.0/16)
* Domain controllers and a bastion host:
    * `ad-vm-a` (10.1.0.3)
    * `ad-vm-b` (10.2.0.3)
    * `jump-server-vm` (10.3.0.x)

In this tutorial, you will add a new subnet, `10.128.0.0/24`, with the DNS suffix and DNS server specified, create a VM, and test the network.

To add a subnet with DHCP settings:

* [Get your cloud ready](#before-begin).
* [Create a subnet](#create-subnet).
* [Test the network](#check-config).

If you no longer need the resources you created, [delete](#clear-out) them.

## Get your cloud ready {#before-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).

To pass this scenario in full, deploy Active Directory. If you use your own DNS servers that are available for cloud VMs, specify your own DNS suffix and IP address values in the scenario.

### Required paid resources {#paid-resources}

The infrastructure support cost includes:

* Fee for continuously running VMs (see [Yandex Compute Cloud pricing](../../compute/pricing.md)).
* Fee for VM disk storage (see [Yandex Compute Cloud pricing](../../compute/pricing.md)).
* Fee for using dynamic or static public IP addresses (see [Yandex Virtual Private Cloud pricing](../../vpc/pricing.md)).
* Fee for Yandex Cloud outbound internet traffic (see [Yandex Compute Cloud pricing](../../compute/pricing.md)).

## Create a subnet {#create-subnet}

To create a new subnet with DHCP settings, follow these steps:

{% list tabs group=instructions %}

- Management console {#console}

  To create a subnet:
  1. Open the **Virtual Private Cloud** section in the folder where you want to create a subnet.
  1. Click `ad-network`.
  1. Click **Add subnet**.
  1. Fill out the form:
      * Enter the subnet name: `test-subnet-1`. Select the availability zone: `ru-central1-a`.
      * Enter the subnet CIDR: `10.128.0.0/24`. For more information about subnet IP address ranges, see [Cloud networks and subnets](../../vpc/concepts/network.md).
  1. Specify **DHCP settings**:
      * In the **Domain name** field, specify the DNS suffix: `yantoso.net`.
      * In the **Domain name servers** field, click **Add DNS server** and specify the DNS server address: `10.1.0.3`. Repeat the steps for the `10.2.0.3` address.
  1. Click **Create subnet**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  Run this command:

  ```
  yc vpc subnet create --name test-subnet-1 \
    --description "My test subnet" \
    --folder-id <folder_ID> \
    --network-name ad-network \
    --zone ru-central1-a \
    --range 10.128.0.0/24 \
    --domain-name yantoso.net \
    --domain-name-server 10.1.0.3,10.2.0.3
  ```

  Where `<folder_ID>` is the ID of the folder to create resources in. If the folder is specified in the CLI profile, this parameter can be omitted.

  Result:

  ```
  id: e2ldy0b1prtj********
  folder_id: b1gbvco8fejm********
  created_at: "2021-07-12T13:28:54Z"
  name: test-subnet-1
  description: My test subnet
  network_id: enpl0t90hept********
  zone_id: ru-central1-a
  v4_cidr_blocks:
  - 10.128.0.0/24
  dhcp_options:
    domain_name_servers:
    - 10.1.0.3
    - 10.2.0.3
    domain_name: yantoso.net
  ```

{% endlist %}

## Test the network {#check-config}

To check the configuration, create a VM and connect to it via RDP:

1. Create a VM:

    {% list tabs group=instructions %}
    
    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), navigate to the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) dashboard, click **Create resource**, and select `Virtual machine instance`.
      1. Under **Boot disk image**, go to the `Custom` tab and select the **Windows Server** image. For more information on how to upload your own image for Microsoft products, see [Importing a custom image](../../microsoft/byol.md#how-to-import).
      1. Under **Location**, select the `ru-central1-a` [availability zone](../../overview/concepts/geo-scope.md) to create your VM in.
      1. Under **Disks and file storages**, specify your boot [disk](../../compute/concepts/disk.md) size: `50 GB`.
      1. Under **Computing resources**, switch to the `Custom` tab and specify the [platform](../../compute/concepts/vm-platforms.md), number of vCPUs, and amount of RAM:

          * **Platform**: `Intel Cascade Lake`.
          * **vCPU**: `2`.
          * **Guaranteed vCPU performance**: `100%`.
          * **RAM**: `4 GB`.
          * Make your VM [preemptible](../../compute/concepts/preemptible-vm.md), if required.

      1. Under **Network settings**, select `ad-network` and `test-subnet-1`.
      1. Under **General information**, specify the VM name: `vm-for-tests-in-subnet`.
      1. Click **Create VM**.

      1. Wait for the VM status to change to `Running` and reset the password:
         
         1. Select the VM.
         1. Click **Reset password**.
         1. Specify the **Username** to reset the password for. If there is no user with that name on the VM, this user will be created with administrator access.
         1. Click **Generate password**.
         1. Save the **New password**. It will become unavailable once you close the window.

    - CLI {#cli}
    
      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).
    
      To set a password for the VM, create the `metadata.yaml` file with the following contents:

      ```
      #ps1
      net user administrator '<password>'
      ```

      To create a VM, run the command:

      ```
      yc compute instance create \
        --name vm-for-tests-in-subnet \
        --metadata-from-file user-data=metadata.yaml \
        --zone ru-central1-a \
        --cores 2 \
        --memory 4 \
        --network-interface subnet-name=test-subnet-1,nat-ip-version=ipv4 \
        --create-boot-disk image-id=<image_ID>
      ```

      Where `<image_ID>` is the ID of your Windows Server image used for creating the VM.

      {% note info %}
      
      The commands [`yc compute instance create`](../../cli/cli-ref/compute/cli-ref/instance/create.md) | [`create-with-container`](../../cli/cli-ref/compute/cli-ref/instance/create-with-container.md) | [`update`](../../cli/cli-ref/compute/cli-ref/instance/update.md) | [`add-metadata`](../../cli/cli-ref/compute/cli-ref/instance/add-metadata.md) support substitution of environment variable values into VM metadata. When you execute a Yandex Cloud CLI command, these values, specified in the `user-data` key in `$<variable_name>` format, will be substituted into the VM metadata from the environment variables of the environment the command is executed in. 
      
      To change such behavior, i.e. to provide a variable name to the VM metadata in `$<variable_name>` format rather than take the variable value from the CLI command runtime environment, use the two-dollar syntax, e.g., `$$<variable_name>`.
      
      For more information, see [Specifics of providing environment variables in metadata via the CLI](../../compute/concepts/metadata/sending-metadata.md#environment-variables).
      
      {% endnote %}

      If the command is successful, save the IP address from the `one_to_one_nat` field. The address is used in the next step to create an RDP connection:

      ```
      ...
      status: RUNNING
      ...
      primary_v4_address:
        address: 10.128.0.26
      ...
      one_to_one_nat:
        address: 130.193.40.112
        ip_version: IPV4
      ...
      ```

    {% endlist %}

1. Wait a few minutes and [connect to the VM](../../compute/operations/vm-connect/rdp.md) over RDP.

1. Run PowerShell on the VM.

1. To view the Windows network configuration, run the command:

    ```
    ipconfig /all
    ```

    Result:

    ```
    Windows IP Configuration
    
      Host Name . . . . . . . . . . . . : epdpjtg********
      Primary Dns Suffix  . . . . . . . :
      Node Type . . . . . . . . . . . . : Hybrid
      IP Routing Enabled. . . . . . . . : No
      WINS Proxy Enabled. . . . . . . . : No
      DNS Suffix Search List. . . . . . : yantoso.net
    
    Ethernet adapter Ethernet 2:
    
      Connection-specific DNS Suffix  . : yantoso.net
      Description . . . . . . . . . . . : Red Hat VirtIO Ethernet Adapter #2
      Physical Address. . . . . . . . . : D0-0D-19-9F-60-C2
      DHCP Enabled. . . . . . . . . . . : Yes
      Autoconfiguration Enabled . . . . : Yes
      Link-local IPv6 Address . . . . . : fe80::1f0:5a1e:76ea:3ded%3(Preferred)
      IPv4 Address. . . . . . . . . . . : 10.128.0.11(Preferred)
      Subnet Mask . . . . . . . . . . . : 255.255.255.0
      Lease Obtained. . . . . . . . . . : Wednesday, July 14, 2021 11:00:09 AM
      Lease Expires . . . . . . . . . . : Saturday, August 20, 2157 5:33:50 PM
      Default Gateway . . . . . . . . . : 10.128.0.1
      DHCP Server . . . . . . . . . . . : 10.128.0.2
      DHCPv6 IAID . . . . . . . . . . . : 114298137
      DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-28-80-7B-90-D0-0D-19-9F-60-C2
      DNS Servers . . . . . . . . . . . : 10.1.0.3
                                          10.2.0.3
      NetBIOS over Tcpip. . . . . . . . : Enabled
    
    Tunnel adapter isatap.yantoso.net:
    
      Media State . . . . . . . . . . . : Media disconnected
      Connection-specific DNS Suffix  . : yantoso.net
      Description . . . . . . . . . . . : Microsoft ISATAP Adapter
      Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
      DHCP Enabled. . . . . . . . . . . : No
      Autoconfiguration Enabled . . . . : Yes
    ```

1. Check if there is a connection to the `yantoso.net` domain controller. 

    Do it by running this command:

    ```
    ping ad-vm-a
    ```
    
    If connected, the output should look as follows:

    ```
    PS C:\Users\Administrator> ping ad-vm-a
    
    Pinging ad-vm-a.yantoso.net [10.1.0.3] with 32 bytes of data:
    Reply from 10.1.0.3: bytes=32 time=1ms TTL=127
    Reply from 10.1.0.3: bytes=32 time<1ms TTL=127
    Reply from 10.1.0.3: bytes=32 time<1ms TTL=127
    Reply from 10.1.0.3: bytes=32 time<1ms TTL=127
    
    Ping statistics for 10.1.0.3:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum = 1ms, Average = 0ms
    ```

## How to delete the resources you created {#clear-out}

Some resources are not free of charge. Delete the resources you no longer need to avoid paying for them:

1. Delete the `vm-for-tests-in-subnet` VM.

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the folder this VM belongs to. 
      1. Navigate to **Compute Cloud**.
      1. Select the VM → click ![image](../../_assets/console-icons/ellipsis.svg) → select **Delete**.
      1. Confirm the deletion.

    - CLI {#cli}
    
      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

      The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

      To delete the VM, run:

      ```
      yc compute instance delete vm-for-tests-in-subnet
      ```

    {% endlist %}

1. Delete `test-subnet-1`.

    {% list tabs group=instructions %}

    - Management console {#console}
    
      1. Open the **Virtual Private Cloud** section in the folder you want to delete a subnet from.
      1. Click the name of the subnet's cloud network: `ad-network`.
      1. Click ![image](../../_assets/console-icons/ellipsis.svg) in the `test-subnet-1` row.
      1. In the menu that opens, click **Delete**.
      1. Confirm the deletion and click **Delete**.

    - CLI {#cli}

      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

      The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

      To delete the subnet, run:

      ```
      yc vpc subnet delete --name test-subnet-1
      ```

    {% endlist %}