A Records vs. CNAME Records
When you are mapping a domain on GitHub pages (or on any site really) an important concept you want to try and wrap your head around is the difference between A Records and CNAME Records. I’m getting closer to full comprehension, but a little help never hurts so I took the following definition from DNS Simple:
The A record points a name to a specific IP. For example, if you want blog.dnsimple.com to point to the server 22.214.171.124 you will configure:
blog.dnsimple.com. A 126.96.36.199
The CNAME record points a name to another name, instead of an IP. The CNAME source represents an alias for the target name and inherits its entire resolution chain. Let’s take our blog as an example:
blog.dnsimple.com. CNAME aetrion.github.io.
To summarize, an 'A record' points a name to an IP. 'CNAME record' can point a name to another CNAME...
It’s good practice to point domains using 'CNAME records' when possible because IP addresses can change, and when they do an A Record will break because it is hard coded. You might think of CNAME records as relative hostnames, hence the IP address can change regularly but the mapped domain will not break.
One issue is that root domains (sometimes called “zone apex” or “naked domain”) have to be set up as an A record, not a CNAME. This means that with most DNS providers you can setup a subdomain CNAME (blog.jimgroom.me) to point to a service like GitHub, but you cannot setup your root domain (jimgroom.me) as a CNAME. That root domain would have to be an A record. Make sense? Good.
Mapping your Domain on GitHub
As you might have guessed from the above definitions, there are two methods for mapping a custom domain on GitHub: CNAME and A Records. You can get a good overview of how Custom Domains work on GitHub here. Mapping a subdomain using a CNAME record is recommended so the domain doesn’t break if the server IP changes, which may very well happen. That said, we understand sometimes you just need that root domain mapped, so an A Record is nice and will suffice.
Mapping your Root Domain with A Records
For this example, I’ll be mapping the root domain jimgroom.me onto a Github page. In terms of getting your Github pages setup for this see GitHub’s “Setting Up a Custom Domain with GitHub Pages.”
First, you need to find the 'Advanced Zone Editor' under the 'Domains' section in cPanel.
After that, you need to choose the root domain you will be mapping. In the example screenshot below you’ll see I have several, but you may only have one which would be the default.
Once you select the domain you need to create two 'A Records' for it using the below screenshot as a template, through the Name will obviously be different depending on the root domain you are mapping. The two a Records will point to the following IP addresses on GitHub: 188.8.131.52 and 184.108.40.206. You need to create a separate A Record for each of these IPs.
Once you have created both A Records in the Advanced DNS Zone Editor you should be all set. GitHub has their own documentation with “Tips for Configuring an A Record with Your DNS Provider” that might also be useful. If you are having any issue see GitHub’s “My Custom Domain Isn’t Working” or contact email@example.com.
Mapping your Subdomain with CNAME Records
For this examp, e I’ll be mapping the subdomain blog.jimgroom.com onto a GitHub Pages Repository using a CNAME Record. Head to Advanced DNS Settings.
Once there, select the domain you will be mapping to if you have more than one.
Now you name to add a CNAME record with the subdomain you are mapping in the Name field and the URL of your GitHub account in the CNAME field.
After that you should be set. I found even if your repository is jimgroom.github.io/blog like mine is in this instance, you only need jimgroom.githib.io in the CNAME field.
GitHub provides a page with “Tips for configuring a CNAME record with your DNS provider” if you need more help, comment below or put in a support ticket.