When working with cloud infrastructure on Amazon Web Services (AWS), networking is one of the most essential aspects. One common question beginners have is:
๐ โHow can I keep the same public IP address for my server, even if I restart or stop it?โ
That is where Elastic IP (EIP) comes in. In this guide, I will dive into Elastic IP addresses, covering everything from basic concepts to advanced usage and best practices.
What is an Elastic IP in AWS?
An Elastic IP (EIP) is a static, public IPv4 address provided by AWS. Unlike normal public IPs that can change when you stop/start an EC2 instance. Elastic IPs remain constant and can be remapped to any instance in your AWS account.
Think of it as:
- Dynamic Public IP = like our home Wi-Fi, which changes after reboot.
- *Elastic IP * = like owning a permanent office address.
Why Use an Elastic IP?
Here are the main benefits:
- Consistency โ Keeps the same IP even if you restart EC2
- Flexibility โ Can be remapped between instances during failure
- High Availability โ Helps in failover scenarios
- External Access โ Useful when clients or third-party services need a fixed IP
How to Allocate and Associate an Elastic IP (Step-by-Step)
Step 1: Allocate an Elastic IP
- Go to AWS Management Console โ EC2 Dashboard
- In the sidebar, click Elastic IPs
- Choose Allocate Elastic IP address
- Select Amazonโs pool of IPv4 addresses and confirm
Step 2: Associate Elastic IP with EC2
- Select your Elastic IP โ Click Actions โ Associate Elastic IP address
- Choose the EC2 instance or network interface
- Click Associate
โ Done! Now your EC2 instance has a permanent public IP.
Elastic IP with AWS CLI
You can also manage Elastic IPs using the AWS CLI:
Allocate Elastic IP:
aws ec2 allocate-address --domain vpc
Associate Elastic IP:
aws ec2 associate-address \
--instance-id i-1234567890abcdef0 \
--allocation-id eipalloc-12345678
Release Elastic IP:
aws ec2 release-address --allocation-id eipalloc-12345678
Use Cases of Elastic IP
- Production Servers โ Keep the same IP for web apps or APIs
- Disaster Recovery โ Quickly remap IP to a standby instance
- Whitelisted Services โ If your app connects to third-party APIs that require fixed IPs
- DNS Mapping โ Point your domain/subdomain to a permanent IP
Pricing and Best Practices
- Elastic IP is free as long as it is attached to a running EC2 instance
- AWS charges for unused Elastic IPs
Best practice
- Do not reserve unused EIPs
- Use Elastic Load Balancers (ELB) or Route 53 for scalability instead of relying solely on EIPs
Conclusion
An Elastic IP in AWS is a powerful way to maintain stable and reliable connectivity for your applications. While they are extremely useful, always follow best practices and avoid keeping unused Elastic IPs to save costs.
By mastering Elastic IP, you take a solid step forward in understanding AWS networking from beginner to advanced.
Top comments (0)