Instance Addressing
All Amazon EC2 instances are assigned two IP addresses at launch: a private address (RFC 1918), and a public address. The public IP address is directly mapped to the private address through Network Address Translation (NAT). Private addresses are only reachable from within the Amazon EC2 network. Public addresses are reachable from the Internet.
Amazon EC2 also provides an internal DNS name and a public DNS name which map to the private and public IP addresses respectively. The internal DNS name can only be resolved within Amazon EC2. The public DNS name resolves to the public IP address outside the Amazon EC2 network and the private IP address within the Amazon EC2 network.
Note | |
---|---|
If you require persistent Internet routable IP addresses that can be assigned to and removed from instances as necessary, use elastic IP addresses. For more information, see Elastic IP Addresses. |
All Amazon EC2 instances are allocated a private address by DHCP. These ranges are defined in RFC 1918, are only routable within Amazon EC2, and are used for communication between instances. For more information, go to RFC 1918.
This private address is associated exclusively with the instance for its lifetime and is only returned to Amazon EC2 when the instance terminates.
Always use the internal address when you are communicating between Amazon EC2 instances. This ensures that your network traffic follows the highest bandwidth, lowest cost, and lowest latency path through our network.
To determine your IP address
-
Connect to the instance.
-
Enter one of the following commands:
-
PROMPT>
-
PROMPT>
curl http://169.254.169.254/latest/meta-data/local-ipv4
The second option refers to the instance data. For more information, see Instance Metadata.
-
Each instance is provided an internal DNS name in the form
ip-10-251-157-188.ec2.internal
.
It will resolve to the private IP address of the instance from within Amazon EC2;
it will not resolve outside of Amazon EC2.
At launch, a public address is also associated with each Amazon EC2 instance using Network Address Translation (NAT). For more information about NAT, go to "RFC 1631: The IP Network Address Translator (NAT)".
This public address is associated exclusively with the instance until it is terminated or replaced with an elastic IP address.
Important | |
---|---|
Amazon EC2 instances that access other instances through their public NAT IP address are charged for regional data transfer. |
The following example shows how you can determine your public IP address from your instance by referring to the instance data.
PROMPT>
curl http://169.254.169.254/latest/meta-data/public-ipv4
Each instance is provided an external DNS name in the form
ec2-72-44-45-204.compute-1.amazonaws.com
.
This DNS name resolves to the public IP address of the instance outside
the Amazon EC2 network and the private IP address from within Amazon EC2 network.