Creating a subnet

Subnets are created in cloud networks. A new subnet is located in one of the availability zones. Resources can be connected to a subnet if they reside in the same availability zone as the subnet itself.

To create a subnet:

  1. Open the Virtual Private Cloud section in the folder where you want to create the subnet.

  2. Click on the name of the cloud network.

  3. Click Add subnet.

  4. Fill in the form: enter the subnet name and select the availability zone from the drop-down list.

    The name must be unique within the folder. The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters.

  5. Enter the subnet CIDR: the IP address and mask. For more information about subnet IP address ranges, see the section Cloud networks and subnets.

  6. Click Create subnet.

If you don't have the Yandex.Cloud command line interface yet, install it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

To create a subnet:

  1. See the description of the CLI command for creating a subnet:

    $ yc vpc subnet create --help
    
  2. Get a list of cloud networks in the required folder:

    $ yc vpc network list --folder-id b1g6ci08ma55klukmdjs
    +----------------------+----------------+
    |          ID          |      NAME      |
    +----------------------+----------------+
    | enpavfmgapumnl7cqin8 | test-network-1 |
    | enplom7a98s1t0lhass8 | default        |
    +----------------------+----------------+
    
  3. Select the NAME or ID of the cloud network you need. Create a subnet in the default folder by specifying the cloud network ID via the --network-id flag:

    $ yc vpc subnet create --name test-subnet-1 \
      --description "My test subnet" \
      --network-id enplom7a98s1t0lhass8 \
      --zone ru-central1-b \
      --range 192.168.0.0/24
    

    You can also select a cloud network by specifying its name via the --network-name flag. Specify the name of the cloud network to create the subnet in and the CIDR. The --zone flag indicates the availability zone where the subnet will be created. If this flag is omitted, the subnet is created in the default availability zone.

    The name must be unique within the folder. The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters.

    $ yc vpc subnet create --name test-subnet-1 \
      --description "My test subnet" \
      --network-name test-network-1 \
      --zone ru-central1-b \
      --range 192.168.0.0/24
    

    The --name and --description flags are optional: you can create a subnet without any name or description and access it by ID.

  4. Get a list of all subnets in the default folder:

    $ yc vpc subnet list
    +----------------------+-----------------------+------------------------+
    |          ID          |         NAME          | ... |       RANGE      |
    +----------------------+-----------------------+------------------------+
    ...
    | e2l0psbfoloefpjb1rau | test-subnet-1         | ... | [192.168.0.0/24] |
    ...
    +----------------------+-----------------------+-----+------------------+
    

    Get the same list with more details in YAML format:

    $ yc vpc subnet list --format yaml
    
    ...
    
    - id: e2l0psbfoloefpjb1rau
      folder_id: b1g6ci08ma55klukmdjs
      created_at: "2018-10-24T12:25:58Z"
      name: test-subnet-1
      description: My test subnet
      network_id: enplom7a98s1t0lhass8
      zone_id: ru-central1-b
      v4_cidr_blocks:
      - 192.168.0.0/24
    
    ...
    

Examples

Create a subnet with a name and description in the selected folder:

$ yc vpc subnet create --name test-subnet-1 \
  --description "My test subnet" \
  --folder-id b1g6ci08ma55klukmdjs \
  --network-id enplom7a98s1t0lhass8 \
  --zone ru-central1-b \
  --range 192.168.0.0/24