When working with AWS Elastic Load Balancers (ALB/NLB), the dynamic nature of their IP addresses creates a DNS configuration challenge. Traditional A records require static IPs, but ELBs automatically scale and change their underlying infrastructure.
For AWS-hosted domains, use Alias records (AWS Route 53 specific):
mydomain.eu. ALIAS dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.
www.mydomain.eu. ALIAS dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.
For non-AWS DNS providers, use CNAME records:
mydomain.eu. CNAME my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.
www.mydomain.eu. CNAME my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.
1. Always use the dualstack prefix for IPv6 compatibility
2. The trailing dot in FQDNs is crucial for proper DNS resolution
3. For root domains, verify your registrar supports CNAME flattening or ALIAS records
resource "aws_route53_record" "main" {
zone_id = aws_route53_zone.primary.zone_id
name = "mydomain.eu"
type = "A"
alias {
name = "dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com"
zone_id = "Z35SXDOTRQ7X7K" # ELB zone ID
evaluate_target_health = true
}
}
After configuration, verify with:
dig mydomain.eu
nslookup www.mydomain.eu
curl -v http://mydomain.eu
When working with AWS Elastic Load Balancers (ALB/NLB), one quickly encounters their dynamic nature - they don't have static IP addresses. This creates a challenge when trying to point your domain directly to the load balancer using traditional A records in your DNS configuration.
An A record maps a domain name to an IPv4 address. For example:
mydomain.eu. IN A 192.0.2.1
But AWS load balancers frequently change their underlying IP addresses due to scaling, maintenance, or regional failovers. If you use an A record pointing to a specific IP, your DNS will eventually become stale and stop working.
There are two recommended approaches:
Option 1: CNAME Record
A CNAME record maps a name to another name (canonical name). For AWS load balancers, you would:
www.mydomain.eu. IN CNAME dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com. mydomain.eu. IN CNAME dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.
Note: Some registrars don't allow CNAME records at the root domain (apex). In those cases, use Option 2.
Option 2: ALIAS/ANAME Record (Recommended for root domains)
Modern DNS providers (Route 53, Cloudflare, etc.) support alias records that function like CNAMEs but work at the root:
; Route 53 example mydomain.eu. IN A ALIAS dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com. www.mydomain.eu. IN CNAME dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.
For AWS users, here's a complete example using the AWS CLI to create the records:
aws route53 change-resource-record-sets --hosted-zone-id Z1PEXAMPLE \\ --change-batch '{ "Changes": [{ "Action": "UPSERT", "ResourceRecordSet": { "Name": "mydomain.eu", "Type": "A", "AliasTarget": { "HostedZoneId": "Z35SXDOTRQ7X7K", "DNSName": "dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com", "EvaluateTargetHealth": false } } }] }'
After setting up your DNS records, verify with:
dig mydomain.eu dig www.mydomain.eu
You should see your domain resolving to the ELB's DNS name rather than a specific IP address.
- Always use the "dualstack" prefix in AWS ELB DNS names for IPv6 compatibility
- TTL values don't affect alias records the same way as regular records
- Some DNS providers may implement alias records differently (e.g., Cloudflare's CNAME flattening)
- For non-AWS DNS providers, check their documentation for equivalent functionality
If your registrar doesn't support alias records at the root, you can:
; Root domain uses traditional A records mydomain.eu. IN A 192.0.2.1 mydomain.eu. IN A 192.0.2.2 ; Subdomain uses CNAME app.mydomain.eu. IN CNAME dualstack.my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.
Then configure your web server at the root domain to redirect to the subdomain.