Ravindra BagaleCourses & study guides

Guides

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.

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?

Elastic IP stays the same after stop and start An EC2 instance goes from running to stopped and back to running. The auto-assigned public IP 13.233.10.25 disappears when the instance stops and a different IP, 3.110.45.7, appears after the start, so a domain pointing to it breaks. The Elastic IP 13.232.50.10 stays the same through the whole cycle, so the domain keeps working. EC2 instance web-server-1 Running Stopped Running stop → start Auto-assigned public IP 13.233.10.25 (released) 3.110.45.7 Elastic IP (your account) 13.232.50.10 example.com A record Auto IP changed Elastic IP did not

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.

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

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.

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!
  1. Build and test web-2 using its own temporary public IP.
  2. Select the EIP → Actions → Associate Elastic IP address → choose web-2 → tick Allow this Elastic IP address to be reassociated → Associate.
  3. Traffic goes to web-2 within seconds. Keep web-1 stopped 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!

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.

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.