Switching name servers, to Azure DNS with Office 365

I finally took the time, and moved my domain to Azure DNS. I have my website hosted in Azure, and I’m also using Office 365, so I had a few records I need to move. Luckily, we have PowerShell 🙂

First we need to understand what we’re working with. In Azure DNS we have DNS zones, DNS records and record sets. The DNS zone is your domain, in this case “cloudpuzzles.net” and is managed by PowerShell *AzureDnsZone* PowerShell cmdlets. DNS records contains the data, like IP address, Exhange and so on. They’re managed using *AzureDnsRecordConfig* cmdlets. Record sets contains all records for a given name and type, for example a website hosted on multiple public IP’s would need all those IP’s under the same record set. It could be “www.cloudpuzzles.net” needed to point to both 94.245.104.73 and 94.245.104.74, and so they would need to be within the same record set. Record sets are also used if you only have a single record for the given name and type. Record sets are managed using *AzureDnsRecordSet* cmdlets.

Let’s dive in. I started out by creating the DNS zone, in an existing resource group:

[powershell]
$zone = New-AzureDnsZone -Name cloudpuzzles.net -ResourceGroupName cloudpuzzles
[/powershell]

For my website I needed 2 records: 1 for cloudpuzzles.net and 1 for http://www.cloudpuzzles.net. They were easily created with these commands:

[powershell]
$rs = New-AzureDnsRecordSet -Name "@" -RecordType A -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Ipv4Address 94.245.104.73
Set-AzureDnsRecordSet -RecordSet $rs

$rs = New-AzureDnsRecordSet -Name "www" -RecordType A -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Ipv4Address 94.245.104.73
Set-AzureDnsRecordSet -RecordSet $rs
[/powershell]

What this does is:

  1. Create a new record set with the name of the record (@ points to the domain, cloudpuzzles.net, so people don’t have to write www.), the type (A), TTL (3600) and the zone ($zone which we created before)
  2. Adds a value to the record set, in this case an IPv4 address
  3. Commits the record set to Azure

After this, I added a bunch of CNAME records for Office 365:

[powershell]
$rs = New-AzureDnsRecordSet -Name "sip" -RecordType CNAME -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Cname "sipdir.online.lync.com"
Set-AzureDnsRecordSet -RecordSet $rs

$rs = New-AzureDnsRecordSet -Name "autodiscover" -RecordType CNAME -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Cname "autodiscover.outlook.com"
Set-AzureDnsRecordSet -RecordSet $rs

$rs = New-AzureDnsRecordSet -Name "lyncdiscover" -RecordType CNAME -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Cname "webdir.online.lync.com"
Set-AzureDnsRecordSet -RecordSet $rs

$rs = New-AzureDnsRecordSet -Name "msoid" -RecordType CNAME -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Cname "clientconfig.microsoftonline-p.net"
Set-AzureDnsRecordSet -RecordSet $rs

$rs = New-AzureDnsRecordSet -Name "enterpriseregistration" -RecordType CNAME -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Cname "enterpriseregistration.windows.net"
Set-AzureDnsRecordSet -RecordSet $rs

$rs = New-AzureDnsRecordSet -Name "enterpriseenrollment" -RecordType CNAME -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Cname "enterpriseenrollment.manage.microsoft.com"
Set-AzureDnsRecordSet -RecordSet $rs
[/powershell]

And 2 SRV records for Lync Skype for Business:

[powershell]
$rs = New-AzureDnsRecordSet -Name "_sip._tls" -RecordType SRV -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs –Priority 100 –Weight 1 –Port 443 –Target "sipdir.online.lync.com"
Set-AzureDnsRecordSet -RecordSet $rs

$rs = New-AzureDnsRecordSet -Name "_sipfederationtls._tcp" -RecordType SRV -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs –Priority 100 –Weight 1 –Port 5061 –Target "sipfed.online.lync.com"
Set-AzureDnsRecordSet -RecordSet $rs
[/powershell]

We also need an MX record for email:

[powershell]
$rs = New-AzureDnsRecordSet -Name "@" -RecordType MX -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Exchange cloudpuzzles-net.mail.eo.outlook.com -Preference 5
Set-AzureDnsRecordSet -RecordSet $rs
[/powershell]

And last, a TXT record to prevent spam:

[powershell]
$rs = New-AzureDnsRecordSet -Name "@" -RecordType TXT -Zone $zone -Ttl 3600
Add-AzureDnsRecordConfig -RecordSet $rs -Value "v=spf1 include:spf.protection.outlook.com -all"
Set-AzureDnsRecordSet -RecordSet $rs
[/powershell]

The full configuration can be found at GitHub.

If you want to list all record sets, you can use this command:

[powershell]
Get-AzureDnsRecordSet -ResourceGroupName cloudpuzzles -ZoneName cloudpuzzles.net | ft
[/powershell]

I prefer to format as table, gives a better overview in my opinion.

2 comments

  1. Does Azure DNS allow multiple MX records with different weights which are processed correctly? (not every DNS host does that right!)

    Like

    1. I haven’t tested it, but it should be possible. You can specify the weight using by using the -Preference parameter.

      /Jesper

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s