One of the new Azure services announced at Ignite was Azure DNS. A globally replicated and highly available DNS service leveraging Anycast for fast DNS responses from anywhere around the globe. Wow. Since it’s using well known management tools (Powershell) and integration interfaces (REST and C#) Azure DNS is really easy to build upon and maximize on the investment.
The only thing I’m missing (for obvious reasons) is the ability to register and manage domains at a registrar level. Hopefully a <insert domain registrar name here> Resource Provider is only a matter of time.
I’m very excited about this since I am wasting was wasting a boatload of money on two A0 VMs in an availability set hosting DNS. Since I had a small boat it only fit about $30/month.. 😉
With Azure DNS I’m only paying $0.25 per zone and $0.20 per 1 billion queries. So I basically cut my DNS cost by 99% and reduced my management cost by about the same amount.
Gettings started with Azure DNS
To sign up for Azure DNS, which is currently in preview, you’ll have to use Powershell. Be sure you have at least version 0.9.1 installed. Even tho DNS Cmdlets have been hiding since November 26th, 2014.
You easily can download and install the latest version with the help of this post.
Add-AzureAccount Switch-AzureMode -Name AzureResourceManager # Had to re-register the Microsoft.Network provider for the DNS feature to ever become Registered Register-AzureProvider -ProviderNamespace Microsoft.Network Register-AzureProviderFeature -ProviderNamespace Microsoft.Network -FeatureName azurednspreview
Wait until RegistrationState turns into Registered. It should happen almost instantly.
Get-AzureProviderFeature -ProviderNamespace Microsoft.Network -FeatureName azurednspreview | fl * FeatureName : azurednspreview ProviderName : Microsoft.Network RegistrationState : Registered
Next we’ll create our first DNS Zone. All zones must be placed inside a Resource Group.
New-AzureResourceGroup -Name WE-DMZ-DNS -Location westeurope New-AzureDnsZone -Name runbookautomation.se -ResourceGroupName WE-DMZ-DNS # Get DNS zone name server (Get-AzureDnsRecordSet -ZoneName runbookautomation.se -ResourceGroupName WE-DMZ-DNS -Name '@' -RecordType NS).Records
Next up is the slow and tricky part. The last row in the previous snippet expands the name servers of your newly created zone. These name servers need to be configured at your domain registrar.
This is how it looked like at my registrar:
Once the DNS changes have replicated and Resolve-DnsName returns something like this you are good to go. The key property here is PrimaryServer.
Lastly we’ll create a CNAME record:
# Get the target Zone $Zone = Get-AzureDnsZone -Name runbookautomation.se -ResourceGroupName WE-DMZ-DNS # Create the DNS Record Set $RecordSet = New-AzureDnsRecordSet -Name blog -RecordType CNAME -Ttl 3600 -Zone $Zone # Add the CNAME value to the DNS Record Set Add-AzureDnsRecordConfig -RecordSet $RecordSet -Cname blog-runbookautomation-se.azurewebsites.net # Apply changes to Record Set in Azure Set-AzureDnsRecordSet -RecordSet $RecordSet
Below is the complete code using variables for easier use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ZoneName = "" | |
$ResourceGroupName = "" | |
$AzureLocation = "westeurope" | |
$CnameKey = "blog" | |
$CnameValue = ".azurewebsites.net" | |
# Add Azure Account | |
Add-AzureAccount | |
# Switch to ARM mode | |
Switch-AzureMode -Name AzureResourceManager | |
# Had to re-register the Microsoft.Network provider for the DNS feature to ever become Registered | |
Register-AzureProvider -ProviderNamespace Microsoft.Network | |
# Register for Azure DNS preview | |
Register-AzureProviderFeature -ProviderNamespace Microsoft.Network -FeatureName azurednspreview | |
# Check providerFeature registration status. Wait until registrationStatus=Registered | |
Get-AzureProviderFeature -ProviderNamespace Microsoft.Network -FeatureName azurednspreview | |
# Create Resource Group for DNS resources | |
$ResourceGroup = New-AzureResourceGroup -Name $ResourceGroupName -Location $AzureLocation | |
# Create DNS Zone | |
$Zone = New-AzureDnsZone -Name $ZoneName -ResourceGroupName $ResourceGroup.ResourceGroupName | |
# Get DNS zone name server | |
(Get-AzureDnsRecordSet -ZoneName $Zone.Name -ResourceGroupName $ResourceGroup.ResourceGroupName -Name '@' -RecordType NS).Records | |
# Check if name server settings has replicated. Property PrimaryServer. | |
Resolve-DnsName $ZoneName | |
# Create the DNS Record Set | |
$RecordSet = New-AzureDnsRecordSet -Name $CnameKey -RecordType CNAME -Ttl 3600 -Zone $Zone | |
# Add the CNAME value to the DNS Record Set | |
Add-AzureDnsRecordConfig -RecordSet $RecordSet -Cname $CnameValue | |
# Apply changes to Record Set in Azure | |
Set-AzureDnsRecordSet -RecordSet $RecordSet |