AWS :Public IP vs Private IP vs Elastic IP

AWS :Public IP vs Private IP vs Elastic IP

Β·

4 min read

πŸ“’ Unveiling the Mysteries of IP Addresses: A Hands-On Exploration πŸ”

We're going to dive deep into the fascinating world of IP addresses and witness their behavior in action! Get ready for a hands-on adventure filled with real-time examples, emojis, and bite-sized explanations. Let's go! πŸš€

🌐 Public IPv4 Addresses: The Internet Gatekeepers

✨ Public IPv4 addresses are like digital passports, allowing our EC2 instances to communicate with the World Wide Web.

πŸ”‘ In our real-time example, we have a public IPv4 address assigned to our instance, which we can use to SSH into it. πŸ’»

Let's say our instance has the public IP address: 52.87.225.205

We can use this IP to SSH into our instance with the following command:

ssh -i /path/to/your/key.pem ec2-user@52.87.225.205

And voila! We're now connected to our instance using its public IP address.

🏑 Private IPv4 Addresses: The Local Network Companions

πŸ”’ Once we're logged into our instance, we can see that it also has a private IPv4 address assigned as its hostname.

🌐 This private IP allows communication within the AWS private network.

🚫 However, if we disconnect from our instance and try to SSH using the private IP, it won't work because we're not connected to the AWS private network.

⚠️ To access our instance from the public internet, we must use the public IP address.

Let's check our instance's private IP address by running the following command:

hostname -I

This might display something like: 72-31-18-80.ec2.internal

Now, let's try to SSH into our instance using this private IP address:

ssh -i /path/to/your/key.pem ec2-user@10.0.0.4

As expected, this command will fail because we're not connected to the AWS private network.

πŸ”„ Observing IP Address Changes: A Real-Time Experiment

Let's see what happens when we stop and start our EC2 instance:

πŸ’€ First, we stop our instance and note down its current public IP address, which is 52.87.225.205.

⏳ After a short wait, we start the instance again. πŸ†• Lo and behold! Our instance now has a brand new public IP address, let's say 54.197.22.115.

πŸ”‘ The private IP address, however, remains unchanged at ip-172-31-18-80.ec2.internal.

πŸ”— Introducing Elastic IP Addresses: The Persistent Companions

πŸ”’ If we want our instance to maintain the same public IP address, even after stopping and starting, we can use an Elastic IP.

πŸ’° In our example, we allocate a new Elastic IP from Amazon's pool of IPv4 addresses, let's say 54.236.131.54. πŸ”— We then associate this Elastic IP 54.236.131.54 with our running instance. πŸŽ‰ Now, even if we stop and start our instance, the public IP (the Elastic IP) remains the same at 54.236.131.54!

How to allocate Elastic IP address to EC2 Instance

Go to EC2 -Dashboard -Select Elastic IP

Click on Allocate Elastic IP address -

1.Select your region

2.Click on allocate

Elastic IP allocated successfully

Click on Actions->Associate Elastic IP address

Select your Instance IP and Private IP address ->Click on Associate

Elastic IP Associated successfully

Click on Instance-See your created instance detailed -Observe Elastic IP is displayed

Now Stop your Instance and restart the instance ,and observe Public is not changed this time because we have allocated Elastic IP

πŸ†“ Free Tier Fun: Managing Public IP Costs

πŸ’Έ AWS charges a small hourly fee for using public IPv4 addresses, including Elastic IPs.

🎁 However, you get 750 hours per month of free public IPv4 usage with the free tier.

πŸ’° To avoid unexpected charges, remember to terminate your instances and release Elastic IPs when you're done using them.

🏁 The Finish Line: Wrapping Up Our Hands-On Adventure

πŸ”„ We witnessed how stopping and starting an instance changes its public IP address. πŸ”— We learned how to use an Elastic IP to maintain a persistent public IP. πŸ’Έ We discussed the importance of managing public IP costs and utilizing the free tier wisely.

Now, you're equipped with a deeper understanding of IP addresses and their behavior in AWS. Keep exploring, keep learning, and most importantly, keep having fun! πŸŽ‰

Thank you for joining me on this journey through the world of cloud computing! Your interest and support mean a lot to me, and I'm excited to continue exploring this lfascinating field together. Let's stay connected and keep learning and growing as we navigate the ever-evolving landscape of technology.

LinkedIn Profile: https://www.linkedin.com/in/prasad-g-743239154/

Feel free to reach out to me directly at . I'm always open to hearing your thoughts and suggestions, as they help me improve and better cater to your needs. Let's keep moving forward and upward!

If you found this blog post helpful, please consider showing your support by giving it a round of applauseπŸ‘πŸ‘πŸ‘. Your engagement not only boosts the visibility of the content, but it also lets other DevOps and Cloud Engineers know that it might be useful to them too. Thank you for your support! πŸ˜€

Thank you for reading and happy deploying! πŸš€

Best Regards,

Sprasad

Β