There are a few different AWS IP address types that AWS instances can be associated with: Public, Private or Elastic. IP addresses will be either an IPv4 or IPv6 address. Here’s a little more about these types.
A public IP is an address that can be reached from the internet. You can use a public address for communication between the internet and your AWS instances. The best use case for Public IP addresses is for small projects where a dynamic IP can be used without much overhead. AWS has over a million public IP addresses and is constantly adding new ones.
Public IP and Elastic IP addresses are similar in the sense that they are both public and allow instances to communicate with the internet. However, they differ because of the way they are associated with EC2 instances. Public IP addresses are assigned to your instances automatically from Amazon’s pool of public IPv4 addresses once they are launched and remain assigned to the instance until the instance is stopped. If an instance is stopped, a new public IP address will be assigned once the instance is started.
Now let’s look at Elastic IP addresses..
Elastic IP Addresses
An Elastic IP address is static and designed for dynamic cloud computing. An Elastic IP address is allocated to your AWS account rather than with a specific instance. When you associate an Elastic IP address with an instance, it remains allocated to your account and specific instance until it is disassociated from either.
Elastic IP addresses are most commonly used to help with fault-tolerant instances or software. For example, if you have an EC2 instance that has an Elastic IP address and that instance is stopped or terminated, you can remap the address and re-associate it with another instance in your account. You can also re-attach the same IP address to the same EC2 instance when it is restarted, allowing IP-based connections to work seamlessly – and making it possible to start and stop instances to save money while not in use, without losing the IP address.
When it comes to pricing, you can use one Elastic IP address while your instance is running at no charge. But, if you have any additional Elastic IP addresses associated with the instance, or have an EIP reserved and do not use it, you will be charged a small hourly rate of $0.01/hr.
A private address in AWS is an IP address that is not reachable over the internet. You would use private addresses for communication between instances in the same Virtual Private Cloud (VPC). Private IP addresses remain associated with the instance when it is stopped or rebooted, it will only disassociate once the instance is terminated.
When launched, an instance can be assigned a private IP address or EC2 will automatically assign an IP address to the instance within the address range of the subnet. If you don’t specify a primary private IP address, AWS selects an available IP address in the subnet range for you. An additional private IP address, known as secondary private IP address, can also be assigned.
Multiple IP Addresses
While you can give your instance multiple private IPv4 and IPv6 IP addresses, it’s important to note that the number of interfaces and private IP addresses you can specify for an instance depends on the instance type. Multiple IP addresses can be assigned and unassigned to network interfaces that are attached to instances that are stopped or running.
Once you launch an instance, you can assign a secondary private IP address to it. If the instance has already been launched, then you can assign a secondary private IP address to a network interface. A secondary private IPv4 address that’s assigned to a network interface can be reassigned to an additional one as long as you explicitly allow it.
A few use cases where it could be useful to assign multiple IP addresses to an instance in your VPC are:
- If you want to host multiple websites on a single server by using multiple SSL certificates and associate every certificate with a specific IP address.
- Operate network appliances that have multiple IP addresses for each network interface.
- To redirect traffic to a standby instance in case your instance fails – this is done by reassigning a secondary IP address to the standby instance.
- Move private IP addresses between instances or interfaces
Additional Aspects of IP Addresses to Know
Amazon Virtual Private Cloud (VPC)
Every EC2 instance in a VPC has a private IP address, users can also opt to have a public IP address. This is a virtual network that is dedicated to your AWS account. VPC offers the ability to have an isolated network that’s dedicated to you, that you can control.
A subnet is a range of IP addresses in your VPC. You can currently create 200 subnets per VPC. if an instance is in a public subnet, it can have either a private, public or elastic IP address. However, if an instance is in a private subnet, it will only have a private IP address with the option of an elastic IP address.
Elastic Network Interface (ENI)
An ENI is a virtual interface that can be created, configured and attached to an instance within a VPC. An ENI can include a public IP address, a primary private IP address, an optional elastic IP address, one or more secondary private IP addresses, and more.
If you’re powering off servers using ParkMyCloud, then you’ll want to use an Elastic IP if you need to connect from the outside world. Otherwise, use a private IP for connections from within your AWS VPC. If you’re going to use Public IPs, make sure you’re careful when restarting the servers as the public IP address will change once an instance has been stopped and started again.