Setting up DNS within an Azure Virtual Network

I had the same issue and I believe that I've come up with a reasonable solution which doesn't involve any extra machines and is very little work.

In short, you put your backend and frontend in the same Virtual Network and Subnet so that they are given the same DNS server. Then you configure the DNS Suffix Search List on the frontend services so that they use the DNS suffix of the backend when performing name resolution.

Steps:

  1. Log into one of your backend VMs and execute ipconfig.
  2. From the output, get the value of Connection-specific DNS Suffix

    Output of ipconfig

  3. Set the value of $dnsSuffix to the value from step 2 in the following script.

    $dnsSuffix = 'xxxxxx.yyyyy.uswest.internal.cloudapp.net';
    
    $nics = Get-WmiObject `
      -Class win32_networkadapterconfiguration `
      -Filter 'IPEnabled = true';
    $nics | % {
      $nicSuffixes = $_.DNSDomainSuffixSearchOrder;
      if ($nicSuffixes -notcontains $dnsSuffix) {
        $_.DNSDomainSuffixSearchOrder = $dnsSuffix + $_.DNSDomainSuffixSearchOrder;
      }
    };
    
    Invoke-WmiMethod `
        -Class win32_networkadapterconfiguration `
        -Name setDNSSuffixSearchOrder `
        -ArgumentList @(@($dnsSuffix)),$null;
    
  4. Name that script Set-DnsSuffixSearchList.ps1 and include it in your project, setting the properties on the file to "Copy always" like so:

    Set-DnsSuffixSearchList.ps1 properties

  5. Create a file called startup.cmd which contains the following contents and also set the "Copy always" property:

    powershell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
    
    # Set the DNS SearchList so that backend hosts are resolvable using their shortened names.
    powershell .\Set-DnsSuffixSearchList.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
    
  6. Add a startup task to your Azure Cloud Service Project by editing ServiceDefinition.csdef and adding the following XML under the WebRole node:

    <Startup>
      <Task
        commandLine="startup.cmd"
        executionContext="elevated"
        taskType="background">
      </Task>
    </Startup>
    
  7. You're done, assuming that you've already specified that your site and backend should be in the same subnet. If not, add this to your ServiceConfiguration.Cloud.cscfg file inside the ServiceConfiguration node:

      <NetworkConfiguration>
        <VirtualNetworkSite name="yourVirtualNetwork" />
        <AddressAssignments>
          <InstanceAddress roleName="yourCloudServiceName">
            <Subnets>
              <Subnet name="yourSubnetName" />
            </Subnets>
          </InstanceAddress>
        </AddressAssignments>
      </NetworkConfiguration>
    

Hope that helps anyone else who stumbles across the same problem!


There are some "hidden" features of VN in Azure that will help you. First of all, yes, you are correct. If you create a Virtual Network, name resolution will not work unless you provide your own DNS Server and set it up to allow dynamic updates. You can't use public DNS Services to provide DNS name resolution for Windows Azure Virtual Network.

So here is your solution. You must start "Clean" because you cannot change DNS Server IP Address once VNet has running Virtual Machines in it.

  • Create the VNet as usual (and its subnets)
  • Provide DNS Server address. Set this address to be xxx.xxx.xxx.4 (4 will always be the first IP Address assigned in a given SubNet!) !
  • On that clean VNet, Create a new VM with Windows Server. That VM will get xxx.xxx.xxx.4 IP Address
  • Install and configure DNS Server Role on this machine
  • DO NOT SET STATIC IP ADDRESS OF THIS MACHINE!
  • Create rest of the VMs as usual

Things to be aware of:

  • Never assign static IP Addresses to any VM in Windows Azure. They must have DHCP allocated IP Addresses
  • Be careful to first create the DNS Machine, so that it get .4 IP Address
  • Your DNS VM will preserve its IP Address (.4) as long as you do not DELETE it.

This architecture has proven to be valid and works within Windows Azure IaaS (a.k.a. Virtual Machines)