π’ 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.ec
2.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 spujari.devops@gmail.com. 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