All Products
Search
Document Center

Elastic Compute Service:Primary private IP address

Last Updated:Apr 14, 2025

A private IP address typically refers to a private IPv4 address. Each elastic network interface (ENI) includes a default primary private IP address, which is integral to its functionality. You may encounter scenarios where you need to specify the primary private IPv4 address when you are creating an Elastic Compute Service (ECS) instance, or change the primary private IPv4 address of an ECS instance to resolve IP address conflicts or expand your network. This topic describes how to specify the primary private IPv4 address when creating an ECS instance, and how to change the primary private IPv4 address for an existing ECS instance or an associated secondary ENI.

Background information

  • Upon creation, an ECS instance is equipped with a default ENI, known as the primary ENI. This primary ENI receives a primary private IPv4 address from the IPv4 CIDR block of the vSwitch, which functions as the default private IP address.

  • Secondary ENIs, similar to the primary ENI, receive a default primary private IPv4 address that cannot be unassociated from the ENI.

  • If you want more IP addresses in addition to the primary private one, you can add secondary private IP addresses to the primary ENI or introduce more secondary ENIs to your ECS instance. The figure below illustrates the relationship between ECS instance ENIs and private IP addresses:

image

Specify the primary private IPv4 address when creating an ECS instance

Procedure

  1. Log on to the ECS instance buy page.

  2. On the Custom Launch tab, in the Network and Zone section, select an existing virtual private cloud (VPC) and an existing vSwitch, or click Create VPC and Create vSwitch to create a VPC and a vSwitch in the VPC console, respectively. After both are created, refresh the ECS instance buy page for the updated VPC list and vSwitch list by clicking the refresh icon.

  3. Select Specify Primary Private IP Address of Primary ENI and set a primary private IPv4 address for the ECS instance.

    image

Note

Alternatively, call the RunInstances API operation during ECS instance creation and set the PrivateIpAddress parameter to specify the primary private IPv4 address for the ECS instance.

Change the primary private IPv4 address for an existing ECS instance

Important

If you have configured the primary private IP address of your ECS instance in your applications, whitelists for cloud services (such as databases and caching services), or system configuration files (such as /etc/hosts), please remember to update the IP address configuration after a change. This is important to avoid any business interruptions.

Prerequisites

  • The ENI of your ECS instance does not have a secondary private IP address configured.

  • Your ECS instance is in the Stopped state. For more information, see Stop an instance.

Procedure

  1. Go to ECS console - Instance.

  2. In the top navigation bar, select the region and resource group of the resource that you want to manage. 地域

  3. Find the ECS instance that you want to manage and click its ID. In the upper-right corner, choose All Actions > Network and Security Group > Modify Private IP Address.

  4. In the Modify Private IP Address dialog box, configure the parameters and click OK.

    • Before changing the vSwitch, ensure the new vSwitch is in the same zone as the ECS instance.

    • If not changing the vSwitch, directly modify the primary private IP address. If the primary private IP address is left blank, the system automatically assigns a new primary private IP address.

    • To use a vSwitch that is in a different zone from your ECS instance, you must migrate your ECS instance to the zone of the vSwitch. For more information, see Change instance types across zones.

  5. On the instance details page, in the upper-right corner, choose All Actions > Instance Status > Start. The new primary private IP address is effective after the ECS instance restarts.

  6. (Optional) After changing the primary private IP address, you may need to update the security group rules for your ECS instance to reflect the new IP address. For more information, see Modify a security group rule.

Note

Alternatively, call the ModifyInstanceVpcAttribute API operation to change the primary private IP address for an existing ECS instance.

Primary private IPv4 address of a secondary ENI

A secondary ENI is also assigned a primary private IPv4 address within the CIDR block of the connected vSwitch. Depending on how a secondary ENI is created, whether you can change its primary private IPv4 address differs:

  • Created alongside an ECS instance

    When creating an ECS instance, you have the option to include an ENI that is automatically assigned a primary private IPv4 address and is associated with the ECS instance. For such secondary ENIs, you cannot specify the primary private IP address.

  • Created separately

    When creating an ENI separately, you can specify an available IP address within the CIDR block of the selected vSwtich as its primary private IPv4 address. If you skip this configuration, the system automatically assigns an available private IP address to the ENI.

For more information, see Separately create an ENI.

Note

Once created, the primary private IPv4 address of a secondary ENI cannot be changed. If you want to use another IP address, create a new secondary ENI, specifying a new primary private IPv4 address within the CIDR block of the connected vSwitch. Then, associate the new secondary ENI to the ECS instance.