Import and export a Azure DNS zone file using CLI

Import a DNS zone file into Azure DNS

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.

Merge behavior

  • By default, existing and new record sets are merged. Identical records within a merged record set are de-duplicated.
  • When record sets are merged, the time to live (TTL) of preexisting record sets is used.
  • Start of Authority (SOA) parameters (except host) 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.
  • An imported CNAME record does not replace an existing CNAME record with the same name.
  • 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.

Additional information about importing

The following notes provide additional technical details about the zone import process.

  • The $TTL directive is optional, and it is supported. When no $TTL 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.
  • The $ORIGIN directive is optional, and it is supported. When no $ORIGIN is set, the default value used is the zone name as specified on the command line (plus the terminating “.”).
  • The $INCLUDE and $GENERATE directives are not supported.
  • These record types are supported: A, AAAA, CNAME, MX, NS, SOA, SRV, and TXT.
  • 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 except the host 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.
  • 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.
  • During Public Preview, Azure DNS supports only single-string TXT records. Multistring TXT records are be concatenated and truncated to 255 characters.

CLI format and values

The format of the Azure CLI command to import a DNS zone is:

az network dns zone import -g <resource group> -n <zone name> -f <zone file name>

 

Values:

  • <resource group> is the name of the resource group for the zone in Azure DNS.
  • <zone name> is the name of the zone.
  • <zone file name> is the path/name of the zone file to be imported.

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.

Step 1. Import a zone file

To import a zone file for the zone chirkut.com.

  1. If you don’t have one already, you need to create a Resource Manager resource group.

az group create –group myresourcegroup -l westeurope

2. To import the zone chirkut.com from the file chirkut.com.txt into a new DNS zone in the resource group myresourcegroup, you will run the command az network dns zone import.
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.

az network dns zone import -g myresourcegroup -n chirkut.com -f contoso.com.txt

Step 2. Verify the zone

To verify the DNS zone after you import the file, you can use any one of the following methods:

  • You can list the records by using the following Azure CLI command:

az network dns record-set list -g myresourcegroup -z chirkut.com

 

  • You can list the records by using the PowerShell cmdlet Get-AzureRmDnsRecordSet.
  • You can use nslookup to verify name resolution for the records. Because the zone isn’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 “www” record by using nslookup.

az network dns record-set ns list -g myresourcegroup -z –output json

 

CMD

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

Step 3. Update DNS delegation

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 Update the DNS delegation.

Export a DNS zone file from Azure DNS

The format of the Azure CLI command to import a DNS zone is:

az network dns zone export -g <resource group> -n <zone name> -f <zone file name>

Values:

  • <resource group> is the name of the resource group for the zone in Azure DNS.
  • <zone name> is the name of the zone.
  • <zone file name> is the path/name of the zone file to be exported.

As with the zone import, you first need to sign in, choose your subscription, and configure the Azure CLI to use Resource Manager mode.

To export a zone file

To export the existing Azure DNS zone chirkut.com in resource group myresourcegroup to the file chirkut.com.txt (in the current folder), run azure network dns zone export. This command calls the Azure DNS service to enumerate record sets in the zone and export the results to a BIND-compatible zone file.

az network dns zone export -g myresourcegroup -n chirkut.com -f chirkut.com.txt

Leave a Reply

Your email address will not be published. Required fields are marked *