Fixing github page and G-suite email dns issue to use same host name

For a small business, lower the daily cost is a good way to run business. github page provides an easy and free way to create website. and gsuite provides bunch of features for small business like emails, calendars and drives etc. After you applied a domain name from a DNS provider, the followup setting of dns to pointing different services to different venders is a must-do. that is, point web service to github, and email service to google.

To point web service to a certain server, normally people are using CNAME. and to redirect email service to google, it should use MX. but unfortunately, CNAME can not be used with MX record at the same time, it is a limitation of DNS itself. CNAME setting will break MX record.

According to RFC 1034:

If a CNAME RR is present at a node, no other data should be
present; this ensures that the data for a canonical name and its aliases
cannot be different.

Understanding the differences

These are the main differences:

  • The A record maps a name to one or more IP addresses when the IP are known and stable.
  • The CNAME record maps a name to another name. It should only be used when there are no other records on that name.
  • The ALIAS record maps a name to another name, but can coexist with other records on that name.
  • The URL record redirects the name to the target name using the HTTP 301 status code.

Important rules:

  • The A, CNAME, and ALIAS records cause a name to resolve to an IP. Conversely, the URL record redirects the name to a destination. The URL record is a simple and effective way to apply a redirect for one name to another name, for example redirecting www.example.com to example.com.
  • The A name must resolve to an IP. The CNAME and ALIAS records must point to a name.
  • Use an A record if you manage which IP addresses are assigned to a particular machine, or if the IP are fixed (this is the most common case).
  • Use a CNAME record if you want to alias one name to another name, and you don’t need other records (such as MX records for emails) for the same name.

The solution is also simple, don’t use CNAME to redirect web service, but using A record to point the web service to the service provider’s IP address.

Configuring an apex domain

To set up an apex domain, such as example.com, you must configure a CNAME file in your GitHub Pages repository and an ALIAS, ANAME, or A record with your DNS provider.

  1. On GitHub, go to your site’s repository.
  2. Under your repository name, click Settings.
Image for post
Image for post

3. Under “Custom domain”, type your custom domain, then click Save. This will create a commit that adds a CNAME file in the root of your publishing source.

Image for post
Image for post

4. Navigate to your DNS provider and create either an ALIAS, ANAME, or A record. For more information about how to create the correct record, see your DNS provider's documentation.

  • To create an ALIAS or ANAME record, point your apex domain to the default domain for your site. For more information about the default domain for your site, see "About GitHub Pages."
  • To create an A record, point your apex domain to the IP addresses for GitHub Pages.
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
Image for post
Image for post

Then Open a Terminal.

To confirm that your DNS record configured correctly, use the dig command, replacing EXAMPLE.COM with your apex domain. Confirm that the results match the IP addresses for GitHub Pages above.

$ dig EXAMPLE.COM +noall +answer
> EXAMPLE.COM 3600 IN A 185.199.108.153
> EXAMPLE.COM 3600 IN A 185.199.109.153
> EXAMPLE.COM 3600 IN A 185.199.110.153
> EXAMPLE.COM 3600 IN A 185.199.111.153

To setting gmail for gsuite in dns, it is also very straightforward. Just setting up MX records like following, then we have done.

Priority Points to
1 ASPMX.L.GOOGLE.COM.
5 ALT1.ASPMX.L.GOOGLE.COM.
5 ALT2.ASPMX.L.GOOGLE.COM.
10 ALT3.ASPMX.L.GOOGLE.COM.
10 ALT4.ASPMX.L.GOOGLE.COM.
TTL can be automatic or 60 mins or 3600 seconds
Image for post
Image for post

It can also using https://toolbox.googleapps.com/apps/dig/#CNAME/ to get the dig result. normally, after configuration changed in dns service provider. it will take about 45 minutes to populate the changes over the internet.

Reference:

Written by

自由撰稿人,时评人,平等公义追求者

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store