Saturday, 15 October 2016

How to associate a static IP to your AWS EC2 instance using Elastic IP Addresses

Background

When you start up an EC2 instance by default you get a public IP and a public DNS by which you can reach your server from internet. However when you restart your EC2 instance your IP and your public DNS (which is infact your hostname) gets changed and that may not always be way you desire. So in this post we will see how to associate a static IP to your AWS EC2 instance using Elastic IP Addresses.


Elastic IP Addresses

An Elastic IP address is a static IP address designed for dynamic cloud computing. An Elastic IP address is associated with your AWS account. With an Elastic IP address, you can mask the failure of an instance or software by rapidly remapping the address to another instance in your account. 

An Elastic IP address is a public IP address, which is reachable from the Internet. If your instance does not have a public IP address, you can associate an Elastic IP address with your instance to enable communication with the Internet; for example, to connect to your instance from your local computer.


How to associate a static IP to your AWS EC2 instance using Elastic IP Addresses

If you have an EC2 instance running you can see the current public IP address and your public DNS entry.





And you can reach your EC2 instance using ec2-54-69-69-192.us-west-2.compute.amazonaws.com. (highlighted in image above)For eg I have deployed a webapp I can access it using URL - 
  •  http://ec2-54-69-69-192.us-west-2.compute.amazonaws.com:8080/WebDynamo
Please note these URLs are for demo purpose and may not be live when you are reading this. This is just to give you idea about what changes when you assign an elastic IP address.

As I mentioned earlier this will change when you reboot your EC2 instance. Lets see how we can assign an elastic IP.

Go to Elastic IP under Network & Security and select "Allocate New Address" and confirm.



You can see a new entry in the list with your newly assigned elastic IP. Select the entry , go to actions and select "Associate Address"


You can select either your instance your your network interface. I have selected my running EC2 instance. Then click associate.

NOTE : Careful! Note you will get a new public IP and public DNS (you will loose the previous non static one).





You will see the new IP, public DNS and Elastic Ip in EC2 dashboard.

That's it! You can now access your EC2 instance with this new IP and public DNS.  For eg -
  • http://ec2-52-24-69-249.us-west-2.compute.amazonaws.com:8080/WebDynamo
Note how the IP has changed and what was before. And this will remain same even when you reboot!

PS : WebDynamo is a sameple webapp (https://github.com/aniket91/WebDynamo) that I have deployed on tomcat on my EC2 instance for demo purpose. Please refer links in Related Links section below for more details.

Related Links

No comments:

Post a Comment

t> UA-39527780-1 back to top