Doing Elastic Ips the Right Way
Tags: aws, cloud, ec2
Published: 2022-01-27 07:54:03

---
title: Doing Elastic Ips the Right Way
published: true
date: 2021-11-07 16:30:06 UTC
tags: aws,aws,cloud,ec2
canonical_url: https://www.archerimagine.com/articles/aws/aws-elastic-ip-tutorial.html
---

![AWS Made Easy | AWS Elastic IP](https://www.archerimagine.com/images/aws/ec2/06-AWS-Elastic-IP.png "AWS Made Easy | AWS Elastic IP")

## Introduction[¶](#introduction "Permanent link")

You are in the middle of understanding each of the [steps in creating an EC2 instance](https://www.archerimagine.com/articles/aws/aws-ec2-tutorial.html). You have till now learned about Instance types, AMIs, CLIs and SDKs, and the pricing of AWS EC2 instance. One important step in this is to communicate with the AWS EC2 instance. Launching an AWS EC2 instance is of no use. There should be a medium to communicate with it. The communication may be external or internal.

Whichever type of communication you try to make, IPs play an important role. IP is like a unique address for your AWS EC2 instance, which can help you to connect with the instance. We have 3 types of IPs associated with an AWS EC2 instance.

- Private IP
- Public IP
- Elastic IP

Let's jump right into learning what these different types of IPs are and what are its benefits.

## Private IP[¶](#private-ip "Permanent link")

You might have already guessed by the name, this is a private IP. This is the default IP address associated with an AWS EC2 instance. This is an IP address which disassociated with an AWS EC2 instance based on these 2 parameters.

- The VPC in which it is present.
- The Subnet in within the VPC it is present.

AWS EC2 instance within the VPC can communicate with each other based on the private IP.

Each AWS EC2 instance, will have a private IP associate with it. This private IP is visible only within the VPC and not outside it.

If you want to connect to this AWS EC2 instance from your Laptop, it will not be possible as for this communication we need a Public IP.

Your laptop should have a Public IP for connecting to the AWS EC2 instance.

![AWS Made Easy | AWS IP | Private IP](https://www.archerimagine.com/images/aws/ec2/06-AWS-Elastic-IP-Public-Private-IP.png "AWS Made Easy | AWS IP | Private IP")

You should keep these things in mind while using private IP.

- Private IP on an AWS EC2 instance does not change on reboot.
- It also does not change when the AWS EC2 instance is in stopping state.
- No two AWS EC2 instance, can have the same private IP in the same VPC.
- You will need an AWS EC2 with private IP to launch a database system.
  - This provides inherit protection from attach outside the AWS environment.

## Public IP[¶](#public-ip "Permanent link")

AWS EC2 instance cannot function in isolation. There are certain use case which needs only private IPs, like for database machine.

A web server should be open to all. If you launch a web server in an AWS EC2 instance it should be accessible from outside. You will need a public IP on this AWS EC2 instance to achieve this.

Your AWS EC2 instance communicates over open Internet using a public IP. An AWS EC2 instance, can have both private and public IP associated with it.

When you stop an AWS EC2 instance, it releases the public IP associated with it. Public IP are a scarce resource in AWS, it's use should demand justification.

You can still keep the public IP address on the AWS EC2 instance if it reboots.

All AWS EC2 instance having a public IP does not connect to the Internet. You should enable the relevant security groups.

When you launch an AWS EC2 instance, in the default VPC, it has a Public IP. This is not the case of non default VPC.

![AWS Made Easy | AWS IP | Public IP](https://www.archerimagine.com/images/aws/ec2/06-AWS-Elastic-IP-Public-Private-IP.png "AWS Made Easy | AWS IP | Public IP")

## Elastic IP[¶](#elastic-ip "Permanent link")

You might be wondering, Private IP and Public IP both solve a specific problem.

_What is the need of Elastic IP?_

If you want to access your AWS EC2 instance with a fixed IP every time, How do you do it? The AWS EC2 instance releases the public IP when it is in stopped state.

How do you assign a Static Public IP to your AWS EC2 Instance.

AWS Elastic IP belongs to an account and not to an Instance. Once you create an Elastic IP, you can assign it to any AWS EC2 instance.

The Elastic IP and the AWS EC2 has a symbiotic relationship. Once the AWS EC2 instance terminates, it frees the Elastic IP.

You can remove the Elastic IP attached to current AWS EC2 instance once the purpose finishes.

### Cost of AWS Elastic IP[¶](#cost-of-aws-elastic-ip "Permanent link")

AWS Elastic IP has a weird pricing policy. It is free to use, till it's used.

If the elastic IP is not used, then it is chargeable.

These conditions will determine if your Elastic IP is in use.

- AWS EC2 instance has an Elastic IP associated with itself.
- The AWS EC2 instance is in running state.
- Only one Elastic IP attached with this AWS EC2 instance.
- The Elastic IP associated with an attached network interface.

### AWS Elastic IP limits[¶](#aws-elastic-ip-limits "Permanent link")

AWS limits only 5 Elastic IP address per region. You can alter the limit from the console.

_Is AWS Elastic IP free?_

AWS elastic IP is free if it is in use. It's charged when not in use.

_What is an Elastic IP in AWS?_

It is a Static public IP associated with an instance.

In case of an instance failure, Elastic IP added to a new instance, without any impact on incoming traffic.

## Public IP Vs Elastic IP[¶](#public-ip-vs-elastic-ip "Permanent link")

| Public IP | Elastic IP |
| --- | --- |
| It is associated with the AWS EC2 Instance | It is associated with the AWS Account, and not the instance. |
| Public IP cannot be manually attached from one instance to another. | It can be removed from one instance and attached to another. |
| Public IP is released when the instance is stopped. | Elastic IP is not released, when the instance is stopped. |
| Public IP is free by default. | Elastic IP is charged if it is Idle. |
| An instance, launched in default VPC will have a public IP associated with it. | Elastic IP is manually assigned, it is not attached by default. |
| IPv4 and IPv6 support. | Only IPv6 support. |

![AWS Made Easy | AWS IP | Elastic IP Vs Public IP](https://www.archerimagine.com/images/aws/ec2/06-AWS-Elastic-IP-Elastic-IP-Vs-Public-IP.png "AWS Made Easy | AWS IP | Elastic IP Vs Public IP")

## Static IP Vs Elastic IP[¶](#static-ip-vs-elastic-ip "Permanent link")

AWS Elastic IP is a static public IP for an AWS account.

There is a benefit in using Elastic IP

- You can associate a new EC2 instance when old EC2 instance fails. 
- This happens through code, and no manual attention required. 

## Assign Public IP to an AWS EC2 Instance after launch[¶](#assign-public-ip-to-an-aws-ec2-instance-after-launch "Permanent link")

If you have an AWS EC2 instance, in running state having a private IP. How do you attach a public IP to this running instance. This is a million dollar question for you.

The only option to attach a public IP to an already running AWS EC2 instance is AWS Elastic IP. You can create a new Elastic IP. Once created you can associate this Elastic IP with the running instance. The running instance picks the new Elastic Public IP.

![AWS Made Easy | AWS IP | Attach Public IP to a running AWS Instance](https://www.archerimagine.com/images/aws/ec2/06-AWS-Elastic-IP-Attach-Public-IP-To-Instance.png "AWS Made Easy | AWS IP | Attach Public IP to a running AWS Instance")

## Conclusion[¶](#conclusion "Permanent link")

You have got a significant insight into the 3 different IP provided by AWS.

Private IP secures the AWS EC2 instance from outside traffic. Like, in database system, you do not need any outside traffic reaching it. AWS EC2 always have a private IP.

No communication inside a VPC is possible without these private IP. It's attached to the AWS EC2 instance throughout the life cycle of the instance. It's released only when the instance terminated.

When the AWS EC2 instance need communication with outside world, Public IP is the medium. Web Server needs public communication. When AWS EC2 instance launched in default VPC, its comes with Public IP.

It's assigned before creation or restart of the instance. The public IP is only associated with the AWS EC2 instance till instance is in running or reboot state. In any other state it release the Public IP.

Elastic IP associated with an AWS account and not AWS EC2 instance. The Elastic IP switched between instances. This only supports IPv4 unlike others which supports IPv6.

Elastic IP comes in helpful, when the EC2 instance fails. You can use Elastic IP reassigned to another AWS EC2. This is not a good architecture, but you should remember this is an option though not used.

Now the idea of AWS elastic IP, public IP, private IP might be clear. If you want to launch an EC2 instance. Checkout, the free tier EC2 instance launch article. See [Step by Step guide to create an EC2 instance](https://www.archerimagine.com/articles/aws/aws-ec2-tutorial.html).

## Reference[¶](#reference "Permanent link")

- [YouTube | Alan Rodrigues | AWS Elastic IP](https://www.youtube.com/watch?v=mgfpduy5ZAo)
- [YouTube | KnowledgeIndia | AWS - Difference between Elastic, Public & Private IP | DEMO](https://www.youtube.com/watch?v=MTBR9jyD5RM)
- [YouTube | KnowledgeIndia | AWS ENI - Elastic Netwok Interface - Mutiple IPs on an EC2 (DEMO)](https://www.youtube.com/watch?v=PIMls6oGc0U) 
- [Amazon EC2 instance IP addressing](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html)
- [Does private IP of an AWS instance change while instance is running?](https://stackoverflow.com/questions/54128771/does-private-ip-of-an-aws-instance-change-while-instance-is-running)
- [An IP address of EC2 instance gets changed after the restart](https://stackoverflow.com/questions/55414302/an-ip-address-of-ec2-instance-gets-changed-after-the-restart)
- [Why am I being billed for Elastic IP addresses when all my Amazon EC2 instances are terminated?](https://aws.amazon.com/premiumsupport/knowledge-center/elastic-ip-charges/)
- [Difference between static IP and elastic IP address?](https://serverfault.com/questions/390841/difference-between-static-ip-and-elastic-ip-address)
- [Elastic IP, Static IP, Public IP. What’s the Difference?](https://medium.com/@datapath_io/elastic-ip-static-ip-public-ip-whats-the-difference-8e36ac92b8e7)
- [What's the difference between a public IP and an elastic IP in AWS EC2?](https://www.quora.com/Whats-the-difference-between-a-public-IP-and-an-elastic-IP-in-AWS-EC2)
- [Assign Public IP (not Elastic IP) after instance launched.](https://serverfault.com/questions/706560/assign-public-ip-not-elastic-ip-after-instance-launched)