{"id":1808,"date":"2020-04-13T14:30:21","date_gmt":"2020-04-13T12:30:21","guid":{"rendered":"https:\/\/bornoe.org\/blog\/?p=1808"},"modified":"2021-10-16T12:25:44","modified_gmt":"2021-10-16T11:25:44","slug":"import-g-suite-mx-records-into-cloudflare-dns-using-zone-files","status":"publish","type":"post","link":"https:\/\/bornoe.org\/blog\/2020\/04\/import-g-suite-mx-records-into-cloudflare-dns-using-zone-files\/","title":{"rendered":"Import G Suite MX records into Cloudflare DNS using zone files"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.cloudflare.com\/dns\/\">The Cloudflare authoritative DNS<\/a> product is a great DNS solution running on one of the world\u2019s fastest infrastructures with high availability. The good part is that they offer a free tier that will suit the needs of most personal and business domains. If you are  managing several domains and often need to add G Suite MX records this process can be somewhat trivial. Unfortunately, Cloudflare does not offer the possibility to define zone templates or similar through the web interface. They do offer API access, but a lot of users will find interaction with the API to be excessive in terms of both needs and technical knowledge.<\/p>\n\n\n\n<p>As a middle ground, Cloudflare has implemented the option to import <a href=\"https:\/\/en.wikipedia.org\/wiki\/Zone_file\">BIND formatted DNS zone files<\/a> through either the web interface or the API. This is easy to learn and an effective approach for importing DNS records.<\/p>\n\n\n\n<p>This approach does have some drawbacks. One important one being that DNS zone files are not designed to modify or remove existing records. Removal of potential existing MX records has to be done through other means such as the web interface.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">BIND formatted DNS zone files adding G Suite MX records<\/h2>\n\n\n\n<p>In the following sections, I have included some BIND formatted DNS zones files that are ready to use and an explanation of two approaches for importing the zone files. The zone files will add MX records and the default G Suite SPF record.<\/p>\n\n\n\n<p>You can either save the text into a file or download the ready to upload DNS zone files. Remember to delete existing MX records if such exist. This can be done before or after importing a zone file. <\/p>\n\n\n\n<p>Both zone files include the basics and use default values. The zone files will assign the Time To Live (TTL) value to the Cloudflare default value <em>&#8220;Auto.&#8221;<\/em> This is by Cloudflare defined to be 300 seconds or 5 minutes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verifying domain ownership.<\/h3>\n\n\n\n<p><meta charset=\"utf-8\">If the domain is not yet verified with G Suite, you will need to verify ownership <meta charset=\"utf-8\">before or after you have configured the DNS records. <meta charset=\"utf-8\">See Googles instructions about <a href=\"https:\/\/support.google.com\/a\/topic\/9196\" data-type=\"URL\" data-id=\"https:\/\/support.google.com\/a\/topic\/9196\">verifying domain ownership<\/a>. One method is to add a unique verification TXT record. See Googles instructions about how to <a href=\"https:\/\/support.google.com\/a\/answer\/183895\">verify your domain with a TXT record<\/a>. You can include the TXT record in your zone file, but the text string is unique for each domain.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DMARC and DKIM records<\/h3>\n\n\n\n<p>The zone files only contain the MX and SPF records. Often you will want to add additionally e-mail related DNS records such as TXT records for DMARC, DKIM settings, etc. You can add the additional records through the web interface or add them to the zone file. Since several of these records are not generic and need customization, it is not possible to include them in a generic zone file template. Google has published documentation about setting up <a href=\"https:\/\/support.google.com\/a\/answer\/2466563\">DMARC<\/a> and <a href=\"https:\/\/support.google.com\/a\/answer\/174124\">DKIM<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Zone file adding G Suite DNSSEC MX records<\/h3>\n\n\n\n<p>While not officially recognized or documented, Google has made a set of DNSSEC MX records available for G Suite hosted domains. This zone file will import the four MX records into Cloudflare.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>;; G Suite - https:\/\/gsuite.google.com\/\n\n;; Adds G Suite DNSSEC MX records.\n\n;; Adds the default G Suite SPF as a TXT record.\n;; Documentation\n;; https:\/\/support.google.com\/a\/answer\/33786\n\n;; MX Records\n@\t1\tIN\tMX\t20 mx4.smtp.goog.\n@\t1\tIN\tMX\t10 mx3.smtp.goog.\n@\t1\tIN\tMX\t5 mx2.smtp.goog.\n@\t1\tIN\tMX\t1 mx1.smtp.goog.\n\n;; TXT Records\n@\t1\tIN\tTXT\t\"v=spf1 include:_spf.google.com ~all\"<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/bornoe.org\/blog\/wp-content\/uploads\/2020\/04\/gsuite-mx-dnssec.txt\">Download as a txt file.<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Zone file adding default G Suite MX records<\/h3>\n\n\n\n<p>This zone file will import the five <a href=\"https:\/\/support.google.com\/a\/answer\/140034\">default G Suite MX records<\/a> into Cloudflare. The MX records are not DNSSEC signed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>;; G Suite - https:\/\/gsuite.google.com\/\n\n;; Adds G Suite MX records\n;; Documentation\n;; https:\/\/support.google.com\/a\/answer\/140034\n\n;; Adds the default G Suite SPF as a TXT record.\n;; Documentation\n;; https:\/\/support.google.com\/a\/answer\/33786\n\n;; MX Records\n@\t1\tIN\tMX\t10 alt4.aspmx.l.google.com.\n@\t1\tIN\tMX\t10 alt3.aspmx.l.google.com.\n@\t1\tIN\tMX\t5 alt2.aspmx.l.google.com.\n@\t1\tIN\tMX\t5 alt1.aspmx.l.google.com.\n@\t1\tIN\tMX\t1 aspmx.l.google.com.\n\n;; TXT Records\n@\t1\tIN\tTXT\t\"v=spf1 include:_spf.google.com ~all\"<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/bornoe.org\/blog\/wp-content\/uploads\/2020\/04\/gsuite-mx.txt\">Download as a txt file.<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to import a DNS zone file<\/h2>\n\n\n\n<p>You can import a BIND formatted zone files through either the Cloudflare web interface or API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Import through the web interface<\/h3>\n\n\n\n<p>To import a DNS zone file through the web interface follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li> Log into the Cloudflare Dashboard at <a href=\"https:\/\/dash.cloudflare.com\/\">https:\/\/dash.cloudflare.com\/<\/a><\/li><li>Click on the <em>domain<\/em> in question, e.g. example.com.<\/li><li>Click the menu item <strong>&#8220;DNS&#8221;<\/strong><\/li><li>Click on <strong>&#8220;Advanced&#8221;<\/strong><\/li><li>Either click on <strong>&#8220;Select a file&#8221;<\/strong> or <em>drag the DNS zone file into the upload area<\/em>.<\/li><li>Click <strong>&#8220;Upload&#8221;<\/strong><\/li><\/ol>\n\n\n\n<p>The DNS records are now activated. Remember to remove preexisting MX records if you have not already done so. Having MX records from several different providers will most likely break the setup and result in undeliverable e-mails.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Import through the API using curl<\/h3>\n\n\n\n<p>A neat feature is that you can import a BIND formatted DNS zone file through the <a href=\"https:\/\/api.cloudflare.com\/\">Cloudflare API<\/a>. Below is an example of how this can be done using <a href=\"https:\/\/curl.haxx.se\/\">curl<\/a>. curl is preinstalled on macOS and a lot of Linux distributions. If you don&#8217;t have curl you can install it through your Linux distribution&#8217;s package manager, or download it from <a href=\"https:\/\/curl.haxx.se\/\">https:\/\/curl.haxx.se\/<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X POST \"https:\/\/api.cloudflare.com\/client\/v4\/zones\/CF-ZONE-ID\/dns_records\/import\" \\\n     -H \"X-Auth-Email: CF-ACCOUNT-EMAIL\" \\\n     -H \"X-Auth-Key: CF-API-KEY\" \\\n     --form 'file=@FILE-NAME' \\\n     --form 'proxied=false'<\/code><\/pre>\n\n\n\n<p>You need to customize the API call by editing the four values described below:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>CF-ZONE-ID:<\/strong> All domains have a unique ID number called a <em>&#8220;Zone ID&#8221;<\/em>. You can retrieve a zone ID by logging into the Cloudflare Dashboard at <a href=\"https:\/\/dash.cloudflare.com\/\">https:\/\/dash.cloudflare.com\/<\/a>, then clicking on the <em>domain<\/em> in question, and finally locate the <em>&#8220;Zone ID&#8221;<\/em> on the tab <em>&#8220;Overview.&#8221;<\/em><\/li><li><strong>CF-ACCOUNT-EMAIL:<\/strong> Your Cloudflare login e-mail address.<\/li><li><strong>CF-API-KEY:<\/strong> Your API-key can be found by clicking <strong>&#8220;View&#8221;<\/strong> under <em>&#8220;Global API Key&#8221;<\/em> in the subsection <em>&#8220;API Tokens&#8221;<\/em> at <a href=\"https:\/\/dash.cloudflare.com\/profile\/api-tokens\">https:\/\/dash.cloudflare.com\/profile\/api-tokens\/<\/a><\/li><li><strong>FILE-NAME:<\/strong> The name of the file containing your DNS zone data, e.g., domain.txt. In this example, the file is assumed to be presented in the same directory from which you are calling curl. Otherwise, you will need to include the full path to the file. <\/li><\/ul>\n\n\n\n<p>Remember to remove preexisting MX records if you have not already done so. This can be archived through the <a href=\"https:\/\/dash.cloudflare.com\/\">web interface<\/a>. Having MX records from several different providers will most likely break e-mail deliverability. It is not possible to remove DNS records through DNS zone files.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Cloudflare authoritative DNS product is a great DNS solution running on one of the world\u2019s fastest infrastructures with high availability. The good part is that they offer a free tier that will suit the needs of most personal and business domains. If you are managing several domains and often need to add G Suite [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1846,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,21,20],"tags":[],"class_list":["post-1808","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloudflare","category-dns","category-domains"],"_links":{"self":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts\/1808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/comments?post=1808"}],"version-history":[{"count":3,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts\/1808\/revisions"}],"predecessor-version":[{"id":2181,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts\/1808\/revisions\/2181"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/media\/1846"}],"wp:attachment":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/media?parent=1808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/categories?post=1808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/tags?post=1808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}