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