This topic describes how to create an Elastic Compute Service (ECS) instance that supports dual-stack IPv4/IPv6 addressing in different operating systems by creating or updating a stack in the Resource Orchestration Service (ROS) console. The ECS instance is created based on different conditions.

Background information

When you create an ECS instance that is assigned both IPv4 and IPv6 addresses, you must separately create an IPv6 gateway, purchase an IPv6 Internet bandwidth plan, and configure a public IP address. The configuration methods vary based on the operating systems, which increases your costs and chances of errors. You can use a sample template to create an ECS instance that supports dual-stack IPv4/IPv6 addressing in different operating systems.

The conditions are defined by one or more functions of Fn::And, Fn::Or, Fn::Not, and Fn::Equals. The conditions are evaluated based on the input parameters that you specify when you create or update a stack. You can reference other conditions, parameter values, and mappings in each condition. The following example shows how to create an ECS instance that supports dual-stack IPv4/IPv6 addressing. For more information about the sample template, see Create an ECS instance bound to a Dual IPv4/IPv6 Stack.

The judgement condition used in the template is whether the InstanceImageId value starts with centos. The Fn::Equals, Fn::Select, and Fn::Split functions are used in the Conditions section to perform data processing and logical judgment on the specified InstanceImageId parameter. The following sample code is used:

Parameters:
  InstanceImageId:
    Type: String
    Default: centos_7
    Description:
      zh-cn: Image ID
      en: Image ID, <br>Linux System Select:<font color='red'><b>centos_7</b></font> <br>Windows System Select:<font color='red'><b>win2008r2; win2012r2; win2016</b></font>
    Label:
      zh-cn: Image
      en: Image
Conditions:
  CreateLinux:
    Fn::Equals:
      - centos
      - Fn::Select:
          - '0'
          - Fn::Split:
              - _
              - Ref: InstanceImageId

When you run the UserData commands to initialize the configurations for creating an ECS instance, you can use the Fn::If function to evaluate the CreateLinux condition. This way, you can run different initialization commands in different operating systems to create an ECS instance that supports dual-stack IPv4/IPv6 addressing. The following sample code is used:

Fn::If:
  - CreateLinux
  - Fn::Replace:
      - ros-notify:
          Fn::GetAtt:
            - WaitConditionHandle
            - CurlCli
      - Fn::Join:
          - ''
          - - '#!/bin/sh'
            - |2

            - |
              cd /opt
            - |
              wget http://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/ipv6/rhel/ecs-utils-ipv6
            - |
              chmod +x ./ecs-utils-ipv6
            - |
              ./ecs-utils-ipv6
            - |
              ros-notify -d "{\"Data\" : \"SUCCESS\", \"Status\" : \"SUCCESS\"}"
  - Fn::Replace:
      - ros-notify:
          Fn::GetAtt:
            - WaitConditionHandle
            - PowerShellCurlCli
      - Fn::Join:
          - ''
          - - "[powershell]\r\n"
            - "New-Item -Path \"C:\\set_ipv6\" -Force -type directory\r\n"
            - "cd C:\\set_ipv6 \r\n"
            - "$install_dir=\"C:\\set_ipv6\" \r\n"
            - "$install_path = \"$install_dir\\ecs-utils-ipv6.exe\" \r\n"
            - "$tool_url = 'http://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/ipv6/win/64/ecs-utils-ipv6.exe' \r\n"
            - "Invoke-WebRequest -uri $tool_url -OutFile $install_path \r\n"
            - "Unblock-File $install_path \r\n"
            - "Start-Process -FilePath \"$install_path\" -ArgumentList \"--noenterkey\" -NoNewWindow \r\n"
            - "ros-notify\r\n"

Step 1: Create a stack

  1. Log on to the ROS console.
  2. In the left-side navigation pane, choose Templates > Sample Templates.
  3. Find the Create an ECS instance bound to a Dual IPv4/IPv6 Stack template.
  4. Click Create Stack.
  5. In the Configure Template Parameters step, set Stack Name and the following parameters.
    Parameter Description Example
    VPC IPV4 CIDR Block The IPv4 CIDR block of the virtual private cloud (VPC). We recommend that you set this parameter to one of the following CIDR blocks:
    • 10.0.0.0/8
    • 172.16.0.0/12
    • 192.168.0.0/16

    For more information, see Overview of VPCs and vSwitches.

    192.168.0/16
    VSwitch IPV4 CIDR Block The IPv4 CIDR block of the vSwitch in the VPC.

    For more information, see Overview of VPCs and vSwitches.

    192.168.0.0/24
    VSwitch Availability Zone The zone ID of the vSwitch in the VPC. Qingdao Zone C
    Image The image ID of the ECS instance. You can select a CentOS image or a Windows image.

    For more information, see Image overview.

    centos_7
    Instance Type The instance type of the ECS instance.

    Select a valid instance type. For more information, see Overview of instance families.

    ecs.c5.large
    System Disk Space The system disk size of the ECS instance.

    Valid values: 20 to 500.

    Unit: GB.

    40
    Allocate IPV4 Public IP Specifies whether to allocate an IPv4 public IP address to the ECS instance.
    • If you turn on Allocate IPV4 Public IP, the system allocates a public IP address.
    • If you turn off Allocate IPV4 Public IP, the system does not allocate a public IP address.
    Turn on Allocate IPV4 Public IP
    IPv6 Metric Bandwidth is Billed The billing method used for the public bandwidth resources of the IPv6 gateway. Valid values:
    • PayByTraffic
    • PayByBandwidth
    PayByTraffic
    IPv6 Network Gateway Public Network Bandwidth The public bandwidth of the IPv6 gateway.

    Valid values: 1 to 5000.

    Unit: Mbit/s.

    10
    Specifications for the IPv6 Gateway The type of the IPv6 gateway. Default value: Small. Valid values:
    • Small: Free Edition
    • Medium: Enterprise Edition
    • Large: Enhanced Enterprise Edition
    Small
    System Disk Type The system disk category of the ECS instance. Valid values:
    • cloud_efficiency: ultra disk
    • cloud_ssd: standard SSD
    • cloud_essd: enhanced SSD (ESSD)
    • cloud: basic disk
    • ephemeral_ssd: local SSD

    For more information, see Disks.

    cloud_efficiency
    Instance Password The password that is used to log on to the ECS instance. Test_12****
  6. Click Create.
  7. View the stack status on the Stack Information tab of the stack management page. After the stack is created, click the Outputs tab to obtain the IPv6 address of the ECS instance. Then, access the IPv6 address to manage the IPv6-enabled ECS instance.

Step 2: View resources

  1. Log on to the ROS console.
  2. In the left-side navigation pane, click Stacks.
  3. On the Stacks page, click the ID of the stack that you created.
  4. On the stack management page, click the Resources tab to view the resource list.
    The following table describes the resources in this example.
    Item Quantity Description Specifications
    ALIYUN::ECS::Instance 1 Creates an ECS instance and associates IPv4 and IPv6 addresses with the instance.
    • A single instance of the following specifications is created:
    • InstanceType: ecs.c5.large
    • SystemDiskCategory: cloud_efficiency
    • SystemDiskSize: 40 (Unit: GB)
    • AllocatePublicIP: true
    ALIYUN::VPC::Ipv6Gateway 1 Creates an IPv6 gateway. An IPv6 gateway is a device in a VPC that uses IPv6 to transmit data over the Internet. You can create only one IPv6 gateway in a VPC.
    ALIYUN::ECS::VPC 1 Creates a VPC to ensure network security. None
    ALIYUN::ECS::VSwitch 1 Creates a vSwitch to manage instances within a zone. None
    Note For more information about the resource charges, see the pricing schedule on the official website or the product pricing documentation.