使用 Azure PowerShell 管理 Azure DNS 中的 DNS 记录和记录集Manage DNS records and recordsets in Azure DNS using Azure PowerShell

本文介绍如何使用 Azure PowerShell 管理 DNS 区域的 DNS 记录。This article shows you how to manage DNS records for your DNS zone by using Azure PowerShell. 也可使用跨平台的 Azure CLIAzure 门户管理 DNS 记录。DNS records can also be managed by using the cross-platform Azure CLI or the Azure portal.

本文中的示例假设用户已经安装并登录 Azure PowerShell 以及创建了 DNS 区域The examples in this article assume you have already installed Azure PowerShell, signed in, and created a DNS zone.

备注

本文进行了更新,以便使用新的 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.

简介Introduction

在 Azure DNS 中创建 DNS 记录之前,首先需了解 Azure DNS 如何将 DNS 记录组织到 DNS 记录集中。Before creating DNS records in Azure DNS, you first need to understand how Azure DNS organizes DNS records into DNS record sets.

记录名称Record names

在 Azure DNS 中,记录使用相对名称指定。In Azure DNS, records are specified by using relative names. 完全限定的 域名 (FQDN) 包括区域名称,而相对 域名则不包括。A fully qualified domain name (FQDN) includes the zone name, whereas a relative name does not. 例如,contoso.com 区域中的相对记录名称 www 会提供完全限定的记录名称 www.contoso.comFor example, the relative record name www in the zone contoso.com gives the fully qualified record name www.contoso.com.

顶点 记录是位于 DNS 区域的根(或顶点 )中的 DNS 记录。An apex record is a DNS record at the root (or apex) of a DNS zone. 例如,在 DNS 区域 contoso.com 中,顶点记录还具有完全限定的名称 contoso.com(有时称为裸域)。For example, in the DNS zone contoso.com, an apex record also has the fully qualified name contoso.com (this is sometimes called a naked domain). 按照惯例,相对名称“@”用于表示顶点记录。By convention, the relative name '@' is used to represent apex records.

记录类型Record types

每个 DNS 记录都有一个名称和类型。Each DNS record has a name and a type. 这些记录根据其所包含的数据分为各种类型。Records are organized into various types according to the data they contain. 最常见的类型为“A”记录,这种记录将名称映射到 IPv4 地址。The most common type is an 'A' record, which maps a name to an IPv4 address. 另一种常见类型是“MX”记录,这种记录将名称映射到邮件服务器。Another common type is an 'MX' record, which maps a name to a mail server.

Azure DNS 支持所有常见 DNS 记录类型:A、AAAA、CAA、CNAME、MX、NS、PTR、SOA、SRV 和 TXT。Azure DNS supports all common DNS record types: A, AAAA, CAA, CNAME, MX, NS, PTR, SOA, SRV, and TXT. 请注意,SPF 记录使用 TXT 记录表示Note that SPF records are represented using TXT records.

记录集Record sets

有时,需要创建具有给定名称和类型的多个 DNS 记录。Sometimes you need to create more than one DNS record with a given name and type. 例如,假设在两个不同的 IP 地址上托管“www.contoso.com”网站。For example, suppose the 'www.contoso.com' web site is hosted on two different IP addresses. 该网站需要两个不同的 A 记录,每个 IP 地址一个。The website requires two different A records, one for each IP address. 这就是记录集的示例:Here is an example of a record set:

www.contoso.com.        3600    IN    A    134.170.185.46
www.contoso.com.        3600    IN    A    134.170.188.221

Azure DNS 使用记录集 管理所有 DNS 记录。Azure DNS manages all DNS records using record sets. 记录集(也称为资源 记录集)是某个区域中具有相同名称、相同类型的 DNS 记录的集合。A record set (also known as a resource record set) is the collection of DNS records in a zone that have the same name and are of the same type. 大多数记录集包含单个记录。Most record sets contain a single record. 但是,上面所示的示例一个记录集包含多个记录,这并不少见。However, examples like the one above, in which a record set contains more than one record, are not uncommon.

例如,假设已在区域“contoso.com”中创建 A 记录“www”,指向 IP 地址“134.170.185.46”(上述第一条记录)。For example, suppose you have already created an A record 'www' in the zone 'contoso.com', pointing to the IP address '134.170.185.46' (the first record above). 要创建第二条记录,应将此记录添加到现有记录集而非创建其他记录集。To create the second record you would add that record to the existing record set, rather than create an additional record set.

SOA 和 CNAME 记录类型例外。The SOA and CNAME record types are exceptions. 对于这些类型,DNS 标准不允许多个记录具有相同的名称,因此这些记录集仅可包含单个记录。The DNS standards don't permit multiple records with the same name for these types, therefore these record sets can only contain a single record.

有关 Azure DNS 中的 DNS 记录的详细信息,请参阅 DNS 区域和记录For more information about DNS records in Azure DNS, see DNS zones and records.

创建新的 DNS 记录Create a new DNS record

如果新记录与现有记录具有相同的名称和类型,则需将其添加到现有记录集If your new record has the same name and type as an existing record, you need to add it to the existing record set. 如果新记录与所有现有记录的名称和类型都不同,则需创建新的记录集。If your new record has a different name and type to all existing records, you need to create a new record set.

在新的记录集中创建“A”记录Create 'A' records in a new record set

可以使用 New-AzDnsRecordSet cmdlet 创建记录集。You create record sets by using the New-AzDnsRecordSet cmdlet. 创建记录集时,需指定记录集名称、区域、生存时间 (TTL)、记录类型,以及要创建的记录。When creating a record set, you need to specify the record set name, the zone, the time to live (TTL), the record type, and the records to be created.

添加记录到记录集的参数会因记录集的类型而有所变化。The parameters for adding records to a record set vary depending on the type of the record set. 例如,在使用类型“A”记录集时,需使用参数 -IPv4Address 指定 IP 地址。For example, when using a record set of type 'A', you need to specify the IP address using the parameter -IPv4Address. 其他参数用于其他记录类型。Other parameters are used for other record types. 有关详细信息,请参阅其他记录类型示例。See Additional record type examples for details.

下面的示例在 DNS 区域“contoso.com”中创建具有相对名称“www”的记录集。The following example creates a record set with the relative name 'www' in the DNS Zone 'contoso.com'. 记录集的完全限定名称为“www.contoso.com”。The fully-qualified name of the record set is 'www.contoso.com'. 记录类型为“A”,TTL 为 3600 秒。The record type is 'A', and the TTL is 3600 seconds. 记录集包含单个记录,IP 地址为“1.2.3.4”。The record set contains a single record, with IP address '1.2.3.4'.

New-AzDnsRecordSet -Name "www" -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "1.2.3.4") 

若要在区域的“顶点”(在此例中为“contoso.com”)创建记录集,请使用记录集名称“@”(不包括引号):To create a record set at the 'apex' of a zone (in this case, 'contoso.com'), use the record set name '@' (excluding quotation marks):

New-AzDnsRecordSet -Name "@" -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "1.2.3.4") 

如需创建包含多条记录的记录集,请先创建本地数组并添加记录,然后将数组传递到 New-AzDnsRecordSet,如下所示:If you need to create a record set containing more than one record, first create a local array and add the records, then pass the array to New-AzDnsRecordSet as follows:

$aRecords = @()
$aRecords += New-AzDnsRecordConfig -IPv4Address "1.2.3.4"
$aRecords += New-AzDnsRecordConfig -IPv4Address "2.3.4.5"
New-AzDnsRecordSet -Name www –ZoneName "contoso.com" -ResourceGroupName MyResourceGroup -Ttl 3600 -RecordType A -DnsRecords $aRecords

可以使用记录集元数据,以键-值对的形式将特定于应用程序的数据与每个记录集相关联。Record set metadata can be used to associate application-specific data with each record set, as key-value pairs. 以下示例说明如何使用“dept=finance”和“environment=production”这两个元数据条目创建记录集。The following example shows how to create a record set with two metadata entries, 'dept=finance' and 'environment=production'.

New-AzDnsRecordSet -Name "www" -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "1.2.3.4") -Metadata @{ dept="finance"; environment="production" } 

Azure DNS 还支持“空”记录集,此类记录集可充当占位符,用于在创建 DNS 记录之前保留某个 DNS 名称。Azure DNS also supports 'empty' record sets, which can act as a placeholder to reserve a DNS name before creating DNS records. 空记录集在 Azure DNS 控制平面可见,但也会显示在 Azure DNS 名称服务器上。Empty record sets are visible in the Azure DNS control plane, but do appear on the Azure DNS name servers. 以下示例创建一个空记录集:The following example creates an empty record set:

New-AzDnsRecordSet -Name "www" -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords @()

创建其他类型的记录Create records of other types

详细了解如何创建“A”记录以后,还可通过以下示例了解如何创建 Azure DNS 支持的其他记录类型的记录。Having seen in detail how to create 'A' records, the following examples show how to create records of other record types supported by Azure DNS.

每个示例中都演示了如何创建包含单条记录的记录集。In each case, we show how to create a record set containing a single record. 可以对“A”记录此前的示例进行修改,以便使用元数据创建其他类型的包含多个记录的记录集,或者创建空记录集。The earlier examples for 'A' records can be adapted to create record sets of other types containing multiple records, with metadata, or to create empty record sets.

我们没有提供创建 SOA 记录集的示例,因为 SOA 是随每个 DNS 区域一起创建和删除的,不能单独创建或删除。We do not give an example to create an SOA record set, since SOAs are created and deleted with each DNS zone and cannot be created or deleted separately. 但是,可以修改 SOA,如后面的示例所示However, the SOA can be modified, as shown in a later example.

创建一个包含一条记录的 AAAA 记录集Create an AAAA record set with a single record

New-AzDnsRecordSet -Name "test-aaaa" -RecordType AAAA -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Ipv6Address "2607:f8b0:4009:1803::1005") 

创建一个包含一条记录的 CAA 记录集Create a CAA record set with a single record

New-AzDnsRecordSet -Name "test-caa" -RecordType CAA -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Caaflags 0 -CaaTag "issue" -CaaValue "ca1.contoso.com") 

创建一个包含一条记录的 CNAME 记录集Create a CNAME record set with a single record

备注

DNS 标准不允许在区域的顶点创建 CNAME 记录 (-Name '@'),也不允许记录集包含多个记录。The DNS standards do not permit CNAME records at the apex of a zone (-Name '@'), nor do they permit record sets containing more than one record.

有关详细信息,请参阅 CNAME 记录For more information, see CNAME records.

New-AzDnsRecordSet -Name "test-cname" -RecordType CNAME -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Cname "www.contoso.com") 

创建一个包含一条记录的 MX 记录集Create an MX record set with a single record

在此示例中,使用记录集名称“@”在区域顶端(在本例中为“contoso.com”)创建一条 MX 记录。In this example, we use the record set name '@' to create an MX record at the zone apex (in this case, 'contoso.com').

New-AzDnsRecordSet -Name "@" -RecordType MX -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Exchange "mail.contoso.com" -Preference 5) 

创建一个包含一条记录的 NS 记录集Create an NS record set with a single record

New-AzDnsRecordSet -Name "test-ns" -RecordType NS -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Nsdname "ns1.contoso.com") 

创建一个包含一条记录的 PTR 记录集Create a PTR record set with a single record

在此示例中,“my-arpa-zone.com”表示代表用户 IP 范围的 ARPA 反向查找区域。In this case, 'my-arpa-zone.com' represents the ARPA reverse lookup zone representing your IP range. 此区域中的每个 PTR 记录集对应于此 IP 范围内的一个 IP 地址。Each PTR record set in this zone corresponds to an IP address within this IP range. 记录名称“10”是此 IP 范围内由此记录表示的 IP 地址的最后一个八位字节。The record name '10' is the last octet of the IP address within this IP range represented by this record.

New-AzDnsRecordSet -Name 10 -RecordType PTR -ZoneName "my-arpa-zone.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Ptrdname "myservice.contoso.com") 

创建一个包含一条记录的 SRV 记录集Create an SRV record set with a single record

创建 SRV 记录集时,请在记录集名称中指定 _service_protocolWhen creating an SRV record set, specify the _service and _protocol in the record set name. 在区域顶点创建 SRV 记录集时,无需在记录集名称中包括“@”。There is no need to include '@' in the record set name when creating an SRV record set at the zone apex.

New-AzDnsRecordSet -Name "_sip._tls" -RecordType SRV -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Priority 0 -Weight 5 -Port 8080 -Target "sip.contoso.com") 

创建包含一条记录的 TXT 记录集Create a TXT record set with a single record

以下示例说明如何创建 TXT 记录。The following example shows how to create a TXT record. 如需详细了解 TXT 记录中支持的最大字符串长度,请参阅 TXT 记录For more information about the maximum string length supported in TXT records, see TXT records.

New-AzDnsRecordSet -Name "test-txt" -RecordType TXT -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Value "This is a TXT record") 

获取记录集Get a record set

若要检索现有的记录集,请使用 Get-AzDnsRecordSetTo retrieve an existing record set, use Get-AzDnsRecordSet. 此 cmdlet 返回一个本地对象,该对象表示 Azure DNS 中的记录集。This cmdlet returns a local object that represents the record set in Azure DNS.

对于 New-AzDnsRecordSet,给定的记录集名称必须是相对 名称,这意味着它必须排除区域名称。As with New-AzDnsRecordSet, the record set name given must be a relative name, meaning it must exclude the zone name. 还需指定记录类型,以及包含记录集的区域。You also need to specify the record type, and the zone containing the record set.

以下示例说明如何检索记录集。The following example shows how to retrieve a record set. 在此示例中,区域使用 -ZoneName-ResourceGroupName 参数指定。In this example, the zone is specified using the -ZoneName and -ResourceGroupName parameters.

$rs = Get-AzDnsRecordSet -Name "www" -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"

此外,也可以使用通过 -Zone 参数传递的区域对象指定区域。Alternatively, you can also specify the zone using a zone object, passed using the -Zone parameter.

$zone = Get-AzDnsZone -Name "contoso.com" -ResourceGroupName "MyResourceGroup"
$rs = Get-AzDnsRecordSet -Name "www" -RecordType A -Zone $zone

列出记录集List record sets

也可以使用 Get-AzDnsZone 列出区域中的记录集,省略 -Name 和/或 -RecordType 参数。You can also use Get-AzDnsZone to list record sets in a zone, by omitting the -Name and/or -RecordType parameters.

以下示例返回区域中的所有记录集:The following example returns all record sets in the zone:

$recordsets = Get-AzDnsRecordSet -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"

以下示例说明如何在指定记录类型的同时省略记录集名称,以便检索给定类型的所有记录集:The following example shows how all record sets of a given type can be retrieved by specifying the record type while omitting the record set name:

$recordsets = Get-AzDnsRecordSet -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"

要跨记录类型检索具有给定名称的所有记录集,需先检索所有记录集,然后对结果进行筛选:To retrieve all record sets with a given name, across record types, you need to retrieve all record sets and then filter the results:

$recordsets = Get-AzDnsRecordSet -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" | where {$_.Name.Equals("www")}

在上述所有示例中,区域都可以通过 -ZoneName-ResourceGroupName 参数指定(如下所示),或者通过指定区域对象进行指定:In all the above examples, the zone can be specified either by using the -ZoneName and -ResourceGroupNameparameters (as shown), or by specifying a zone object:

$zone = Get-AzDnsZone -Name "contoso.com" -ResourceGroupName "MyResourceGroup"
$recordsets = Get-AzDnsRecordSet -Zone $zone

将记录添加到现有记录集Add a record to an existing record set

要将记录添加到现有记录集,请执行以下三个步骤:To add a record to an existing record set, follow the following three steps:

  1. 获取现有记录集Get the existing record set

    $rs = Get-AzDnsRecordSet -Name www –ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -RecordType A
    
  2. 将新记录添加到本地记录集。Add the new record to the local record set. 这是一种脱机操作。This is an off-line operation.

    Add-AzDnsRecordConfig -RecordSet $rs -Ipv4Address "5.6.7.8"
    
  3. 将更改提交回 Azure DNS 服务。Commit the change back to the Azure DNS service.

    Set-AzDnsRecordSet -RecordSet $rs
    

使用 Set-AzDnsRecordSet 可将 Azure DNS 中的现有记录集(及其包含的所有记录)替换为指定的记录集 。Using Set-AzDnsRecordSet replaces the existing record set in Azure DNS (and all records it contains) with the record set specified. 使用 Etag 检查可确保不覆盖并发更改。Etag checks are used to ensure concurrent changes are not overwritten. 可以使用可选的 -Overwrite 开关取消这些检查。You can use the optional -Overwrite switch to suppress these checks.

此操作序列也可通过管道传递,即通过管道传递记录集对象,而不是将其作为参数传递:This sequence of operations can also be piped, meaning you pass the record set object by using the pipe rather than passing it as a parameter:

Get-AzDnsRecordSet -Name "www" –ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -RecordType A | Add-AzDnsRecordConfig -Ipv4Address "5.6.7.8" | Set-AzDnsRecordSet

上述示例说明了如何将“A”记录添加到现有的类型“A”记录集。The examples above show how to add an 'A' record to an existing record set of type 'A'. 可以使用类似操作顺序向其他类型的记录集添加记录,将 Add-AzDnsRecordConfig-Ipv4Address 参数替换为特定于每个记录类型的其他参数。A similar sequence of operations is used to add records to record sets of other types, substituting the -Ipv4Address parameter of Add-AzDnsRecordConfig with other parameters specific to each record type. 每个记录类型的参数与 New-AzDnsRecordConfig cmdlet 的参数相同,如上面的其他记录类型示例所示。The parameters for each record type are the same as for the New-AzDnsRecordConfig cmdlet, as shown in Additional record type examples above.

类型为“CNAME”或“SOA”的记录集不能包含多个记录。Record sets of type 'CNAME' or 'SOA' cannot contain more than one record. 此约束源自 DNS 标准,This constraint arises from the DNS standards. 不是 Azure DNS 的限制。It is not a limitation of Azure DNS.

从现有记录集中删除记录Remove a record from an existing record set

从记录集删除记录的过程类似于向现有记录集添加记录的过程:The process to remove a record from a record set is similar to the process to add a record to an existing record set:

  1. 获取现有记录集Get the existing record set

    $rs = Get-AzDnsRecordSet -Name www –ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -RecordType A
    
  2. 从本地记录集对象删除记录。Remove the record from the local record set object. 这是一种脱机操作。This is an off-line operation. 要删除的记录必须与所有参数中的现有记录完全匹配。The record that's being removed must be an exact match with an existing record across all parameters.

    Remove-AzDnsRecordConfig -RecordSet $rs -Ipv4Address "5.6.7.8"
    
  3. 将更改提交回 Azure DNS 服务。Commit the change back to the Azure DNS service. 对于并发更改,使用可选的 -Overwrite 开关取消 Etag 检查Use the optional -Overwrite switch to suppress Etag checks for concurrent changes.

    Set-AzDnsRecordSet -RecordSet $Rs
    

按以上顺序从某个记录集中删除最后一条记录不会删除该记录集,而是留下一个空的记录集。Using the above sequence to remove the last record from a record set does not delete the record set, rather it leaves an empty record set. 若要彻底删除记录集,请参阅删除记录集To remove a record set entirely, see Delete a record set.

与添加记录到记录集类似,也可通过管道传递删除记录集的操作顺序:Similarly to adding records to a record set, the sequence of operations to remove a record set can also be piped:

Get-AzDnsRecordSet -Name www –ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -RecordType A | Remove-AzDnsRecordConfig -Ipv4Address "5.6.7.8" | Set-AzDnsRecordSet

将适当的特定于类型的参数传递给 Remove-AzDnsRecordSet 即可支持不同的记录类型。Different record types are supported by passing the appropriate type-specific parameters to Remove-AzDnsRecordSet. 每个记录类型的参数与 New-AzDnsRecordConfig cmdlet 的参数相同,如上面的其他记录类型示例所示。The parameters for each record type are the same as for the New-AzDnsRecordConfig cmdlet, as shown in Additional record type examples above.

修改现有记录集Modify an existing record set

修改现有记录集的步骤类似于通过记录集添加或删除记录时所采取的步骤:The steps for modifying an existing record set are similar to the steps you take when adding or removing records from a record set:

  1. 使用 Get-AzDnsRecordSet 检索现有记录集。Retrieve the existing record set by using Get-AzDnsRecordSet.
  2. 通过以下方式修改本地记录集对象:Modify the local record set object by:
    • 添加或删除记录Adding or removing records
    • 更改现有记录的参数Changing the parameters of existing records
    • 更改记录集元数据和生存时间 (TTL)Changing the record set metadata and time to live (TTL)
  3. 使用 Set-AzDnsRecordSet cmdlet 提交更改。Commit your changes by using the Set-AzDnsRecordSet cmdlet. 这样会将 Azure DNS 中的现有记录集替换 为指定的记录集。This replaces the existing record set in Azure DNS with the record set specified.

使用 Set-AzDnsRecordSet 时,可通过 Etag 检查确保不覆盖并发更改。When using Set-AzDnsRecordSet, Etag checks are used to ensure concurrent changes are not overwritten. 可以使用可选的 -Overwrite 开关取消这些检查。You can use the optional -Overwrite switch to suppress these checks.

更新现有记录集中的记录To update a record in an existing record set

在此示例中,我们更改现有“A”记录的 IP 地址:In this example, we change the IP address of an existing 'A' record:

$rs = Get-AzDnsRecordSet -name "www" -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"
$rs.Records[0].Ipv4Address = "9.8.7.6"
Set-AzDnsRecordSet -RecordSet $rs

修改 SOA 记录To modify an SOA record

不能在区域顶点从自动创建的 SOA 记录集(-Name "@",包括引号)添加或删除记录。You cannot add or remove records from the automatically created SOA record set at the zone apex (-Name "@", including quote marks). 但是,可以修改 SOA 记录和记录集 TTL 中的任何参数(“Host”除外)。However, you can modify any of the parameters within the SOA record (except "Host") and the record set TTL.

下面的示例演示如何更改 SOA 记录的 Email 属性:The following example shows how to change the Email property of the SOA record:

$rs = Get-AzDnsRecordSet -Name "@" -RecordType SOA -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"
$rs.Records[0].Email = "admin.contoso.com"
Set-AzDnsRecordSet -RecordSet $rs

修改区域顶点处的 NS 记录To modify NS records at the zone apex

在每个 DNS 区域自动创建区域顶点处的 NS 记录集。The NS record set at the zone apex is automatically created with each DNS zone. 其中包含分配给该区域的 Azure DNS 名称服务器名称。It contains the names of the Azure DNS name servers assigned to the zone.

可向此 NS 记录集添加其他名称服务器,从而支持与多个 DNS 提供商共同托管域。You can add additional name servers to this NS record set, to support co-hosting domains with more than one DNS provider. 还可修改此记录集的 TTL 和元数据。You can also modify the TTL and metadata for this record set. 但是,无法删除或修改预填充的 Azure DNS 名称服务器。However, you cannot remove or modify the pre-populated Azure DNS name servers.

请注意,这仅适用于区域顶点处的 NS 记录集。Note that this applies only to the NS record set at the zone apex. 区域中的其他 NS 记录集(用于委派子区域)不受约束,可进行修改。Other NS record sets in your zone (as used to delegate child zones) can be modified without constraint.

以下示例展示如何向区域顶点处的 NS 记录集添加其他名称服务器:The following example shows how to add an additional name server to the NS record set at the zone apex:

$rs = Get-AzDnsRecordSet -Name "@" -RecordType NS -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"
Add-AzDnsRecordConfig -RecordSet $rs -Nsdname ns1.myotherdnsprovider.cn
Set-AzDnsRecordSet -RecordSet $rs

修改记录集元数据To modify record set metadata

可以使用记录集元数据,以键-值对的形式将特定于应用程序的数据与每个记录集相关联。Record set metadata can be used to associate application-specific data with each record set, as key-value pairs.

以下示例说明如何修改现有记录集的元数据:The following example shows how to modify the metadata of an existing record set:

# Get the record set
$rs = Get-AzDnsRecordSet -Name www -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"

# Add 'dept=finance' name-value pair
$rs.Metadata.Add('dept', 'finance') 

# Remove metadata item named 'environment'
$rs.Metadata.Remove('environment')  

# Commit changes
Set-AzDnsRecordSet -RecordSet $rs

删除记录集Delete a record set

可以通过使用 Remove-AzDnsRecordSet cmdlet 删除记录集。Record sets can be deleted by using the Remove-AzDnsRecordSet cmdlet. 删除记录集也会删除记录集内的所有记录。Deleting a record set also deletes all records within the record set.

备注

无法删除区域顶点的 SOA 和 NS 记录集 (-Name '@')。You cannot delete the SOA and NS record sets at the zone apex (-Name '@'). Azure DNS 在区域创建时自动创建这些记录集,并在区域被删除时自动将其删除。Azure DNS created these automatically when the zone was created, and deletes them automatically when the zone is deleted.

以下示例说明如何删除记录集。The following example shows how to delete a record set. 在此示例中,记录集名称、记录集类型、区域名称和资源组都进行了显式指定。In this example, the record set name, record set type, zone name, and resource group are each specified explicitly.

Remove-AzDnsRecordSet -Name "www" -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"

此外,也可通过名称和类型指定记录集,通过对象指定区域:Alternatively, the record set can be specified by name and type, and the zone specified using an object:

$zone = Get-AzDnsZone -Name "contoso.com" -ResourceGroupName "MyResourceGroup"
Remove-AzDnsRecordSet -Name "www" -RecordType A -Zone $zone

第三个选项是通过记录集对象指定记录集本身:As a third option, the record set itself can be specified using a record set object:

$rs = Get-AzDnsRecordSet -Name www -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup"
Remove-AzDnsRecordSet -RecordSet $rs

使用记录集对象指定要删除的记录集时,可以通过 Etag 检查确保不删除并发更改。When you specify the record set to be deleted by using a record set object, Etag checks are used to ensure concurrent changes are not deleted. 可以使用可选的 -Overwrite 开关取消这些检查。You can use the optional -Overwrite switch to suppress these checks.

记录集对象也可以通过管道输送,而不是作为参数传递:The record set object can also be piped instead of being passed as a parameter:

Get-AzDnsRecordSet -Name www -RecordType A -ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" | Remove-AzDnsRecordSet

确认提示Confirmation prompts

New-AzDnsRecordSetSet-AzDnsRecordSetRemove-AzDnsRecordSet cmdlet 都支持确认提示。The New-AzDnsRecordSet, Set-AzDnsRecordSet, and Remove-AzDnsRecordSet cmdlets all support confirmation prompts.

如果 $ConfirmPreference PowerShell 首选项变量的值为 Medium 或更低,则每个 cmdlet 都会提示用户进行确认。Each cmdlet prompts for confirmation if the $ConfirmPreference PowerShell preference variable has a value of Medium or lower. 由于 $ConfirmPreference 的默认值为 High,因此在使用默认的 PowerShell 设置时不会发出这些提示。Since the default value for $ConfirmPreference is High, these prompts are not given when using the default PowerShell settings.

可以使用 -Confirm 参数重写当前的 $ConfirmPreference 设置。You can override the current $ConfirmPreference setting using the -Confirm parameter. 如果指定 -Confirm-Confirm:$True,cmdlet 会在运行之前提示用户进行确认。If you specify -Confirm or -Confirm:$True , the cmdlet prompts you for confirmation before it runs. 如果指定 -Confirm:$False,cmdlet 不会提示用户进行确认。If you specify -Confirm:$False , the cmdlet does not prompt you for confirmation.

有关 -Confirm$ConfirmPreference 的详细信息,请参阅 About Preference Variables(关于首选项变量)。For more information about -Confirm and $ConfirmPreference, see About Preference Variables.

后续步骤Next steps

详细了解 Azure DNS 中的区域和记录Learn more about zones and records in Azure DNS.
了解如何在使用 Azure DNS 时保护区域和记录Learn how to protect your zones and records when using Azure DNS.
查看 Azure DNS PowerShell 参考文档Review the Azure DNS PowerShell reference documentation.