Instance Addressing
There are two kinds of IP addresses and DNS names associated with Amazon EC2 instances.
Each instance is assigned a private (RFC1918) address which is allocated by DHCP. This is the only address the operating system knows about. This is the address that should be used when communicating between Amazon EC2 instances. This address is not reachable from the Internet.
Additionally, Amazon EC2 also provides a public (Internet routable) address for each instance using Network Address Translation (NAT). This is the address that must be used from outside the Amazon EC2 network (i.e. 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 is only resolvable from within Amazon EC2. The public DNS name resolves to the public IP address from outside of Amazon EC2, and, currently, resolves to the private IP address from with Amazon EC2.
All Amazon EC2 instances are allocated a private address by DHCP. These addresses come from a range defined in "RFC 1918 - Address Allocation for Private Internets". These addresses are routable only within Amazon EC2 and are used for communication between instances.
This private address is associated exclusively with the instance for its lifetime. It is returned to Amazon EC2 when the instance terminates. You should always use the internal address when you know you are communicating between Amazon EC2 instances. Using this address assures that your network traffic follows the highest bandwidth, lowest cost, and lowest latency path through our network.
From your instance, you can determine your private IP address by asking the operating system:
PROMPT>
ifconfig eth0
or by referring to the instance data:
PROMPT>
curl http://169.254.169.254/latest/meta-data/local-ipv4
Each instance is given an internal DNS name. This name is of the form
domU-12-31-35-00-35-F3.z-2.compute-1.internal
.
It will resolve to the private IP address described above when resolved from within Amazon EC2
and will not resolve outside of Amazon EC2.
At launch time, a public address is also associated with each Amazon EC2 instance using Network Address Translation (NAT). See "RFC 1631: The IP Network Address Translator (NAT)" for more information on NAT.
This public address is associated exclusively with the instance for its lifetime. It is returned to Amazon EC2 when the instance terminates. You must use this public address to access your instance from outside of Amazon EC2 and you should distribute this address to clients (most likely via a DNS name that maps to it).
Note | |
---|---|
Amazon EC2 instances cannot currently access other instances via their public NAT IP address. Instead, the private address of the instance in the new NAT environment must be used. |
From your instance, you can determine your public IP address by referring to the instance data:
PROMPT>
curl http://169.254.169.254/latest/meta-data/public-ipv4
Each instance is also given an external DNS name.
This name is of the form ec2-72-44-45-204.z-2.compute-1.amazonaws.com
.
This DNS name will resolve to the public IP address described above when resolved from outside Amazon EC2,
and, currently, will resolve to the private IP address from within Amazon EC2. See note below.
Note | |
---|---|
Amazon EC2 instances cannot currently access other instances in the new NAT environment using their public NAT IP address. Instead, the private address of the instance in the new NAT environment must be used. To help address this issue, the Amazon EC2 network will alter DNS responses from external DNS servers by replacing the public IP address for any Amazon EC2 instance in the new NAT environment with its private IP address. In this way, DNS lookups that would resolve to a public Amazon EC2 IP address will be translated to the correct internal IP address. This only works when using the UDP DNS protocol. |