Quickstart: Create an Azure DNS zone and record using Azure PowerShell
This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.
A DNS zone is used to host the DNS records for a particular domain. To start hosting your domain in Azure DNS, you need to create a DNS zone for that domain name. Each DNS record for your domain is then created inside this DNS zone. Finally, to publish your DNS zone to the Internet, you need to configure the name servers for the domain. Each of these steps is described below.
Azure DNS also supports creating private domains. For step-by-step instructions about how create your first private DNS zone and record, see Get started with Azure DNS private zones using PowerShell.
Use Azure Cloud Shell
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. Cloud Shell lets you use either
PowerShell to work with Azure services. You can use the Cloud Shell pre-installed commands to run the code in this article without having to install anything on your local environment.
To launch Azure Cloud Shell:
|Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell.|
|Go to https://shell.azure.com or select the Launch Cloud Shell button to open Cloud Shell in your browser.|
|Select the Cloud Shell button on the top-right menu bar in the Azure portal.|
To run the code in this article in Azure Cloud Shell:
Launch Cloud Shell.
Select the Copy button on a code block to copy the code.
Paste the code into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS.
Press Enter to run the code.
If you don't have an Azure subscription, create a free account before you begin.
Create the resource group
Before you create the DNS zone, create a resource group to contain the DNS zone:
New-AzResourceGroup -name MyResourceGroup -location "eastus"
Create a DNS zone
A DNS zone is created by using the
New-AzDnsZone cmdlet. The following example creates a DNS zone called contoso.xyz in the resource group called MyResourceGroup. Use the example to create a DNS zone, substituting the values for your own.
New-AzDnsZone -Name contoso.xyz -ResourceGroupName MyResourceGroup
Create a DNS record
You create record sets by using the
New-AzDnsRecordSet cmdlet. The following example creates a record with the relative name "www" in the DNS Zone "contoso.xyz", in resource group "MyResourceGroup". The fully qualified name of the record set is "www.contoso.xyz". The record type is "A", with IP address "10.10.10.10", and the TTL is 3600 seconds.
New-AzDnsRecordSet -Name www -RecordType A -ZoneName contoso.xyz -ResourceGroupName MyResourceGroup -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "10.10.10.10")
To list the DNS records in your zone, use:
Get-AzDnsRecordSet -ZoneName contoso.xyz -ResourceGroupName MyResourceGroup
Test the name resolution
Now that you have a test DNS zone with a test 'A' record, you can test the name resolution with a tool called nslookup.
To test DNS name resolution:
Run the following cmdlet to get the list of name servers for your zone:
Get-AzDnsRecordSet -ZoneName contoso.xyz -ResourceGroupName MyResourceGroup -RecordType ns
Copy one of the name server names from the output of the previous step.
Open a command prompt, and run the following command:
nslookup www.contoso.xyz <name server name>
nslookup www.contoso.xyz ns1-08.azure-dns.com.
You should see something like the following screen:
The host name www.contoso.xyz resolves to 10.10.10.10, just as you configured it. This result verifies that name resolution is working correctly.
Delete all resources
When no longer needed, you can delete all resources created in this quickstart by deleting the resource group:
Remove-AzResourceGroup -Name MyResourceGroup
Now that you've created your first DNS zone and record using Azure PowerShell, you can create records for a web app in a custom domain.