Step-By-Step: Enabling Custom Domain Names in Azure via PowerShell

Simplicity of domain name assignment are sometimes just as important as the content the site showcases. When creating a site on Azure however, the site is assigned as a subdomain of cloudapp.net. The result is said site having a URL such as yoursite.cloudapp.net instead of yoursite.com.  This post will help address this by detailing steps on how to add a CNAME and A record for a custom domain.

Prerequisite: Install Azure PowerShell

Steps to Install Azure PowerShell have been detailed here: https://blogs.technet.microsoft.com/canitpro/2015/04/15/step-by-step-installing-and-configuring-azure-powershell/

Step 1: Adding the CNAME record

A new entry in the DNS table needs to be created to create the CNAME record. Domain registers offer similar tools to complete this. While the concept is the same across registers, do connect with their help desk if a problem occurs.

  1. With Azure PowerShell now installed, run the following command:

     Get-AzureDeployment -ServiceName yourservicename | Select Url
    
  2. Write down the domain name used in the URL as it will be required when creating a CNAME record

  3. Access the DNS registrar's website you utilize and navigate to the page that manages DNS

  4. Look for the section that allows you to access CNAME, Subdomains or Alias and locate where you can select or enter a CNAME

  5. The domain or subdomain alias needs to be provided for the CNAME (such as www), if the intent is to create an alias for www.yourdomain.com

Step 2: Adding an A record

We first have to locate the Virtual IP in order to create an A record. Only then can one add a new entry in the DNS table. Again, each Domain register offer similar tools to complete this. While the concept is the same across registers, do connect with their help desk if a problem occurs.

  1. Run the following via Azure PowerShell:

     get-azurevm -servicename yourservicename | get-azureendpoint -VM {$_.VM} | select Vip
    
  2. Write down the IP Address listed as it will be required when creating an A record

  3. Access the DNS registrar's website you utilize and navigate to the page that manages DNS

  4. Look for the section that allows you to access A records

  5. Select or enter the domain or subdomain that will use this A record

  6. Enter the IP address recorded in step 2 in the provided field thus associating the A record domain entry with the IP address of said cloud service