快速入门:使用 Azure PowerShell 创建 Azure DNS 区域和记录Quickstart: Create an Azure DNS zone and record using Azure PowerShell

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

在本快速入门中,你将使用 Azure PowerShell 创建你的第一个 DNS 区域和记录。In this quickstart, you create your first DNS zone and record using Azure PowerShell. 也可以使用 Azure 门户Azure CLI 执行这些步骤。You can also perform these steps using the Azure portal or the Azure CLI.

DNS 区域用来托管某个特定域的 DNS 记录。A DNS zone is used to host the DNS records for a particular domain. 若要开始在 Azure DNS 中托管域,需要为该域名创建 DNS 区域。To start hosting your domain in Azure DNS, you need to create a DNS zone for that domain name. 随后会在此 DNS 区域内为每个 DNS 记录创建域。Each DNS record for your domain is then created inside this DNS zone. 最后,要将 DNS 区域发布到 Internet,需要为域配置名称服务器。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 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

创建资源组Create the resource group

在创建 DNS 区域之前,创建一个资源组来包含 DNS 区域:Before you create the DNS zone, create a resource group to contain the DNS zone:

New-AzResourceGroup -name MyResourceGroup -location "chinaeast"

创建 DNS 区域Create a DNS zone

通过使用 New-AzDnsZone cmdlet 创建 DNS 区域。A DNS zone is created by using the New-AzDnsZone cmdlet. 以下示例在名为 MyResourceGroup 的资源组中创建名为 contoso.xyz 的 DNS 区域。The following example creates a DNS zone called contoso.xyz in the resource group called MyResourceGroup. 使用该示例创建 DNS 区域,将相应的值替换成自己的值。Use the example to create a DNS zone, substituting the values for your own.

New-AzDnsZone -Name contoso.xyz -ResourceGroupName MyResourceGroup

创建 DNS 记录Create a DNS record

可以使用 New-AzDnsRecordSet cmdlet 创建记录集。You create record sets by using the New-AzDnsRecordSet cmdlet. 下面的示例在资源组“MyResourceGroup”的 DNS 区域“contoso.xyz”中创建相对名称为“www”的一个记录。The following example creates a record with the relative name "www" in the DNS Zone "contoso.xyz", in resource group "MyResourceGroup". 记录集的完全限定名称为“www.contoso.xyz”。The fully qualified name of the record set is "www.contoso.xyz". 记录类型为“A”,IP 地址为“10.10.10.10”,TTL 为 3600 秒。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

若要列出区域中的 DNS 记录,请使用:To list the DNS records in your zone, use:

Get-AzDnsRecordSet -ZoneName contoso.xyz -ResourceGroupName MyResourceGroup

测试名称解析Test the name resolution

现在,你已有一个测试 DNS 区域且其中有一个测试“A”记录,可以使用名为 nslookup 的工具来测试名称解析了。Now that you have a test DNS zone with a test 'A' record, you can test the name resolution with a tool called nslookup.

测试 DNS 名称解析:To test DNS name resolution:

  1. 运行以下 cmdlet 以获取区域的名称服务器列表: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.cn.
    

    应当会看到类似以下屏幕的内容:You should see something like the following screen:

    nslookup

主机名 www.contoso.xyz 解析为 10.10.10.10,正如你配置的那样。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

后续步骤Next steps

现在,你已使用 Azure PowerShell 创建了你的第一个 DNS 区域和记录,可以在自定义域中为 Web 应用创建记录了。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.