In this tutorial, we will show you how to associate a NameCheap domain name to an Amazon EC2 instance.

In AWS

  1. Create an Elastic IP and point to the Amazon EC2 instance.
  2. Go to service Route 53, create a ‘A’ record and point to the Elastic IP.
  3. In Route 53, copy the Amazon NS (name server) urls.

In NameCheap

  1. Paste the Amazon NS urls into the NameCheap DNS settings.

In Summary
Request <==> NameCheap <==> Amazon NS <==> Route 53 <==> Elastic IP <==> EC2 Instance.

Note
This DNS changes may take 24 hours to propagate.

1. AWS : EC2 and Elastic IP

1.1 After the Amazon EC2 instance is launched, both public IP and public DNS will be assigned automatically.

aws-ec2-example
Note
If this EC2 instance is “stop” and “start”, both public IP and public DNS will be changed. This is the reason to create an elastic IP and point it to an EC2 instance, because elastic IP will not change even if the instance is “stop” and “start”.

1.2 Create an Elastic IP :

  • Clicks on the “Allocate New Address” button, a new elastic IP will be created automatically.
  • Clicks on the “Associate Address” button, select the EC2 instance.
aws-ec2-elastic-ip-create

Done, the Elastic IP is associated with the EC2 instance.

aws-ec2-elastic-ip-example

Next, configure the DNS settings (Route 53).

2. AWS : Route 53 (DNS)

2.1 Go to service “Route 53”, create a hosted zone, two record set (NS and SOA) will be created automatically. Clicks on the “NS” type, copy the Amazon NS urls, later we need to put these urls in NameCheap.

aws-route53-example1

Amazon NS urls

ns-396.awsdns-49.com.
ns-1143.awsdns-14.org.
ns-1676.awsdns-17.co.uk.
ns-879.awsdns-45.net.

2.2 Create two new “A” or “A – IPv4 address” records (root domain and www.domain) and point it to the Elastic IP.

aws-route53-example2

3. NameCheap : DNS

3.1 Copy the Amazon name server urls and puts it into the NameCheap DNS settings.

Amazon NS urls

ns-396.awsdns-49.com.
ns-1143.awsdns-14.org.
ns-1676.awsdns-17.co.uk.
ns-879.awsdns-45.net.

3.2 In NameCheap, select the domain name, and clicks “Transfer DNS to Webhost” or “Domain Name Server Setup“, copy and paste the Amazon NS urls :

namecheap-aws-ec2-example

Done.

References

  1. Hosting a Web App on Amazon Web Services
  2. ServerFault : IP changed when EC2 instance stopped and started