Associate an Elastic IP address with an instance - Amazon Elastic Compute Cloud

Associate an Elastic IP address with an instance

After you allocate an Elastic IP address, you can associate it with an AWS resource, such as an EC2 instance, NAT gateway, or Network Load Balancer. To associate an Elastic IP address with a different AWS resource later on, you can disassociate it from its current resource and then associated it with the new resource.

Complete the following tasks to associate an Elastic IP address with an EC2 instance.

Allocate an Elastic IP address

Complete the steps in this section to allocate an Elastic IP address.

Console
To allocate an Elastic IP address
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Network & Security, Elastic IPs.

  3. Choose Allocate Elastic IP address.

  4. (Optional) When you allocate an Elastic IP address (EIP), you choose the Network border group in which to allocate the EIP. A network border group is a collection of Availability Zones (AZs), Local Zones, or Wavelength Zones from which AWS advertises a public IP address. Local Zones and Wavelength Zones may have different network border groups than the AZs in a Region to ensure minimum latency or physical distance between the AWS network and the customers accessing the resources in these Zones.

    Important

    You must allocate an EIP in the same network border group as the AWS resource that will be associated with the EIP. An EIP in one network border group can only be advertised in zones in that network border group and not in any other zones represented by other network border groups.

    If you have Local Zones or Wavelength Zones enabled (for more information, see Enable a Local Zone or Enable Wavelength Zones), you can choose a network border group for AZs, Local Zones, or Wavelength Zones. Choose the network border group carefully as the EIP and the AWS resource it is associated with must reside in the same network border group. You can use the EC2 console to view the network border group that your Availability Zones, Local Zones, or Wavelength Zones are in. Typically, all Availability Zones in a Region belong to the same network border group, whereas Local Zones or Wavelength Zones belong to their own separate network border groups.

    If you don't have Local Zones or Wavelength Zones enabled, when you allocate an EIP, the network border group that represents all of the AZs for the Region (such as us-west-2) is predefined for you and you cannot change it. This means that the EIP that you allocate to this network border group will be advertised in all AZs in the Region you're in.

  5. For Public IPv4 address pool, choose one of the following:

    • Amazon's pool of IPv4 addresses—If you want an IPv4 address to be allocated from Amazon's pool of IPv4 addresses.

    • Public IPv4 address that you bring to your AWS account—If you want to allocate a non-contiguous (non-sequential) public IPv4 address from an IP address pool that you have brought to your AWS account. This option is disabled if you do not have any IP address pools. For more information about bringing your own IP address range to your AWS account, see Bring your own IP addresses (BYOIP) to Amazon EC2.

    • Customer owned pool of IPv4 addresses—If you want to allocate an IPv4 address from a pool created from your on-premises network for use with an AWS Outpost. This option is disabled if you do not have an AWS Outpost.

    • Allocate using an IPAM IPv4 pool: If you want to allocate sequential Elastic IP addresses from a contiguous public IPv4 block in an IPAM pool. Allocating sequential Elastic IP addresses can significantly reduce management overhead for security access control lists and simplify IP address allocation and tracking for enterprises scaling on AWS. For more information, see Allocate sequential Elastic IP addresses from an IPAM pool in the Amazon VPC IPAM User Guide.

  6. (Optional) To add a tag, choose Add new tag and enter a tag key and a tag value.

AWS CLI
To allocate an Elastic IP address

Use the allocate-address AWS CLI command.

aws ec2 allocate-address
PowerShell
To allocate an Elastic IP address

Use the New-EC2Address AWS Tools for Windows PowerShell command.

New-EC2Address -Domain Vpc

Associate an Elastic IP address

If you're associating an Elastic IP address with your instance to enable communication with the internet, you must also ensure that your instance is in a public subnet. For more information, see Enable internet access using an internet gateway in the Amazon VPC User Guide.

Console
To associate an Elastic IP address with an instance
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Elastic IPs.

  3. Select the Elastic IP address to associate and choose Actions, Associate Elastic IP address.

  4. For Resource type, choose Instance.

  5. For instance, choose the instance with which to associate the Elastic IP address. You can also enter text to search for a specific instance.

  6. (Optional) For Private IP address, specify a private IP address with which to associate the Elastic IP address.

  7. Choose Associate.

To associate an Elastic IP address with a network interface
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Elastic IPs.

  3. Select the Elastic IP address to associate and choose Actions, Associate Elastic IP address.

  4. For Resource type, choose Network interface.

  5. For Network interface, choose the network interface with which to associate the Elastic IP address. You can also enter text to search for a specific network interface.

  6. (Optional) For Private IP address, specify a private IP address with which to associate the Elastic IP address.

  7. Choose Associate.

AWS CLI
To associate an Elastic IP address

Use the associate-address AWS CLI command.

aws ec2 associate-address --instance-id i-0b263919b6498b123 --allocation-id eipalloc-64d5890a
PowerShell
To associate an Elastic IP address

Use the Register-EC2Address AWS Tools for Windows PowerShell command.

Register-EC2Address -InstanceId i-0b263919b6498b123 -AllocationId eipalloc-64d5890a

Disassociate an Elastic IP address

You can disassociate an Elastic IP address from an instance or network interface at any time. After you disassociate the Elastic IP address, you can reassociate it with another resource.

Console
To disassociate and reassociate an Elastic IP address
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Elastic IPs.

  3. Select the Elastic IP address to disassociate, choose Actions, Disassociate Elastic IP address.

  4. Choose Disassociate.

AWS CLI
To disassociate an Elastic IP address

Use the disassociate-address AWS CLI command.

aws ec2 disassociate-address --association-id eipassoc-12345678
PowerShell
To disassociate an Elastic IP address

Use the Unregister-EC2Address AWS Tools for Windows PowerShell command.

Unregister-EC2Address -AssociationId eipassoc-12345678