powershell - Azure DNS 中的通配符和裸 CNAME 记录

标签 powershell azure dns

我正在将所有 DNS 服务迁移到 Azure DNS。使用 Powershell,我成功创建了 CNAME 记录,以将 www.something.com 解析为 Azure 网站 -

$rs = New-AzureRmDnsRecordSet -Name "www" -RecordType "CNAME" -ZoneName "something.com" -ResourceGroupName "DNSRecords" -Ttl 60 -Overwrite -Force
Add-AzureRmDnsRecordConfig -RecordSet $rs -Cname "MySomethingAzureWebsite.azurewebsites.net"
Set-AzureRmDnsRecordSet -RecordSet $rs -Overwrite

但是如何为通配符和裸地址创建 CNAME 记录,例如

*.something.com 或 something.com

我假设它与(没有双关语)有关

New-AzureRmDnsRecordSet -名称“www”

但是通过所有文档和互联网示例,我似乎找不到正确的措辞。

最佳答案

您遇到的问题是 rules of DNS 的问题,这会禁止存在另一条记录的 CNAME 记录。裸地址(或 Apex)example.com 已经有两条记录(SOA 和 NS),因此不允许使用 CNAME。

If a CNAME RR is present at a node, no other data should be present; this ensures that the data for a canonical name and its aliases cannot be different. This rule also insures that a cached CNAME can be used without checking with an authoritative server for other RR types.

为了创建 Apex 记录,即 example.com,您需要使用 A 记录,这意味着它需要指向您的 Azure 网站的 IP。完成后,您可以创建从 www 到 example.com 的 CNAME。 (这是受支持的方法 - Azure 网站的 IP 地址是静态的)

您正在寻找的命令类似于

$rs = New-AzureRmDnsRecordSet -Name "@" -RecordType A `
       -ZoneName example.com -ResourceGroupName $RG `
       -Ttl $ttl -Force -Overwrite
Add-AzureRmDnsRecordConfig -RecordSet $rs -Ipv4Address $IPAddress
Set-AzureRmDnsRecordSet -RecordSet $rs -Overwrite

然后

$rs = New-AzureRmDnsRecordSet -Name "www" -RecordType "CNAME" `
      -ZoneName "something.com" -ResourceGroupName "DNSRecords" `
      -Ttl 60 -Overwrite -Force
Add-AzureRmDnsRecordConfig -RecordSet $rs -Cname "example.com"
Set-AzureRmDnsRecordSet -RecordSet $rs -Overwrite

这将创建您的区域顶点记录并将 www cname 指向它,使 example.com 和 www.example.com指向同一个地方。

对于通配符,您可以将 Apex“@”替换为星号“*”,例如

$rs = New-AzureRmDnsRecordSet -Name "*" -RecordType A `
       -ZoneName example.com -ResourceGroupName $RG `
       -Ttl $ttl -Force -Overwrite
#You know the rest

关于powershell - Azure DNS 中的通配符和裸 CNAME 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34585964/

相关文章:

python - powershell tts 命令旁白使用 python 更改

powershell - 将文件夹中的每个 .flac 文件转换为 320kbps .mp3,而不丢失元数据

c - 如何配置 c.vim 以便它可以在 Powershell Vim 中编译?

c# - 如何在 Azure Functions 中设置 HTTP 输出

powershell - 使用 powershell 找不到标记的 Azure 资源组

visual-studio - Azure 移动应用程序在现有应用程序中不可用

Heroku 自定义域重写为 herokuapp URL

c# - 显示属于域用户的组

linux - VirtualBox guest 无法解析主机名,但 git 可以

powershell - 如何使用路径和参数的可变值执行exe