Elastic IP Addresses

An Elastic IP is a static public IPv4 address you own and can move between instances.

By default an instance's public IP changes every time it stops and starts. An Elastic IP (EIP) is a fixed public IPv4 address allocated to your account that stays the same and can be remapped instantly.

When to use one

  • A server that must keep the same public IP across restarts.
  • Fast failover — remap the EIP from a failed instance to a healthy one.

Watch the cost

An Elastic IP is free while it is associated with a running instance. An allocated but unattached EIP is charged by the hour — a classic surprise on the bill.

For most modern architectures a load balancer or DNS name is a better choice than pinning an EIP to a single server.

Example

Example · bash
# Allocate an Elastic IP and associate it with an instance
aws ec2 allocate-address --domain vpc
# => { "AllocationId": "eipalloc-0123456789abcdef0", "PublicIp": "52.1.2.3" }

aws ec2 associate-address \
  --instance-id i-0123456789abcdef0 \
  --allocation-id eipalloc-0123456789abcdef0

# Release it when finished
aws ec2 release-address --allocation-id eipalloc-0123456789abcdef0

When to use it

  • A company hosts a mail server on EC2 and uses an Elastic IP so the server's IP never changes between reboots or replacements.
  • A developer allocates an Elastic IP and re-associates it to a new replacement instance during an incident to preserve DNS and firewall rules.
  • A team whitelists a single Elastic IP at a partner's firewall so AWS-to-partner traffic always comes from a predictable address.

More examples

Allocate a New Elastic IP

Reserves a new static public IPv4 address in your account; it persists until you explicitly release it.

Example · bash
aws ec2 allocate-address \
  --domain vpc \
  --query '{AllocationId:AllocationId,PublicIp:PublicIp}' \
  --output table

Associate Elastic IP to Instance

Attaches the reserved Elastic IP to an EC2 instance so the instance gets that stable public address.

Example · bash
aws ec2 associate-address \
  --instance-id i-0123456789abcdef0 \
  --allocation-id eipalloc-0abc1234def56789a

Release Elastic IP to Avoid Charges

Disassociates and releases an unused Elastic IP, since AWS charges for EIPs that are allocated but not attached.

Example · bash
# First disassociate from the instance
aws ec2 disassociate-address \
  --association-id eipassoc-0abc123

# Then release (stops billing for idle EIP)
aws ec2 release-address \
  --allocation-id eipalloc-0abc1234def56789a

Discussion

  • Be the first to comment on this lesson.