你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 Azure PowerShell 委托 Azure DNS 子域

可以使用 Azure PowerShell 委托 DNS 子域。 例如,如果拥有 contoso.com 域,则可将名为 engineering 的子域委托给另一个可以独立于 contoso.com 区域进行管理的单独区域。

如果需要,也可以使用 Azure 门户来委托子域。

注意

本文通篇都使用 contoso.com 作为示例。 请将 contoso.com 替换为你自己的域名。

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户

Azure Cloud Shell

Azure 托管 Azure Cloud Shell(一个可通过浏览器使用的交互式 shell 环境)。 可以将 Bash 或 PowerShell 与 Cloud Shell 配合使用来使用 Azure 服务。 可以使用 Cloud Shell 预安装的命令来运行本文中的代码,而不必在本地环境中安装任何内容。

若要启动 Azure Cloud Shell,请执行以下操作:

选项 示例/链接
选择代码或命令块右上角的“试用”。 选择“试用”不会自动将代码或命令复制到 Cloud Shell。 Screenshot that shows an example of Try It for Azure Cloud Shell.
转到 https://shell.azure.com 或选择启动 Cloud Shell 按钮可在浏览器中打开 Cloud Shell。 Button to launch Azure Cloud Shell.
选择 Azure 门户右上角菜单栏上的 Cloud Shell 按钮。 Screenshot that shows the Cloud Shell button in the Azure portal

若要使用 Azure Cloud Shell,请执行以下操作:

  1. 启动 Cloud Shell。

  2. 选择代码块(或命令块)上的“复制”按钮以复制代码或命令。

  3. 在 Windows 和 Linux 上选择 Ctrl+Shift+V,或在 macOS 上选择 Cmd+Shift+V 将代码或命令粘贴到 Cloud Shell 会话中。

  4. 选择“Enter”运行代码或命令。

先决条件

若要委托 Azure DNS 子域,必须先将公共域委托给 Azure DNS。 有关如何为委托配置名称服务器的说明,请参阅将域委托给 Azure DNS。 将域委托给 Azure DNS 区域后,可以委托子域。

为子域创建区域

首先,为 engineering 域创建区域。

New-AzDnsZone -ResourceGroupName <resource group name> -Name engineering.contoso.com

记下名称服务器

接下来,记下 engineering 子域的四个名称服务器。

Get-AzDnsRecordSet -ZoneName engineering.contoso.com -ResourceGroupName <resource group name> -RecordType NS

创建一条测试记录

在 engineering 区域中创建一条 A 记录以用于测试。

New-AzDnsRecordSet -ZoneName engineering.contoso.com -ResourceGroupName <resource group name> -Name www -RecordType A -ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address 10.10.10.10)

创建 NS 记录

接下来,为 contoso.com 区域中的 engineering 区域创建一条名称服务器 (NS) 记录。

$Records = @()
$Records += New-AzDnsRecordConfig -Nsdname <name server 1 noted previously>
$Records += New-AzDnsRecordConfig -Nsdname <name server 2 noted previously>
$Records += New-AzDnsRecordConfig -Nsdname <name server 3 noted previously>
$Records += New-AzDnsRecordConfig -Nsdname <name server 4 noted previously>
$RecordSet = New-AzDnsRecordSet -Name engineering -RecordType NS -ResourceGroupName <resource group name> -TTL 3600 -ZoneName contoso.com -DnsRecords $Records

测试委托

使用 nslookup 测试委托。

  1. 打开 PowerShell 窗口。

  2. 在命令提示符下,键入 nslookup www.engineering.contoso.com.

  3. 应会收到一条非权威回复,其中显示了地址 10.10.10.10

后续步骤

了解如何为 Azure 中托管的服务配置反向 DNS