Post

Registering domain name in Route53 and integrating it with Hosting Server through CNAME

Abstract

Creating a personalized online presence is an essential step for bloggers, developers, and content creators. One powerful way to establish your brand is by registering a custom domain name and connecting it to your blog hosted on GitHub Pages. In this post, we’ll guide through the comprehensive process of registering a domain name using Amazon Route 53, understanding DNS concepts, and configuring CNAME and Alias records to seamlessly direct traffic to your GitHub Pages blog.

Introduction

A domain registrar is an accredited organization responsible for managing the reservation and registration of domain names. These companies facilitate the process of purchasing domain names, allowing individuals, businesses, and organizations to secure unique online identities. Registrars act as intermediaries between domain owners and the domain name system (DNS), ensuring your chosen domain is properly associated with your website’s IP address.

Popular Domain Registrators are: GoDaddy, Namecheap, Google Domains, Route53. Route53 operates both as DNS service and also provides domain registration.

Domain Registration process is simple

First you check that this record does not exist and after verification proceed to registration: r53-2.png

Keep in mind that if you are using brand new AWS account you can receive error message when trying to register domain. If so contact the support and unlock domain registration for your account.

After domain name is registered you can assign it to different targets, create subdomains, define routings, create health checks, etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
dig tsypuk.com

; <<>> DiG 9.10.6 <<>> tsypuk.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9991
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1432
;; QUESTION SECTION:
;tsypuk.com.			IN	A

;; AUTHORITY SECTION:
tsypuk.com.		3600	IN	SOA	ns-109.awsdns-13.com. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400

This information coresponds to :

ParameterValue
Start of authorityns-109.awsdns-13.com.
Emailawsdns-hostmaster@amazon.com
Serial for this zone1
Refresh SOA record, to detect zone changes2h
Retry serial number from the master15m
Expire stop answering request for this zone336h
Negative cache TTL24h

CNAME to the rescue

I already have personal blog that is hosted on github pages, it is assembled with static site generator Jekyll and very easy to use. However github provides 3rd level domain name extention for you hosting always ending with .github.io.

CNAME record will help to resolve good looking domain name blog.tsypuk.com to tsypuk.github.io

A Canonical Name (CNAME) record is a type of resource record in the Domain Name System (DNS) that maps one domain name (an alias) to another (the canonical name).

Please note that there is a limitation that we can not use CNAME for APEX zone domain name. I can not create CNAME for my domain tsypuk.com - instead I will be using blog.tsypuk.com

img.png

The key element in the setup are:

  • Value: tsypuk.github.io
  • TTL: 172800 this is the maximum value supported by route53 DNS server (2days)

Since there will be no need for dynamic switch of static site content on remote servers - we can set the maximum TTL level to have fewer calls to Route53 and have less billing.

Domain verification on Target Server

Since we are requesting to change domain name of hosted website, we should go through verification procedure - to make sure that we are the owner of ``Domain name`.

There are different verification method based on provider. The most common is verification using TXT or CNAME records.

Domain Verification with CNAME

github.pages requires to verify that we are the owner of tsypuk.com domain name, so it provides it server name backend that should be resolved through additional CNAME added to our domain: cname0.png

The verification algorithm is simple - if you do not have control and can not add requested CNAME then probably you are not the owner of this domain.

Let’s set up CNAME in Route53: cname1.png

Once the record is provisioned, githubpages calls this CNAME and is redirected to verification backend, closing the loop.

Domain Verification with TXT

A TXT record (short for text record) is a type of resource record in the Domain name system (DNS) used to provide the ability to associate arbitrary text with a host or other name, such as human readable information about a server, network, data center, or other accounting information. It is widely used for domain ownership verification.

Same way github pages provides TXT record that should be associated with our Domain.

txt-1.png

Once it is setup in Route53, github will perform lookup to this TXT records compare the response and verify the ownership:

txt2.png

Finally, after verification our domain name will be resolved in githubpages and server will rebuild all links to reference our domain name.

img.png

One more step is to commit file named CNAME to the root of you documentation page with name of domain:

1
blog.tsypuk.com

Verifying the Records

Domain name works perfectly, and we can observe a blog in the browser. Let’s also run dns request to inspect dns record details.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dig blog.tsypuk.com

;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6541
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1432
;; QUESTION SECTION:
;blog.tsypuk.com.		IN	A

;; ANSWER SECTION:
blog.tsypuk.com.	21600	IN	CNAME	tsypuk.github.io.
tsypuk.github.io.	14400	IN	A	185.199.108.153
tsypuk.github.io.	14400	IN	A	185.199.109.153
tsypuk.github.io.	14400	IN	A	185.199.110.153
tsypuk.github.io.	14400	IN	A	185.199.111.153

;; Query time: 305 msec
;; MSG SIZE  rcvd: 138

As we can see our blog dns name blog.tsypuk.com now resolves to tsypuk.github.io (githubpages site) using CNAME record. Also in DNS response we can see A records for actual site (4 IPs from range: 185.199.X.Y)

TTL Tuning

DNS TTL (time to live) is a setting on DNS records that controls how long each record is valid and how long it takes for record updates to reach end-users.

Since target server for all instances has TTL value 14400 we can set the same value to our CNAME TTL

This post is licensed under CC BY 4.0 by the author.