After an Elastic Compute Service (ECS) instance is associated with an elastic IP address (EIP), the ECS instance can communicate with the Internet. You can associate an EIP with an ECS instance in a virtual private cloud (VPC).
Background information
If an EIP is associated with an ECS instance in NAT mode, both the private IP address and public IP address of the ECS instance are available for use.
After an EIP is associated with an ECS instance, you cannot view the EIP on the operation system. You can call DescribeInstances to query the public IP address assigned to the ECS instance. For more information, see DescribeInstances.
EIPs do not support protocols that are managed by NAT application layer gateways (ALGs), such as H.323, Session Initiation Protocol (SIP), Domain Network System (DNS), and Real Time Streaming Protocol (RTSP).
Prerequisites
An ECS instance is created and the ECS instance meets the following requirements:
The ECS instance is deployed in a VPC.
The ECS instance is in the Running or Stopped state.
The ECS instance is in the same region as the EIP to be associated.
The ECS instance is not assigned a static public IP address and is not associated with an EIP.
For more information about how to create an ECS instance, see Create an instance by using the wizard.
Procedure
- Log on to the Elastic IP Address console .
In the top navigation bar, select the region where the EIP is created.
On the Elastic IP Addresses page, find the EIP that you created and click Associate with Resource in the Actions column.
In the Associate EIP with Resource dialog box, set the following parameters and click OK.
Parameter
Example
Instance Type
Select ECS Instance.
Resource Group
Select the resource group to which the ECS instance belongs.
Select an instance to associate
Select the ECS instance to be associated with the EIP.
NoteEach ECS instance can be associated with only one EIP.
To associate multiple EIPs with an ECS instance, associate a secondary elastic network interface (ENI) with the ECS instance and associate EIPs with the secondary ENI. For more information, see How can I associate multiple EIPs with one ECS instance?
FAQ
Why am I unable to associate an EIP with an ECS instance?
Possible causes:
The EIP and ECS instance do not belong to the same region.
The ECS instance is assigned a public IP address or is associated with another EIP.
The ECS instance is deployed in a classic network instead of a VPC. You can associate an EIP with only an ECS instance that is deployed in a VPC.
The ECS instance is in a state that does not allow you to associate an EIP. You can associate an EIP with an ECS instance that is only in the Running or Stopped state.
To troubleshoot the issue, perform the following operations:
Check the regions in which the EIP and the ECS instance are deployed. Make sure that they are deployed in the same region, for example, in the China (Hangzhou) region.
Log on to the ECS console and check the status of the ECS instance. Make sure that the following requirements are met:
Number
Description
1
The ECS instance is assigned only a private IP address.
As shown in the following figure, if your ECS instance is assigned a public IP address or is associated with another EIP, you cannot associate the EIP with your ECS instance.
If you have other requirements, see the following topics:
2
The ECS instance is deployed in a VPC.
If the ECS instance is deployed in a classic network, you can migrate the ECS instance to a VPC. For more information, see Migrate ECS instances from a classic network to a VPC.
3
The ECS instance is in the Running or Stopped state.
For more information about how to manage the status of your ECS instance, see Instance lifecycle.
Why am I unable to view the EIP in the operating system of the ECS instance after I associate the EIP with the ECS instance?
EIPs are deployed on the Internet gateway of Alibaba Cloud and are mapped to the private network interface controllers (NICs) of the associated ECS instances through NAT. Therefore, you cannot view the EIP on the private NIC of the ECS instance.
You can expose an EIP by adding a secondary CIDR block to a VPC. For more information, see Expose an EIP on an NIC by adding a secondary CIDR block to a VPC.
How can I associate multiple EIPs with one ECS instance?
You can associate multiple EIPs with one ECS instance by using the following methods:
Associate an EIP with each secondary ENI. Then, attach the secondary ENIs to the ECS instance. The number of secondary ENIs that can be attached to an ECS instance varies with the specification of the ECS instance. For more information, see Overview of instance families.
Associate multiple EIPs with a secondary ENI in NAT mode. In this mode, each EIP is associated with a secondary private IP address of the secondary ENI. Then, associate the secondary ENI with the ECS instance. For more information, see Associate multiple EIPs with an ECS instance in NAT mode.
References
AssociateEipAddress: associates an EIP with an instance in the same region.