Learn what is elastic IP and public IP means in AWS. List out all differences between elastic IP and public IP in AWS.
I was having a conversation about AWS with one of my friend and he came up with the question what is the difference between elastic IP and public IP? So, I explained him and thought why not draft an post about it! So in this article, we will see the difference between elastic IP and public IP in AWS. This can be cloud interview question so without much delay lets get into elastic IP vs public IP battle.
What is elastic IP in AWS?
First thing first, let’s get basics clear. What is elastic IP? It is IPv4 IP address designed and exist for dynamic cloud computing and reachable over the internet. By name, you can imagine it’s a flexible IP which can be used or mapped rapidly from one EC2 instance to another when a currently associated instance fails. This way end user or application continue to talk to the same IP even if instance behind it fails. They are like static public IPs allocated for your AWS account.
What is Public IP in AWS?
Public IP is IPv4 IP address which is reachable over the internet. Remember switching flexibility of Elastic IP is not available for this IP. Amazon also assigns external/Public DNS name (shown in screenshot) to instances who receives public IP. Public IP of the instance is mapped to primary private IP of that instance via NAT (Network Address Translation) by default.
Refer below screenshot from EC2 console of AWS and observe where you can check your elastic IP, public IP, and public DNS name.
Difference between elastic IP and Public IP
Now let’s look at the difference between these two IP types.
- Whenever new EC2 instance spins up, its assigned with public IP by default. Elastic IP is not assigned by default.
- Elastic IPs are assigned to AWS accounts which you can attach to instances. Public IPs assigned to instances directly.
- When an instance is stopped and started again, public IP gets changed. But if the instance is assigned with elastic IP, it will remain the same even if the instance is stopped and started again.
- If elastic IP is allocated to your account and not in use then you will be charged for it on an hourly basis.
- Public IP released once your instance is stopped so no question of getting charged for not using it.
- You won’t be able to re-use same public IP since its allocated from free IP pool. You can always re-use, re-attach elastic IP to other instance when it is released from current instance.
- You can not manually attach or detach public IP from the instance. It’s auto allocated from the pool. Elastic IP can be manually attached and detach from the instance.
- You can have maximum 5 elastic IP to your account per region. But, you can have as many public IPs as EC2 instances you spin up.
- You can have either of them for an instance. If you assign elastic IP to instance then its currently assigned public IP will be released to the free pool.