Chapter 5: Amazon EC2 (Elastic Compute Cloud)
5.5 Elastic IP (static public IP)
Quick how-to: short click-path version — How to Attach an Elastic IP to an EC2 Instance. Deeper ops (swap servers, zero DNS change) — 14.1 Elastic IP in depth.
Why a normal public IP changes
Why
Priya in Pune runs a small shop site on one EC2 server. She stops the server at night to save money. In the morning the site URL is dead. Friends in Berlin still open the old IP. That IP is gone.
What
A public IPv4 address is an address the whole internet can reach. When AWS gives your instance a normal (auto-assigned) public IP, that IP belongs to the running instance only for a while.
- Stop, then start → AWS takes the old public IP back. You usually get a new one.
- Reboot (restart the OS) → the public IP stays the same.
- The private IP inside the VPC does not change on stop/start.
How — see it yourself
- Open the EC2 console → Instances → pick your instance.
- Copy the Public IPv4 address (example:
13.233.45.67). - Instance state → Stop instance → wait until stopped → Start instance.
- Look at Public IPv4 again. It is often a different number.
Example — before and after stop/start
# On the server, before stop:
curl -s https://checkip.amazonaws.com
# Sample output:
# 13.233.45.67
# Stop the instance in the console, then Start it.
# SSH again (new IP!), then:
curl -s https://checkip.amazonaws.com
# Sample output:
# 65.2.110.88
What it means: the address changed. Any DNS A record or bookmark that used 13.233.45.67 now fails.
Full ops story, including swapping servers without changing DNS, is in lesson 14.1 Elastic IP in depth.
What an Elastic IP is
Why
You need one public address that does not jump around when you stop and start the server.
What
An Elastic IP (EIP) is a static public IPv4 address that AWS allocates to your account in one Region. It stays yours until you release it. You can move it from one instance to another in the same Region.
- Elastic IPs are IPv4 only. AWS does not offer Elastic IP for IPv6. IPv6 on EC2 uses a different model (assign an IPv6 address to the ENI; it is already fixed).
- An EIP lives in one Region (for example
ap-south-1). You cannot move the same EIP to another Region. - BYOIP (Bring Your Own IP): if you bring your own public IPv4 range to AWS, addresses from that pool do not count toward the normal EIP quota and are not billed as AWS-provided public IPv4. Most beginners can ignore BYOIP.
How — mental model
- AWS holds a pool of public IPv4 addresses.
- Allocate = “this address is now in my account.”
- Associate = “map this address to this instance’s network interface.”
- Internet traffic to the EIP hits the Internet Gateway, then your instance’s private IP.
Example — names you will see
- Allocation ID — like
eipalloc-0a1b2c3d4e5f67890(the EIP itself in your account). - Association ID — like
eipassoc-0123456789abcdef0(the link to an instance or ENI). - Public IP — like
3.110.55.201(what browsers and DNS use).
What it means: you release with the allocation ID. You disassociate with the association ID. The public IP is the human-facing number.
Allocate and associate (console)
Why
Omar in Dubai wants shop.example.com to keep working after every stop/start. He needs an EIP on his instance first.
What
Two console actions: Allocate Elastic IP address, then Associate Elastic IP address.
How — numbered steps
- Open the EC2 console in your Region (example: Mumbai
ap-south-1). - Left menu → Network & Security → Elastic IPs.
- Click Allocate Elastic IP address.
- Public IPv4 address pool: Amazon’s pool of IPv4 addresses (default).
- Optional tag:
Name = mauli-web-eip(Mauli Dairy lab name). - Click Allocate. Note the new Public IP and Allocation ID.
- Select that EIP → Actions → Associate Elastic IP address.
- Resource type: Instance → choose the instance → choose its private IP → Associate.
- Open the instance page. Public IPv4 address should now show the Elastic IP.
Example — what you should see
- Elastic IPs list:
3.110.55.201· Associated instance ID · Allocation IDeipalloc-… - Instance summary: Public IPv4 =
3.110.55.201(same number).
What it means: the old auto-assigned public IP is gone. SSH and HTTP must use the new EIP from now on.
Note: when you associate an EIP, AWS releases the instance’s previous auto-assigned public IP. You cannot turn that old auto IP into an EIP.
Same job with AWS CLI
Why
Scripts and exams expect the CLI. Same ideas: allocate, associate, describe.
What
Main commands: allocate-address, associate-address, describe-addresses.
How
- Allocate in the VPC domain (today every EIP is VPC):
Example — allocate
aws ec2 allocate-address --domain vpc
{
"PublicIp": "3.110.55.201",
"AllocationId": "eipalloc-0a1b2c3d4e5f67890",
"Domain": "vpc"
}
What it means: 3.110.55.201 is now in your account. Nothing is attached yet. You are already being billed for this public IPv4.
- Associate it to an instance:
Example — associate
aws ec2 associate-address \
--instance-id i-0abc123def4567890 \
--allocation-id eipalloc-0a1b2c3d4e5f67890
{ "AssociationId": "eipassoc-0123456789abcdef0" }
What it means: traffic to 3.110.55.201 now reaches that instance.
- List what you own:
Example — describe
aws ec2 describe-addresses --output table
What it means: you see each PublicIp, AllocationId, InstanceId (if any), and AssociationId. Empty InstanceId = idle EIP (still billed).
Disassociate and release
Why
Anita finishes a lab in Hyderabad. If she only terminates the instance and forgets the EIP, the bill keeps growing.
What
- Disassociate — unlink the EIP from the instance. The EIP stays in your account.
- Release — return the address to AWS. Billing for that address stops (once released).
How — console
- EC2 → Elastic IPs → select the address.
- Actions → Disassociate Elastic IP address → confirm.
- Select it again → Actions → Release Elastic IP addresses → Release.
How — CLI
Example — disassociate then release
aws ec2 disassociate-address --association-id eipassoc-0123456789abcdef0
aws ec2 release-address --allocation-id eipalloc-0a1b2c3d4e5f67890
What it means: after release, describe-addresses no longer lists that AllocationId. Always disassociate before release if it is still attached.
Recover a released Elastic IP (sometimes)
Why
You released the EIP by mistake. DNS still points to 3.110.55.201. Can you get it back?
What
Often yes, if AWS has not given that address to someone else yet, and if recovering it would not push you over your EIP quota. You recover only with the API/CLI (not the console button). Tags on the old allocation are not restored.
How
- Run allocate again and pass the exact address:
Example — try to recover
aws ec2 allocate-address --domain vpc --address 3.110.55.201
What it means: success → you get a new AllocationId for the same public IP. Failure → another account took it, or you hit quota. Then you must pick a new IP and update DNS.
Official docs: Work with Elastic IP addresses (recover section).
Pricing and quota
Why
Many students still believe “first EIP is free while attached.” That old rule is gone.
What — price
From 1 February 2024, AWS charges $0.005 per hour for every public IPv4 address in your account — including:
- auto-assigned public IPs on running instances,
- Elastic IPs that are attached,
- Elastic IPs that are idle (allocated but not associated).
Rough maths: one address ≈ 0.005 × 24 × 30 ≈ $3.60 per month.
EC2 Free Tier (first 12 months) includes 750 hours/month of public IPv4 with EC2. Other services and idle EIPs can still cost money. Always check the current page.
What — quota
Default quota: 5 Elastic IP addresses per Region per account. You can request more in Service Quotas. BYOIP addresses do not count against this quota.
How — stay cheap
- Prefer one EIP only when you truly need a fixed address.
- After every lab: Elastic IPs list → release unused ones.
- For many public apps, put an Application Load Balancer (or similar) in front and point DNS at the load balancer — see Chapter 18. For a name on one server, learn DNS in Chapter 9: Domain Names, DNS and Subdomains.
Example — when EIP vs load balancer / DNS
- Use an EIP — single server, you SSH to a stable IP, or you must remap fast to a standby instance in the same Region.
- Use a load balancer + DNS — public website with more than one instance, or you want HTTPS and health checks. Point the domain at the load balancer DNS name, not at a raw EIP.
- DNS alone — if your DNS TTL is short and you accept a short delay when the IP changes, you can update the A record after stop/start. Still painful for beginners; EIP is simpler for one box.
Sources (pricing & EIP basics):
- Amazon VPC pricing — Public IPv4 Address ($0.005/hr in-use and idle)
- AWS News Blog — Public IPv4 charge from 1 Feb 2024
- EC2 User Guide — Elastic IP addresses (IPv4 only, quota 5/Region, pricing note)
- VPC User Guide — Allocate, associate, release, recover
Common mistakes
- Release forgotten after terminate — instance is gone; EIP remains and bills you.
- Thinking reboot = stop/start — reboot keeps the auto public IP; stop/start does not.
- Associating in the wrong Region — EIP in
us-east-1will not attach to an instance inap-south-1. - Expecting IPv6 “Elastic IP” — there is no EIP for IPv6.
- Assuming you can never recover a released IP — you often can with
allocate-address --address, but only while it is still free (see above and 14.1). - Putting an EIP on every instance “just in case” — prefer load balancer + DNS for fleets.
Checklist before you leave the lab
- I know stop/start changes auto public IP; reboot does not.
- I allocated an EIP and associated it to my instance.
- I verified with
curl -s https://checkip.amazonaws.com. - I disassociated, then released, when the lab ended.
- Elastic IPs list in this Region is empty (or only has EIPs I still need).
Ravindra Bagale's Tip
Attach the Elastic IP before you create DNS records (Chapter 9), install WordPress, or set server_name — then nothing needs to change later. After every lab, do a one-minute EIP audit: EC2 → Elastic IPs — release every address with no associated instance. Your bill stays clean.
Ravindra Bagale's Tip – मराठी
DNS records (Chapter 9), WordPress install किंवा server_name सेट करण्याआधी Elastic IP attach करा – मग नंतर काहीच बदलावं लागत नाही. Lab संपली की एक मिनिटाचा EIP audit करा: EC2 → Elastic IPs – associated instance नसलेली प्रत्येक address release करा. Bill स्वच्छ राहतं.
Ravindra Bagale's Tip – हिंदी
DNS records (Chapter 9), WordPress install या server_name सेट करने से पहले Elastic IP attach करो – फिर बाद में कुछ बदलना नहीं पड़ता. Lab खत्म हो तो एक मिनट का EIP audit करो: EC2 → Elastic IPs – जिस address पर associated instance नहीं है उसे release करो. Bill साफ़ रहता है.
Lab — pin a stable public IP on one EC2
Goal: prove that an Elastic IP survives stop/start, then clean up so you are not billed.
- Launch (or reuse) a free-tier EC2 instance in
ap-south-1. Name itmauli-web-1. - Copy its current auto public IP into a notepad.
- Allocate an Elastic IP. Tag
Name=mauli-web-eip. - Associate it with
mauli-web-1. - From your laptop:
ssh -i your.pem ec2-user@THE_EIP(Amazon Linux) or the matching user for your AMI. - On the server run:
curl -s https://checkip.amazonaws.com— it must print the EIP. - Stop the instance. Start it again. Confirm the Public IPv4 is still the EIP (not a new random IP).
- Disassociate the EIP. Release the EIP. Confirm the Elastic IPs list is empty in this Region.
Pass: IP stayed the same across stop/start while associated; list is empty after release.
Quick quiz
Five questions. Only what this lesson teaches. Click an answer to check.