3.6
Public, Private and Elastic IPs
Which address an instance gets and when it changes, Elastic IPs, the public IPv4 charge, and better alternatives.
20 min Reading + animations
Tip: tap or hover any dotted-underlined term to see what it means.
By the end of this lesson you will be able to
- Name the three kinds of IPv4 address an EC2 instance can have and what each is used for.
- Predict what happens to each address on reboot, stop/start and termination.
- Use an Elastic IP correctly, including to mask an instance failure, and know its limits.
- Explain the public IPv4 charge and avoid paying for forgotten Elastic IPs.
- Choose a better design than a fixed IP when the exam (or a real system) offers one.
#Three kinds of address
An instance in a VPC can have three kinds of IPv4 address:
| Address | Comes from | Reachable from | Changes when |
|---|---|---|---|
| Private IP | The subnet’s CIDR range (lesson 3.2) | Inside the VPC (and networks connected to it) | Never while the instance exists; released at termination |
| Public IP (auto-assigned) | AWS’s pool, if the subnet’s “auto-assign public IPv4” is on (or you ask at launch) | The internet | Stop/start (released on stop, a new one on start) and termination |
| Elastic IP (EIP) | Allocated to your account, then associated with an instance or network interface | The internet | Only when you move or release it |
Remember from lesson 3.3 that the public and Elastic IPs live in the internet gateway’s one-to-one mapping. The operating system only ever sees the private address.
What each is for:
- Private IP: everything inside the VPC. Servers, databases and load balancers talk to each other with private addresses: faster, cheaper (no internet path) and never exposed.
- Public IP: a throwaway address so an instance can be reached from the internet, or reach it directly, without paying for or managing a fixed address.
- Elastic IP: a public address that must never change, because something outside depends on it (a partner’s firewall allow-list, a DNS record you cannot update quickly).
What happens to an instance’s addresses
Follow the private IP, the auto-assigned public IP and an Elastic IP through reboots, stops, failures and termination.
Scenario
Server A was launched in a public subnet with auto-assign on. It has a private IP, 10.0.0.10, and AWS also gave it a public IP from its pool: 203.0.113.25. Customers use the public one.
#Elastic IPs
An Elastic IP is a static public IPv4 address that you allocate to your account in a Region and then associate with an instance (or a network interface). Facts to know:
- It stays yours until you release it, independent of any instance’s life.
- It is associated with one instance or network interface at a time, but you can move it in seconds.
- Default quota: 5 Elastic IPs per Region per account (you can request more).
- It is a Regional resource: it cannot be moved to another Region.
Masking a failure. Because it can be remapped quickly, an Elastic IP lets you swap a failed instance for a standby without clients noticing: disassociate from the broken instance, associate with the healthy one. Clients keep using the same address. (The animation’s “Mask a failure” scenario.)
#Why AWS says to avoid them
AWS itself recommends using Elastic IPs sparingly. A fixed IP on a single instance usually means a fragile architecture: one server, manual failover, no scaling. Better options:
- Give the instance (or a load balancer) a DNS name in Route 53, and change the record instead of pinning an address (Chapter 8).
- Put instances behind a load balancer (Chapter 6): clients use the load balancer’s DNS name; instances can be private and come and go freely.
- When fixed public IPs are genuinely required (partners allow-listing your addresses), a Network Load Balancer can have one Elastic IP per AZ, and AWS Global Accelerator gives two static anycast IPs for a whole application (Chapter 11).
#Public IPv4 costs money
IPv4 addresses are scarce, and since 1 February 2024 AWS charges for every public IPv4 address, about $0.005 per hour (roughly $3.60 per month) each:
- in use (attached to a running instance) or idle (allocated but unattached, or attached to a stopped instance);
- auto-assigned public IPs and Elastic IPs alike;
- public IPs on load balancers, NAT gateways and other AWS resources too.
The AWS Free Tier includes some public IPv4 hours for new accounts during the first year.
Self-checkQuestion
An instance with an auto-assigned public IP is stopped for maintenance and started again. Users now cannot reach it at the old address. What happened, and what prevents it?
#Try it yourself
# Allocate an Elastic IP and attach it to an instance
ALLOC=$(aws ec2 allocate-address --domain vpc --query AllocationId --output text)
aws ec2 associate-address --allocation-id $ALLOC --instance-id i-0123456789abcdef0
# Find Elastic IPs that are allocated but attached to nothing (paying for nothing)
aws ec2 describe-addresses --query "Addresses[?AssociationId==null].[PublicIp,AllocationId]" --output table
# Stop paying: disassociate, then release
aws ec2 disassociate-address --association-id eipassoc-0abc123
aws ec2 release-address --allocation-id $ALLOC
# On a Linux instance: the OS only knows its private address
ip -4 addr show eth0
Amazon VPC IP Address Manager (IPAM) includes a free public IP insights view that lists every public IPv4 address in your accounts and shows which are idle.
#Summary
Key takeaways
- Private IP: from the subnet range, used inside the VPC, kept until termination.
- Public IP (auto-assigned): from AWS’s pool, changes on stop/start (not on reboot), released at termination.
- Elastic IP: a static public IP allocated to your account until you release it; one instance or interface at a time, remappable in seconds to mask a failure; 5 per Region by default.
- The operating system sees only the private address; the internet gateway maps public ↔ private.
- All public IPv4 addresses cost about $0.005/hour since February 2024, attached or idle. Terminating an instance does not release its Elastic IP: release it to stop paying.
- Prefer DNS names and load balancers over fixed IPs; when static IPs are required, consider an NLB’s Elastic IPs or Global Accelerator.
Answer on your own first, then read the explanation, even when you got it right.
Self-checkQuestion
A team terminated an instance last month, but the bill still shows a public IPv4 charge. What is the most likely cause?
Self-checkQuestion
Which design best avoids depending on a single instance’s public IP for a web application?
Self-checkQuestion
Where does an instance’s private IPv4 address come from?
Self-checkQuestion
An EC2 instance has both a private IP and a public IP. Which address does its operating system see on its network interface?
Self-checkQuestion
An instance with an auto-assigned public IP is rebooted. What happens to its public IP?
Self-checkQuestion
An application server must connect to a database instance in the same VPC. Which address should it use?
Self-checkQuestion
What is the default Elastic IP quota?
Self-checkQuestion
What is the difference between disassociating and releasing an Elastic IP?
Self-checkQuestion
Which two actions make an instance lose its current auto-assigned public IPv4 address?
Choose 2
Self-checkQuestion
Why has AWS charged for every public IPv4 address since February 2024?
Self-checkQuestion
Which statement about public IP billing is correct today?
Self-checkQuestion
Which two statements about Elastic IPs are true?
Choose 2
Self-checkQuestion
A solutions architect allocated an Elastic IP in us-east-1 and now wants to use it for an instance in eu-west-1. What happens?
Self-checkQuestion
An instance has a private IP and an associated Elastic IP. The instance is terminated. What happens to the two addresses?
Self-checkQuestion
A company stops a development instance every evening and starts it every morning. The instance has an Elastic IP. What happens to the Elastic IP overnight?
Self-checkQuestion
A solutions architect launches an instance in a subnet whose route table sends 0.0.0.0/0 to an internet gateway. The security group allows the traffic, but the instance cannot be reached from the internet, and the console shows no public IPv4 address. What is the most likely cause?
Self-checkQuestion
On Friday evening an engineer stopped an instance to save money and started it again on Monday morning. Now the team’s saved SSH connection to the instance’s public address times out. Nothing else was changed. What is the most likely cause?
Self-checkQuestion
An instance in a public subnet has an auto-assigned public IP. It is patched with reboots only and is never stopped. A manager asks for an Elastic IP ‘so the address survives the reboots’. Which statement is accurate?
Self-checkQuestion
A company’s single EC2 instance uploads files to a partner over the internet. The partner’s firewall accepts connections only from source IPs on its allow-list. The instance is stopped and started every week for patching. What should the solutions architect do?
Self-checkQuestion
A legacy application runs on one instance, and clients connect to a fixed IP address that cannot change. A standby instance is ready. How can the solutions architect move clients to the standby within seconds if the primary fails?
Self-checkQuestion
A solutions architect uses Elastic IP remapping as the failover plan for a web application. A reviewer says a different design would be better. Which weakness is the reviewer most likely pointing at?
Self-checkQuestion
A company reviews its bill after February 2024. Which two statements about public IPv4 charges are correct?
Choose 2
Self-checkQuestion
A small internal tool runs on one EC2 instance, and there is no budget for a load balancer. A Route 53 record points at the instance’s auto-assigned public IP, and the tool breaks every time the instance is stopped and started. What is the simplest fix?
Self-checkQuestion
A company runs 40 web instances in public subnets behind an internet-facing load balancer. Every instance has an auto-assigned public IP, but all user traffic arrives through the load balancer. How can the company cut its public IPv4 charges without affecting users?
Self-checkQuestion
A company’s web application runs behind an Application Load Balancer, whose IP addresses can change over time. A large customer must allow-list a small, fixed set of IP addresses for the application. Which two options meet this requirement?
Choose 2
Self-checkQuestion
During a migration a company needs 7 Elastic IPs in one Region, because a partner allow-lists each address. Allocating the sixth address fails. What should the solutions architect do?
Self-checkQuestion
A company is designing a new public application and wants to avoid the hourly public IPv4 charge where it can. All of its clients support IPv6. Which approach does this lesson point to?
Self-checkQuestion
A cloud team wants to find public IPv4 addresses that are being paid for but not used. Which two tools help?
Choose 2
Self-checkQuestion
A finance team sees public IPv4 charges in an account where no instance is running. Which of these could NOT be causing the charge?
Self-checkQuestion
A solutions architect must keep an application reachable for internet clients even when individual servers fail or are replaced. Which of these is NOT a design AWS recommends over pinning one Elastic IP to one instance?