How to Attach an Elastic IP to an EC2 Instance
To attach an Elastic IP to an EC2 instance, open EC2 → Elastic IPs → Allocate Elastic IP address, then select it → Actions → Associate Elastic IP address → choose the instance → Associate. The instance keeps this static public IPv4 address after every stop and start, until you release it. AWS charges for every public IPv4 address, so release Elastic IPs you no longer need.
Friends, you stopped the instance at night and started it in the morning – and the IP had changed! The website link, the DNS record, everything broke. One of my students had sent his GF the link to his proposal website, and in the morning all she saw was an error. We won't let that happen. There is one fix: Elastic IP.
मित्रांनो, रात्री instance stop केला आणि सकाळी start केला – आणि IP बदललेला! वेबसाइटची लिंक, DNS रेकॉर्ड, सगळं तुटलं. माझ्या एका स्टुडंट ने तर GF ला प्रपोजल वेबसाइटची लिंक पाठवली होती, आणि सकाळी तिला फक्त एरर दिसला. आपण असं होऊ देणार नाही. उपाय एकच: Elastic IP.
दोस्तों, रात को instance stop किया और सुबह start किया – और IP बदल गया! वेबसाइट की लिंक, DNS रिकॉर्ड, सब टूट गया. मेरे एक स्टूडेंट ने तो GF को प्रपोज़ल वेबसाइट की लिंक भेजी थी, और सुबह उसे सिर्फ़ एरर दिखा. हम ऐसा नहीं होने देंगे. उपाय एक ही है: Elastic IP.
Quick answer
Console: EC2 → Network & Security → Elastic IPs → Allocate Elastic IP address → Allocate. Then select it → Actions → Associate Elastic IP address → Resource type: Instance → choose the instance → Associate. Verify on the server:
curl -s https://checkip.amazonaws.com # prints the Elastic IP
AWS CLI equivalent:
aws ec2 allocate-address --domain vpc
aws ec2 associate-address --instance-id i-0123456789abcdef0 --allocation-id eipalloc-0abc1234def567890
What do I need before attaching an Elastic IP?
- A running or stopped EC2 instance in the region where you allocate the address. See How to Launch an EC2 Instance in AWS.
- The region selected in the top-right menu (for example Mumbai, ap-south-1). An Elastic IP belongs to one region.
- A plan for the cost: AWS charges an hourly fee for every public IPv4 address, attached or idle. Check the current rate on the Amazon VPC pricing page.
Why does the public IP change after stop and start?
After a stop and start, the auto-assigned public IP is replaced by a new one and the domain breaks. The Elastic IP belongs to your account and stays the same.
Stop आणि start नंतर auto-assigned public IP च्या जागी नवीन IP येतो आणि डोमेन तुटतं. Elastic IP तुमच्या अकाउंटची असते आणि तशीच राहते.
Stop और start के बाद auto-assigned public IP की जगह नया IP आ जाता है और डोमेन टूट जाता है. Elastic IP आपके अकाउंट की होती है और वैसी ही रहती है.
The auto-assigned public IPv4 address is released when you stop the instance, and a new one is given when you start it. An Elastic IP (EIP) is a static public IPv4 address that belongs to your account (not to an instance) until you release it.
| Point | Auto-assigned public IP | Elastic IP |
|---|---|---|
| Survives stop/start | No — new IP after start | Yes |
| Owned by | The instance (temporarily) | Your AWS account |
| Move to another instance | Not possible | Yes — re-associate in seconds |
| Default limit | — | 5 per region per account (a service quota; you can request more) |
| Charges | Public IPv4 is charged hourly | Public IPv4 is charged hourly — whether attached or idle |
How do I attach an Elastic IP to EC2?
Step 1 — Allocate the Elastic IP
EC2 → Network & Security → Elastic IPs → Allocate Elastic IP address → Network border group: your region (e.g. ap-south-1) → Public IPv4 address pool: Amazon's pool of IPv4 addresses → optionally add a tag Name=web-eip → Allocate.
Step 2 — Associate it with the instance
Select the new address → Actions → Associate Elastic IP address → Resource type: Instance → choose your instance (and its private IP) → Associate.
Step 3 — Verify and reconnect
The instance's Public IPv4 address now shows the Elastic IP. The previous auto-assigned IP is released immediately, so reconnect with the new address:
ssh -i mykey.pem ec2-user@<ELASTIC_IP>
curl -s https://checkip.amazonaws.com # should print the Elastic IP
Step 4 — Test a stop and start
Stop the instance, start it again, and check the Public IPv4 address. It is the same Elastic IP. Your address is now fixed! 🎉
Step 5 — Update everything that uses the IP
- Point your domain's A record to the Elastic IP — see How to Connect a GoDaddy Domain to AWS EC2.
- If Nginx has the old IP in
server_name, change it and runsudo nginx -t && sudo service nginx reload.
Ravindra Bagale's Tip
Attach the Elastic IP before the DNS record, the WordPress install or the server_name config – then nothing needs changing later. Many students do it the other way round: WordPress first, Elastic IP later, and then the site redirects to the old IP. Remember the order: Elastic IP first, everything else after.
Ravindra Bagale's Tip – मराठी
Elastic IP हा DNS रेकॉर्ड, WordPress इन्स्टॉल किंवा server_name कॉन्फिग करण्याआधी आधी अटॅच करा – मग नंतर काहीच बदलावं लागत नाही. खूप स्टुडंट्स उलटं करतात: आधी WordPress, मग Elastic IP, आणि मग साइट जुन्या IP कडे रीडायरेक्ट होते. क्रम लक्षात ठेवा: आधी Elastic IP, मग बाकी सगळं.
Ravindra Bagale's Tip – हिंदी
Elastic IP को DNS रिकॉर्ड, WordPress इंस्टॉल या server_name कॉन्फ़िग से पहले अटैच करो – फिर बाद में कुछ नहीं बदलना पड़ता. बहुत स्टूडेंट्स उल्टा करते हैं: पहले WordPress, फिर Elastic IP, और फिर साइट पुराने IP पर रीडायरेक्ट होती है. क्रम याद रखो: पहले Elastic IP, बाकी सब बाद में.
How do I move an Elastic IP to a new server?
This is the most useful real-world trick. Suppose web-1 is old and you have built and tested a new web-2:
Before: www.example.com ──► EIP 13.232.50.10 ──► web-1 (old)
After: www.example.com ──► EIP 13.232.50.10 ──► web-2 (new) DNS record unchanged!
- Build and test
web-2using its own temporary public IP. - Select the EIP → Actions → Associate Elastic IP address → choose
web-2→ tick Allow this Elastic IP address to be reassociated → Associate. - Traffic goes to
web-2within seconds. Keepweb-1stopped for a day as a rollback option, then terminate it.
How do I release an Elastic IP?
- Disassociate: select the EIP → Actions → Disassociate Elastic IP address. The EIP stays in your account and is still charged.
- Release: select the EIP → Actions → Release Elastic IP addresses → Release. The address goes back to AWS; you usually cannot get the same IP again.
aws ec2 describe-addresses --output table
aws ec2 disassociate-address --association-id eipassoc-0123abcd4567ef890
aws ec2 release-address --allocation-id eipalloc-0abc1234def567890
Ravindra Bagale's Tip
💡 Many students terminate the instance when the lab ends but forget to Release the Elastic IP – and the bill arrives at the end of the month. First Disassociate, then Release – both steps. After every lab open the EC2 → Elastic IPs list and release every EIP that has no associated instance. Don't forget!
Ravindra Bagale's Tip – मराठी
💡 खूप स्टुडंट्स लॅब संपली की instance terminate करतात, पण Elastic IP Release करायला विसरतात – आणि महिन्याच्या शेवटी बिल येतं. आधी Disassociate, मग Release – दोन्ही स्टेप्स. प्रत्येक लॅब नंतर EC2 → Elastic IPs लिस्ट उघडा आणि associated instance नसलेली प्रत्येक EIP release करा. अजिबात विसरू नका!
Ravindra Bagale's Tip – हिंदी
💡 बहुत स्टूडेंट्स लैब खत्म होते ही instance terminate कर देते हैं, पर Elastic IP Release करना भूल जाते हैं – और महीने के आख़िर में बिल आ जाता है. पहले Disassociate, फिर Release – दोनों स्टेप्स. हर लैब के बाद EC2 → Elastic IPs लिस्ट खोलो और जिस EIP के साथ कोई associated instance नहीं है उसे release करो. बिल्कुल मत भूलना!
How do I fix common Elastic IP problems?
Ghabru naka 😅 — these are the usual ones:
| Symptom | Likely cause | Fix |
|---|---|---|
| SSH times out right after associating | You still use the old public IP | Connect to the Elastic IP |
| Address limit exceeded when allocating | Default quota of 5 per region used | Release unused EIPs or request a quota increase |
| Elastic IP not in the instance list | EIP and instance are in different regions | Allocate the EIP in the instance's region |
| Unexpected public IPv4 charges | Idle or forgotten EIPs | Disassociate and release them |
| Site still shows the old IP in links | WordPress or server_name stores the old IP |
Update server_name; for WordPress see the WordPress guide |
| New auto IP after disassociating | Expected: the old auto IP never comes back | Associate the EIP again, or use the new IP |
Learn it properly
This guide is the short path. The free AWS course explains every step in depth, with labs:
Got it? The Elastic IP belongs to the account, not the instance – so the address stays the same even after a stop and start. Allocate, associate, verify – and release it when you are done. Now get ready to point a domain.
समजलं का? Elastic IP अकाउंटची आहे, instance ची नाही – म्हणून stop-start केलं तरी पत्ता तसाच राहतो. Allocate, associate, verify – आणि काम संपलं की release. आता डोमेन पॉइंट करायला तयार व्हा.
समझ आया? Elastic IP अकाउंट की है, instance की नहीं – इसलिए stop-start करने पर भी पता वही रहता है. Allocate, associate, verify – और काम खत्म होते ही release. अब डोमेन पॉइंट करने के लिए तैयार हो जाओ.
Frequently asked questions
What is an Elastic IP in AWS?
A static public IPv4 address that belongs to your AWS account (not to an instance) until you release it. Unlike the auto-assigned public IP, it stays the same after a stop and start.
Does an Elastic IP cost money?
Yes. AWS charges an hourly fee for every public IPv4 address, including Elastic IPs, whether attached or idle. Check the current rate on the Amazon VPC pricing page.
How many Elastic IPs can I have?
The default limit is 5 per region per account. It is a service quota, and you can request more.
What happens to the old public IP when I associate an Elastic IP?
The previous auto-assigned public IP is released immediately, so reconnect SSH using the Elastic IP.
How do I move an Elastic IP to a new server?
Select the Elastic IP, choose Associate Elastic IP address, pick the new instance and tick Allow this Elastic IP address to be reassociated. Traffic moves within seconds and the DNS record stays unchanged.
How do I remove an Elastic IP?
First Disassociate it (it stays in your account and is still charged), then Release it. After release you usually cannot get the same IP again.