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 egress 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:
Specify the primary private IPv4 address when creating an ECS instance
Procedure
Log on to the ECS instance buy page.
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 icon.
Select Specify Primary Private IP Address of Primary ENI and set a primary private IPv4 address for the ECS instance.
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
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
Log on to the ECS console.
In the left-side navigation pane, choose .
In the top navigation bar, select the region and resource group to which the resource belongs.
Find the ECS instance that you want to manage. In the Actions column, select
.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.
In the Actions column of the ECS instance that you want to manage, select
. The new primary private IP address is effective after the ECS instance restarts.(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.
Alternatively, call the ModifyInstanceVpcAttribute API operation to change the primary private IP address for an existing ECS instance.
Primary private IP address of a secondary ENI
You can use one of the following methods to create a secondary ENI:
Create a secondary ENI alongside the ECS instance creation
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, without needing additional steps. You can associate up to two ENIs to an ECS instance: one primary (associated automatically) and one secondary. Note that you cannot specify the primary private IP address for a secondary ENI created in this manner.
Create a secondary ENI separately
Create ENIs separately on the page. These ENIs can be associated with an ECS instance as secondary ENIs. You can specify the primary private IPv4 address for them during creation, provided that the IP address is an idle IP address within the IPv4 CIDR block of the vSwitch. If not specified, an idle private IPv4 address is automatically assigned to such an ENI upon creation. For more information, see Create a secondary ENI.
Once created, the primary private IPv4 address of a secondary ENI cannot be changed.