Using Instance Addressing
Topics
This section describes how to perform common instance addressing tasks.
API Overview
This section provides a brief overview of each elastic IP address operation.
-
AllocateAddress—Acquires an elastic IP address for use with your account.
-
DescribeAddresses—Lists elastic IP addresses assigned to your account.
-
ReleaseAddress—Releases an elastic IP address associated with your account.
After releasing an elastic IP address, it is released to the IP address pool and might no longer be available to your account.
-
AssociateAddress—Associates an elastic IP address with an instance.
-
DisassociateAddress—Disassociates the specified elastic IP address from the instance to which it is assigned.
Determining Your IP Addresses
This section describes how to determine your internal and external IP addresses.
AWS Management Console
To determine your private and public IP addresses
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Instances in the Navigation pane.
The console displays a list of running instances.
-
Locate and select an instance.
The console displays information about the instance in the lower pane.
-
To determine the public IP address, use the IP address specified within the Public DNS field.
-
To determine the private IP address, use the IP address specified within the Private DNS field.
Command Line Tools
To determine your private IP address in Linux and UNIX
-
Connect to the instance.
-
Enter one of the following commands:
-
#
-
#
The second option refers to the instance data. For more information, see Instance Metadata.
-
Using Elastic IP Addresses
Elastic IP addresses are static IP addresses designed for dynamic cloud computing. An elastic IP address is associated with your account, not a particular instance. You control addresses associated with your account until you choose to explicitly release them.
This section describes how to perform common elastic IP address tasks.
Allocating Elastic IP Addresses
This section describes how to assign an Amazon EC2 elastic IP address to your account and verify it.
AWS Management Console
To allocate a new IP address for use with your account
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Elastic IPs in the Navigation pane.
The console displays a list of elastic IP addresses assigned to your account.
-
Click Allocate New Address.
A confirmation dialog box appears.
-
Click Yes, Allocate.
A new elastic IP address appears in the list.
Command Line Tools
To allocate a new IP address for use with your account
-
Enter the following command:
PROMPT>
Amazon EC2 returns an elastic IP address similar to the following:
ADDRESS 75.101.155.119
Note | |
---|---|
An Elastic IP address is associated with an account and billed accordingly until the address is released using |
Describing Elastic IP Addresses
This section describes how to view the elastic IP addresses allocated to your account.
AWS Management Console
To view elastic IP addresses assigned to your account
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Elastic IPs in the Navigation pane.
The console displays a list of elastic IP addresses assigned to your account.
-
To reduce the size of the list, start typing part of the IP address or instance ID to which it is assigned in the search box.
Command Line Tools
To view elastic IP addresses assigned to your account
-
To view all elastic IP addresses assigned to your account::
PROMPT>
Amazon EC2 returns a list of elastic IP addresses similar to the following:
ADDRESS 75.101.157.145 ADDRESS 75.101.155.119
-
To verify a specific elastic IP address:
PROMPT>
ip_address
Amazon EC2 returns the specified elastic IP address, similar to the following:
ADDRESS 75.101.157.145
Associating an Elastic IP Address with a Running Instance
Once an elastic IP address is allocated, you can map it to a running instance.
AWS Management Console
To associate an elastic IP address with an instance
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Instances in the Navigation pane.
The console displays a list of running instances.
-
Write down the instance ID to associate with the elastic IP address.
-
Click Elastic IPs in the Navigation pane.
The console displays a list of elastic IP addresses assigned to your account.
-
Select an instance and click Associate.
The Associate Address dialog box appears.
-
Select the instance from the Instance ID list box and click Associate.
The elastic IP address is associated with the instance.
Command Line Tools
To associate an elastic IP address with an instance
-
Describe running instances:
PROMPT>
Amazon EC2 returns output similar to the following:
RESERVATION r-ae33c2c7 924417782495 default INSTANCE i-b2e019da ami-2bb65342 ec2-72-44-33-67.compute-1.amazonaws.com ip-10-251-71-165.ec2.internal running gsg-keypair 0 m1.small 2008-03-03T23:09:09+0000 us-east-1a INSTANCE i-b2e019db ami-2bb65342 ec2-67-202-3-83.compute-1.amazonaws.com ip-10-251-47-36.ec2.internal running gsg-keypair 1 m1.small 2008-03-03T23:09:09+0000 us-east-1a
Write down the instance ID to associate with an elastic IP address.
-
Describe elastic IP addresses assigned to the account:
PROMPT>
Amazon EC2 returns a list of elastic IP addresses similar to the following:
ADDRESS 75.101.157.145 ADDRESS 75.101.155.119
Write down the elastic IP address to associate with an instance.
-
To associate the instance and elastic IP address:
PROMPT>
ec2-associate-address -i
instance_id
ip_address
Amazon EC2 returns output similar to the following:
ADDRESS 75.101.157.145 i-b2e019da
-
Associations take a few minutes to complete. To verify the association using
ec2-describe-addresses
:PROMPT>
Amazon EC2 returns output similar to the following:
ADDRESS 75.101.157.145 i-b2e019da
-
To verify the association using
ec2-describe-instances
:PROMPT>
ec2-describe-instances-i
instance_id
Amazon EC2 returns output similar to the following:
RESERVATION r-ae33c2c7 924417782495 default INSTANCE i-b2e019da ami-2bb65342 ec2-75-101-157-145.compute-1.amazonaws.com ip-10-251-71-165.ec2.internal running gsg-keypair 0 m1.small 2008-03-03T23:09:09+0000 us-east-1a
Associating an Elastic IP Address with a Different Running Instance
Once an Elastic IP Address is allocated, you can map it to a different running instance.
Note | |
---|---|
It is highly unlikely that an instance will be configured with its original public IP address that it used prior to being mapped. |
AWS Management Console
To remap an IP address
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Instances in the Navigation pane.
The console displays a list of running instances.
-
Write down the new instance ID to associate with the elastic IP address.
-
Click Elastic IPs in the Navigation pane.
The console displays a list of elastic IP addresses assigned to your account.
-
Locate the IP address to remap and click Disassociate.
A confirmation dialog box appears.
-
Click Yes, Disassociate.
The elastic IP address is disassociated from the instance and you are returned to the list of elastic IP addresses assigned to your account.
-
Locate the IP address in the list and click Associate.
The Associate Address dialog box appears.
-
Select the new instance from the Instance ID list box and click Associate.
The elastic IP address is associated with the new instance.
Command Line Tools
To remap an IP address
-
Describe running instances:
PROMPT>
Amazon EC2 returns output similar to the following:
RESERVATION r-ae33c2c7 924417782495 default INSTANCE i-b2e019da ami-2bb65342 ec2-67-202-46-87.compute-1.amazonaws.com ip-10-251-71-165.ec2.internal running gsg-keypair 0 m1.small 2008-03-03T23:09:09+0000 us-east-1a INSTANCE i-b2e019db ami-2bb65342 ec2-75-101-157-145.compute-1.amazonaws.com ip-10-251-47-36.ec2.internal running gsg-keypair 1 m1.small 2008-03-03T23:09:09+0000 us-east-1a
Write down the instance ID to associate with an elastic IP address.
-
Associate the address with a new instance:
PROMPT>
ec2-associate-address -i
instance_id
ip_address
Amazon EC2 returns output similar to the following:
ADDRESS 75.101.157.145 i-b2e019da
-
Verify the changes:
PROMPT>
Amazon EC2 returns output similar to the following:
RESERVATION r-ae33c2c7 924417782495 default INSTANCE i-b2e019da ami-2bb65342 ec2-75-101-157-145.compute-1.amazonaws.com ip-10-251-71-165.ec2.internal running gsg-keypair 0 m1.small 2008-03-03T23:09:09+0000 us-east-1a INSTANCE i-b2e019db ami-2bb65342 ec2-67-202-46-39.compute-1.amazonaws.com ip-10-251-47-36.ec2.internal running gsg-keypair 1 m1.small 2008-03-03T23:09:09+0000 us-east-1a
Example
In the following example, web servers are connected to the Internet through elastic IP addresses and to database servers through their private IP addresses.
The administrator decides to replace a web server with a larger instance type. To do this, the administrator starts a new instance using a larger instance type (1), disassociates an elastic IP address from a running instance (2), associates the elastic IP address with the new instance (3), and terminates the old instance (4).
AWS Management Console Example
The following demonstrates how to set up these tasks using the AWS Management Console.
Launch Process
1 |
The user clicks Instances in the Navigation pane. The console displays a list of running instances. |
2 |
The user clicks Launch Instance, specifies settings that meet the new requirements, and clicks Launch. |
3 |
The user clicks Elastic IPs in the Navigation pane. The console displays a list of elastic IP addresses assigned to the account. |
4 |
The user selects the desired IP address that is assigned to another instance, clicks Disassociate, and confirms the disassociation. The user is returned to the list of elastic IP addresses. |
5 |
The user locates the IP address in the list, clicks Associate, selects the new instance, and confirms the association. The elastic IP address is assigned to the new instance. |
6 |
The user clicks Instances in the Navigation, selects the old instance, and clicks Terminate. Amazon EC2 begins shutting down the old instance. |
Command Line Tools Example
The following demonstrates how to set up these tasks using the command line tools.
PROMPT>
ec2-run-instances ami-6ba54002 -n 1 --availability-zone us-east-1a
RESERVATION r-a034c7c9 924417782495 default INSTANCE i-3ea74257 ami-6ba54002 pending 0 m1.large 2007-07-11T16:40:44+0000 us-east-1a
PROMPT>
ec2-disassociate-address 67.202.55.255
ADDRESS 67.202.55.255
PROMPT>
ec2-associate-address -i i-3ea74257 67.202.55.255
ADDRESS 67.202.55.255 i-43a4412a
PROMPT>
ec2-terminate-instances i-4bc32334
INSTANCE i-4bc32334 running shutting-down