{"id":1704,"date":"2020-07-09T23:20:02","date_gmt":"2020-07-10T06:20:02","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=1704"},"modified":"2020-07-09T23:20:02","modified_gmt":"2020-07-10T06:20:02","slug":"import-and-export-a-dns-zone-file-using-the-azure-cli","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=1704","title":{"rendered":"Import and export a DNS zone file using the Azure CLI"},"content":{"rendered":"\n<p>This article walks you through how to import and export DNS zone files for Azure DNS using the Azure CLI.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction-to-dns-zone-migration\">Introduction to DNS zone migration<\/h2>\n\n\n\n<p>A DNS zone file is a text file that contains details of every Domain Name System (DNS) record in the zone. It follows a standard format, making it suitable for transferring DNS records between DNS systems. Using a zone file is a quick, reliable, and convenient way to transfer a DNS zone into or out of Azure DNS.<\/p>\n\n\n\n<p>Azure DNS supports importing and exporting zone files by using the Azure command-line interface (CLI). Zone file import is&nbsp;<strong>not<\/strong>&nbsp;currently supported via Azure PowerShell or the Azure portal.<\/p>\n\n\n\n<p>The Azure CLI is a cross-platform command-line tool used for managing Azure services. It is available for the Windows, Mac, and Linux platforms from the&nbsp;<a href=\"https:\/\/azure.microsoft.com\/downloads\/\">Azure downloads page<\/a>. Cross-platform support is important for importing and exporting zone files, because the most common name server software,&nbsp;<a href=\"https:\/\/www.isc.org\/downloads\/bind\/\">BIND<\/a>, typically runs on Linux.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"obtain-your-existing-dns-zone-file\">Obtain your existing DNS zone file<\/h2>\n\n\n\n<p>Before you import a DNS zone file into Azure DNS, you need to obtain a copy of the zone file. The source of this file depends on where the DNS zone is currently hosted.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>If your DNS zone is hosted by a partner service (such as a domain registrar, dedicated DNS hosting provider, or alternative cloud provider), that service should provide the ability to download the DNS zone file.<\/li><li>If your DNS zone is hosted on Windows DNS, the default folder for the zone files is&nbsp;<strong>%systemroot%\\system32\\dns<\/strong>. The full path to each zone file also shows on the&nbsp;<strong>General<\/strong>&nbsp;tab of the DNS console.<\/li><li>If your DNS zone is hosted by using BIND, the location of the zone file for each zone is specified in the BIND configuration file&nbsp;<strong>named.conf<\/strong>.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"import-a-dns-zone-file-into-azure-dns\">Import a DNS zone file into Azure DNS<\/h2>\n\n\n\n<p>Importing a zone file creates a new zone in Azure DNS if one does not already exist. If the zone already exists, the record sets in the zone file must be merged with the existing record sets.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"merge-behavior\">Merge behavior<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>By default, existing and new record sets are merged. Identical records within a merged record set are de-duplicated.<\/li><li>When record sets are merged, the time to live (TTL) of preexisting record sets is used.<\/li><li>Start of Authority (SOA) parameters (except&nbsp;<code>host<\/code>) are always taken from the imported zone file. Similarly, for the name server record set at the zone apex, the TTL is always taken from the imported zone file.<\/li><li>An imported CNAME record does not replace an existing CNAME record with the same name.<\/li><li>When a conflict arises between a CNAME record and another record of the same name but different type (regardless of which is existing or new), the existing record is retained.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"additional-information-about-importing\">Additional information about importing<\/h3>\n\n\n\n<p>The following notes provide additional technical details about the zone import process.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The&nbsp;<code>$TTL<\/code>&nbsp;directive is optional, and it is supported. When no&nbsp;<code>$TTL<\/code>&nbsp;directive is given, records without an explicit TTL are imported set to a default TTL of 3600 seconds. When two records in the same record set specify different TTLs, the lower value is used.<\/li><li>The&nbsp;<code>$ORIGIN<\/code>&nbsp;directive is optional, and it is supported. When no&nbsp;<code>$ORIGIN<\/code>&nbsp;is set, the default value used is the zone name as specified on the command line (plus the terminating &#8220;.&#8221;).<\/li><li>The&nbsp;<code>$INCLUDE<\/code>&nbsp;and&nbsp;<code>$GENERATE<\/code>&nbsp;directives are not supported.<\/li><li>These record types are supported: A, AAAA, CAA, CNAME, MX, NS, SOA, SRV, and TXT.<\/li><li>The SOA record is created automatically by Azure DNS when a zone is created. When you import a zone file, all SOA parameters are taken from the zone file&nbsp;<em>except<\/em>&nbsp;the&nbsp;<code>host<\/code>&nbsp;parameter. This parameter uses the value provided by Azure DNS. This is because this parameter must refer to the primary name server provided by Azure DNS.<\/li><li>The name server record set at the zone apex is also created automatically by Azure DNS when the zone is created. Only the TTL of this record set is imported. These records contain the name server names provided by Azure DNS. The record data is not overwritten by the values contained in the imported zone file.<\/li><li>During Public Preview, Azure DNS supports only single-string TXT records. Multistring TXT records are be concatenated and truncated to 255 characters.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"cli-format-and-values\">CLI format and values<\/h3>\n\n\n\n<p>The format of the Azure CLI command to import a DNS zone is:Azure CLICopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az network dns zone import -g &lt;resource group> -n &lt;zone name> -f &lt;zone file name><\/code><\/pre>\n\n\n\n<p>Values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>&lt;resource group&gt;<\/code>&nbsp;is the name of the resource group for the zone in Azure DNS.<\/li><li><code>&lt;zone name&gt;<\/code>&nbsp;is the name of the zone.<\/li><li><code>&lt;zone file name&gt;<\/code>&nbsp;is the path\/name of the zone file to be imported.<\/li><\/ul>\n\n\n\n<p>If a zone with this name does not exist in the resource group, it is created for you. If the zone already exists, the imported record sets are merged with existing record sets.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-1-import-a-zone-file\">Step 1. Import a zone file<\/h3>\n\n\n\n<p>To import a zone file for the zone&nbsp;<strong>contoso.com<\/strong>.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>If you don&#8217;t have one already, you need to create a Resource Manager resource group.Azure CLICopy<code>az group create --group myresourcegroup -l westeurope<\/code><\/li><li>To import the zone&nbsp;<strong>contoso.com<\/strong>&nbsp;from the file&nbsp;<strong>contoso.com.txt<\/strong>&nbsp;into a new DNS zone in the resource group&nbsp;<strong>myresourcegroup<\/strong>, you will run the command&nbsp;<code>az network dns zone import<\/code>.<br>This command loads the zone file and parses it. The command executes a series of commands on the Azure DNS service to create the zone and all the record sets in the zone. The command reports progress in the console window, along with any errors or warnings. Because record sets are created in series, it may take a few minutes to import a large zone file.Azure CLICopy<code>az network dns zone import -g myresourcegroup -n contoso.com -f contoso.com.txt<\/code><\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-2-verify-the-zone\">Step 2. Verify the zone<\/h3>\n\n\n\n<p>To verify the DNS zone after you import the file, you can use any one of the following methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You can list the records by using the following Azure CLI command:Azure CLICopy<code>az network dns record-set list -g myresourcegroup -z contoso.com<\/code><\/li><li>You can list the records by using the Azure CLI command&nbsp;<code>az network dns record-set ns list<\/code>.<\/li><li>You can use&nbsp;<code>nslookup<\/code>&nbsp;to verify name resolution for the records. Because the zone isn&#8217;t delegated yet, you need to specify the correct Azure DNS name servers explicitly. The following sample shows how to retrieve the name server names assigned to the zone. This also shows how to query the &#8220;www&#8221; record by using&nbsp;<code>nslookup<\/code>.Azure CLICopy<code>az network dns record-set ns list -g myresourcegroup -z contoso.com --output json <\/code>JSONCopy<code>[ { ....... \"name\": \"@\", \"nsRecords\": [ { \"additionalProperties\": {}, \"nsdname\": \"ns1-03.azure-dns.com.\" }, { \"additionalProperties\": {}, \"nsdname\": \"ns2-03.azure-dns.net.\" }, { \"additionalProperties\": {}, \"nsdname\": \"ns3-03.azure-dns.org.\" }, { \"additionalProperties\": {}, \"nsdname\": \"ns4-03.azure-dns.info.\" } ], \"resourceGroup\": \"myresourcegroup\", \"ttl\": 86400, \"type\": \"Microsoft.Network\/dnszones\/NS\" } ] <\/code>cmdCopy<code>nslookup www.contoso.com ns1-03.azure-dns.com Server: ns1-01.azure-dns.com Address: 40.90.4.1 Name:www.contoso.com Addresses: 134.170.185.46 134.170.188.221<\/code><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-3-update-dns-delegation\">Step 3. Update DNS delegation<\/h3>\n\n\n\n<p>After you have verified that the zone has been imported correctly, you need to update the DNS delegation to point to the Azure DNS name servers. For more information, see the article&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/dns\/dns-domain-delegation\">Update the DNS delegation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"export-a-dns-zone-file-from-azure-dns\">Export a DNS zone file from Azure DNS<\/h2>\n\n\n\n<p>The format of the Azure CLI command to export a DNS zone is:Azure CLICopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az network dns zone export -g &lt;resource group> -n &lt;zone name> -f &lt;zone file name><\/code><\/pre>\n\n\n\n<p>Values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>&lt;resource group&gt;<\/code>&nbsp;is the name of the resource group for the zone in Azure DNS.<\/li><li><code>&lt;zone name&gt;<\/code>&nbsp;is the name of the zone.<\/li><li><code>&lt;zone file name&gt;<\/code>&nbsp;is the path\/name of the zone file to be exported.<\/li><\/ul>\n\n\n\n<p>As with the zone import, you first need to sign in, choose your subscription, and configure the Azure CLI to use Resource Manager mode.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"to-export-a-zone-file\">To export a zone file<\/h3>\n\n\n\n<p>To export the existing Azure DNS zone&nbsp;<strong>contoso.com<\/strong>&nbsp;in resource group&nbsp;<strong>myresourcegroup<\/strong>&nbsp;to the file&nbsp;<strong>contoso.com.txt<\/strong>&nbsp;(in the current folder), run&nbsp;<code>azure network dns zone export<\/code>. This command calls the Azure DNS service to enumerate record sets in the zone and export the results to a BIND-compatible zone file.Azure CLICopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az network dns zone export -g myresourcegroup -n contoso.com -f contoso.com.txt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"next-steps\">Next steps<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Learn how to&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/dns\/dns-getstarted-create-recordset-cli\">manage record sets and records<\/a>&nbsp;in your DNS zone.<\/li><li>Learn how to&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/dns\/dns-domain-delegation\">delegate your domain to Azure DNS<\/a>.<\/li><\/ul>\n\n\n\n<p>Original:  <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/dns\/dns-import-export\">https:\/\/docs.microsoft.com\/en-us\/azure\/dns\/dns-import-export<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article walks you through how to import and export DNS zone files for Azure DNS using the Azure CLI. Introduction to DNS zone migration A DNS zone file is a text file that contains details of every Domain Name System (DNS) record in the zone. It follows a standard format, making it suitable for <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=1704\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[238,239],"tags":[],"class_list":["post-1704","post","type-post","status-publish","format-standard","hentry","category-cloud","category-azure"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/1704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1704"}],"version-history":[{"count":0,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/1704\/revisions"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}