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).
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.
- 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.
Select ECS Instance.
Select the resource group to which the ECS instance belongs.
Select a mode in which the EIP is associated with the ECS instance.
You can select only NAT Mode. In NAT mode:
Both the private IP address and public IP address of the ECS instance are available for use.
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).
Select an instance to associate.
Select the ECS instance to be associated with the EIP.Note
Each ECS instance can be associated with only one EIP.
Why am I unable to associate an EIP with an ECS instance?
- The EIP and the ECS instance are deployed in different regions.
- The ECS instance is assigned a public IP address or is associated with another EIP.
- The ECS instance runs in the classic network instance. EIPs can be associated only with ECS instances that are deployed inside VPCs. If your ECS instance is not deployed in a VPC, you cannot associate an EIP with the ECS instance.
- 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.
- 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, both services are deployed 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:
No Description ① 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.For more information, see:
② The network type of the ECS instance is VPC.
If the network type of the ECS instance is classic network, you can change it to VPC. For more information, see Migrate ECS instances from the classic network to a VPC.
③ 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 ENIs of the associated ECS instances through NAT. Therefore, you cannot view the EIP on the private ENI of the ECS instance.
When you associate an EIP with a secondary ENI, you can select the cut-through mode. In cut-through mode, the EIP replaces the private IP address of the secondary ENI. The secondary ENI serves as a public network interface controller (NIC) and the private network feature is no longer available. To query the EIP in the operating system, run the ifconfig or ipconfig command. For more information, see Associate a secondary ENI in cut-through mode (not recommended).
How can I associate multiple EIPs with one ECS instance?
- 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 based on 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.
AssociateEipAddress: associates an EIP with an instance in the same region.