Monthly Archives: May 2015

What is Azure DNS? And how do I get started?

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:
binerodns

Once the DNS changes have replicated and Resolve-DnsName returns something like this you are good to go. The key property here is PrimaryServer.
resolvedns

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.


$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

Update Azure Powershell module with Powershell

A couple of months ago I shared a script that downloaded and installed the latest version of the Azure Powershell module. Since that time a lot of things have changed.

The module has moved from azure-sdk-tools to azure-powershell on GitHub!
The module has been updated from version 0.8.6 to version 0.9.1 with the help of over 3000 commits!
The module has gone from 434 cmdlets up to 761 cmdlets!

Below is a new snippet that leverages the GitHub API to download and install the latest Azure Powershell module:


# Get latest azure-powershell
$AzureModule = Get-Module -Name Azure* -ListAvailable
$LatestRelease = Invoke-RestMethod -Uri https://api.github.com/repos/Azure/azure-powershell/releases/latest -Method GET
If (-not($AzureModule) -or $AzureModule.Version.ToString() -ne $LatestRelease.name)
{
$Asset = $LatestRelease.assets | Where-Object {$_.name -like "*.msi"}
$OutFile = "{0}\{1}" -f $env:TEMP, $Asset.name
Invoke-WebRequest -Uri $Asset.browser_download_url -OutFile $Outfile -Method Get
Start-Process -FilePath msiexec.exe -ArgumentList @("/i $OutFile /qb") -Wait -PassThru
}
else
{
Write-Host "Azure Powershell module is up to date."
}

Download and invoke the script to update. Or just run this one-liner:


iex (Invoke-RestMethod -Uri https://api.github.com/gists/dfe515f4ef0b14e6be15).files.'Update-AzurePowershell.ps1'.content