AWS Cost Optimization for Public IPv4 Addresses


AWS introduced new public IPv4 pricing in 2024:

  • $0.005 per hour per public IPv4 = $3.60/month each
  • Applies whether the IP is Elastic or directly attached to an EC2.
  • This cost is in addition to your EC2, VPC, and data transfer charges.

If you run multiple domains or services on AWS, these charges add up quickly. Below is a step-by-step cost reduction playbook.


🔹 1. Consolidate Domains on Fewer Public IPs

  • Instead of assigning 1 IP per domain, you can serve multiple domains from a single IP using Virtual Hosts in Apache/Nginx.

Example: Apache VirtualHosts

<VirtualHost *:80>
    ServerName domain1.com
    DocumentRoot /var/www/domain1
</VirtualHost>

<VirtualHost *:80>
    ServerName domain2.com
    DocumentRoot /var/www/domain2
</VirtualHost>

<VirtualHost *:80>
    ServerName domain3.com
    DocumentRoot /var/www/domain3
</VirtualHost>
  • Point all DNS records (A or CNAME) to the same EC2 public IP.
  • The web server selects the right site based on the Host header.
  • Savings: 3 IPs → 1 IP = cut IPv4 cost by 66% (from $11.16 to $3.72/month).

🔹 2. Use Application Load Balancer (ALB)

  • ALB provides a single DNS name (e.g., myapp-1234567890.ap-south-1.elb.amazonaws.com).
  • Supports host-based routing:
    • domain1.com → target group 1
    • domain2.com → target group 2
  • You don’t need any public IPs on EC2 (only private IPs in private subnets).
  • ALB has a fixed hourly + LCU cost (~$16–$18/month), so it’s cost-effective if:
    • You manage 5+ domains.
    • You want SSL offloading, WAF, auto-scaling.

🔹 3. Put Domains Behind CloudFront CDN

  • CloudFront distributions don’t charge per IP.
  • Each distribution gets a public edge DNS name (e.g., dxxxxx.cloudfront.net).
  • Attach your custom domains via CNAME + ACM certificate.
  • CloudFront forwards traffic to your EC2 instance’s private IP or ALB.
  • You can consolidate dozens of domains behind CloudFront, all with zero IPv4 cost.

🔹 4. Embrace IPv6 (Free)

  • AWS charges for IPv4, but IPv6 is free.
  • Steps:
    • Enable dual-stack networking for EC2/ALB/CloudFront.
    • Add AAAA DNS records for your domains.
    • Encourage users/CDNs/ISPs to connect via IPv6.
  • You’ll still need at least 1 IPv4 for compatibility, but gradually traffic shifts away.

🔹 5. Release Idle Elastic IPs

  • Check for unused Elastic IPs: aws ec2 describe-addresses --query "Addresses[?AssociationId==null]"
  • Release them: aws ec2 release-address --allocation-id eipalloc-xxxxxx
  • AWS charges for unattached Elastic IPs, so don’t keep them reserved if not in use.

🔹 6. Use DNS Instead of IPs for Apps

  • Many setups bind services directly to public IPs.
  • Instead, use Route 53 (or any DNS provider) and map domain → single public endpoint.
  • This avoids the “1 IP per service” trap.

🔹 7. Automate Audit & Alerts

  • Enable AWS Cost Explorer + Budgets:
    • Track IPv4 cost (Amazon Virtual Private Cloud → Public IPv4 Address line item).
    • Set alerts if IPv4 spend > $5–$10.
  • Run a weekly script to list public IP usage: aws ec2 describe-instances --query "Reservations[*].Instances[*].[InstanceId,PublicIpAddress]" --output table

âś… Summary of Optimization Options

StrategyEffortSavingsBest For
VirtualHosts (1 IP, many domains)EasyHigh (66–80%)Small setups, 2–10 domains
Release unused IPsEasySmall (~$3.60/IP/mo)Anyone with idle Elastic IPs
ALB (DNS-based routing)MediumModerateMulti-domain, need SSL/WAF/scaling
CloudFront (CDN)MediumHigh (remove all IPv4 costs, reduce egress too)Global traffic, static assets
IPv6 adoptionMedium/LongFuture-proofLong-term savings, modern apps

📌 Recommended Path (for your case)

Since you said 3 domains → 3 EC2 public IPs:

  1. âś… Switch all 3 domains to 1 EC2 public IP (via Apache VirtualHosts).
  2. âś… Release the 2 extra Elastic IPs.
  3. Later, move everything behind CloudFront → $0 IPv4 charge + huge egress savings.
  4. Enable IPv6 dual-stack now to future-proof.

👉 This way your IPv4 cost drops from $11.16 → $3.72 now, and eventually $0.


Leave a Comment