Muokkaa

Jaa


Quickstart: Create an Azure DNS zone and record using Azure PowerShell

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

In this quickstart, you create your first DNS zone and record using Azure PowerShell. You can also perform these steps using the Azure portal or the Azure CLI.

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 in this article.

Diagram of DNS deployment environment using the Azure portal.

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.

Prerequisites

  • An Azure account with an active subscription. Create an account for free.
  • Azure PowerShell installed locally or Azure Cloud Shell

Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.

To start Azure Cloud Shell:

Option Example/Link
Select Try It in the upper-right corner of a code or command block. Selecting Try It doesn't automatically copy the code or command to Cloud Shell. Screenshot that shows an example of Try It for Azure Cloud Shell.
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser. Button to launch Azure Cloud Shell.
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal. Screenshot that shows the Cloud Shell button in the Azure portal

To use Azure Cloud Shell:

  1. Start Cloud Shell.

  2. Select the Copy button on a code block (or command block) to copy the code or command.

  3. Paste the code or command into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.

  4. Select Enter to run the code or command.

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

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")

View records

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:

  1. Run the following cmdlet to get the list of name servers for your zone:

    Get-AzDnsRecordSet -ZoneName contoso.xyz -ResourceGroupName MyResourceGroup -RecordType ns
    
  2. Copy one of the name server names from the output of the previous step.

  3. Open a command prompt, and run the following command:

    nslookup www.contoso.xyz <name server name>
    

    For example:

    nslookup www.contoso.xyz ns1-08.azure-dns.com.
    

    You should see something like the following screen:

    Screenshot shows a command prompt window with an n s lookup command and values for Server, Address, Name, and Address.

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.

Clean up resources

When no longer needed, you can delete all resources created in this quickstart by deleting the resource group:

Remove-AzResourceGroup -Name MyResourceGroup

Next steps

Now that your first DNS zone and record is created using Azure PowerShell, you can create records for a web app in a custom domain.