1
votes

I'm migrating all my DNS services to Azure DNS. Using Powershell I've managed to successfully create the CNAME record to get www.something.com to resolve to an Azure website-

$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

But how to I create CNAME records for wildcard and naked addresses like

*.something.com or something.com

I'm assuming it's something (no pun intended) to do with

New-AzureRmDnsRecordSet -Name "www"

But through all the documentation and Internet examples I can't seem to find the right verbiage.

2

2 Answers

1
votes

The problem you're having is an issue with the rules of DNS, which forbid a CNAME record where another record exists. The naked address (or Apex) example.com already has two records (the SOA and NS) so a CNAME is not allowed.

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.

In order to create an Apex record, i.e. example.com you need to use an A record, which means it needs to point to the IP of your Azure website. Once you have that you can then create a CNAME from www to example.com. (this is the supported method - your IP Address for Azure websites is static)

the command you are looking for, would be something like

$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

then

$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

This will create your zone apex record and point the www cname to it making example.com and www.example.com point to the same place.

For a Wildcard you replace the Apex "@" with an asterix "*" so something like

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

As the previous answer stated, you can't create a CNAME at the zone apex (name = "@"). This is because of the RFC constraints, and the correct approach is to use other record types e.g. A records at the zone apex instead, as the previous respondent explained.

However, you can create a wildcard CNAME at the zone apex. Since wildcards do not match against empty strings in DNS, they do not fall foul of the RFC constraints. For example, in PowerShell:

$z = New-AzureRmDnsZone -Name myzone.com -ResourceGroupName MyResourceGroup
$rs = New-AzureRmDnsRecordSet -Name "*" -Zone $z -Ttl 3600 -RecordType CNAME
Add-AzureRmDnsRecordConfig -RecordSet $rs -Cname cnametarget.com
Set-AzureRmDnsRecordSet -RecordSet $rs

This will resolve for queries to e.g. foo.myzone.com but not for myzone.com.

Wikipedia has a good page to learn more about wildcard DNS.