### Set up and install Az.DnsResolver PowerShell module Source: https://learn.microsoft.com/en-us/azure/dns/dns-traffic-log-how-to These PowerShell commands register a local repository, install a specific version of the Az.DnsResolver module, and confirm the installation. Ensure you have the correct path to your local repository. ```powershell # Register the repository Register-PSRepository -Name LocalPSRepo -SourceLocation 'C:\bin\PSRepo' -ScriptSourceLocation 'C:\bin\PSRepo' -InstallationPolicy Trusted # Install the Az.DnsResolver module Install-Module -Name Az.DnsResolver -RequiredVersion 0.2.6 -SkipPublisherCheck # If you already installed Az.DnsResolver, update your version to 0.2.6 Update-Module -Name Az.DnsResolver # Confirm that the Az.DnsResolver module was installed properly Get-InstalledModule -Name Az.DnsResolver ``` -------------------------------- ### Install Private DNS Migration Script Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-migration-guide Run this command in an elevated PowerShell window to install the migration script. Enter 'A' when prompted to confirm the installation. ```PowerShell install-script PrivateDnsMigrationScript ``` -------------------------------- ### Install Azure DNS Management Library for .NET Source: https://learn.microsoft.com/en-us/azure/dns/dns-sdk Install the Azure DNS management library for .NET using the .NET CLI. ```bash dotnet add package Azure.ResourceManager.Dns ``` -------------------------------- ### Install NGINX and set index page on web-01 Source: https://learn.microsoft.com/en-us/azure/dns/tutorial-alias-tm Installs NGINX and sets a custom index.html for the web-01 virtual machine. Ensure the VM is running Ubuntu and has apt-get available. ```bash sudo apt-get update && sudo apt-get install -y nginx && echo 'Hello World from web-01' | sudo tee /var/www/html/index.html ``` -------------------------------- ### Install NGINX and set index page on web-02 Source: https://learn.microsoft.com/en-us/azure/dns/tutorial-alias-tm Installs NGINX and sets a custom index.html for the web-02 virtual machine. Ensure the VM is running Ubuntu and has apt-get available. ```bash sudo apt-get update && sudo apt-get install -y nginx && echo 'Hello World from web-02' | sudo tee /var/www/html/index.html ``` -------------------------------- ### Ping Output Example Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-getstarted-powershell Example output from a successful ping command to a VM within the private DNS zone, showing successful packet replies and round-trip times. ```text PS C:\> ping myvm01.private.contoso.com Pinging myvm01.private.contoso.com [10.2.0.4] with 32 bytes of data: Reply from 10.2.0.4: bytes=32 time<1ms TTL=128 Reply from 10.2.0.4: bytes=32 time=1ms TTL=128 Reply from 10.2.0.4: bytes=32 time<1ms TTL=128 Reply from 10.2.0.4: bytes=32 time<1ms TTL=128 Ping statistics for 10.2.0.4: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 1ms, Average = 0ms PS C:\> ``` -------------------------------- ### Example: Export Azure DNS Zone 'contoso.com' Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-import-export This example demonstrates exporting the 'contoso.com' DNS zone from the 'myresourcegroup' resource group to a file named 'contoso.com.txt' in the current directory. ```azurecli az network private-dns zone export -g myresourcegroup -n contoso.com -f contoso.com.txt ``` -------------------------------- ### Install NGINX on Ubuntu VM Source: https://learn.microsoft.com/en-us/azure/dns/tutorial-alias-pip Use this command to update package lists and install NGINX on an Ubuntu virtual machine. Ensure you have sudo privileges. ```bash sudo apt-get update && sudo apt-get install -y nginx ``` -------------------------------- ### Install Az.DnsResolver PowerShell Module Source: https://learn.microsoft.com/en-us/azure/dns/dns-private-resolver-get-started-powershell Installs the Az.DnsResolver module. Ensure you have the Az module installed first. ```powershell Install-Module Az.DnsResolver ``` -------------------------------- ### Get All Dns Zones in a Resource Group Source: https://learn.microsoft.com/en-us/azure/dns/dns-sdk This example shows how to retrieve a list of all DNS zones within a specific resource group. It iterates through the results and prints the name of each DNS zone. ```csharp ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); // first we need to get the resource group string rgName = "myRgName"; ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName); // Now we get the DnsZone collection from the resource group DnsZoneCollection dnsZoneCollection = resourceGroup.GetDnsZones(); // With ListAsync(), we can get a list of the DnsZones AsyncPageable response = dnsZoneCollection.GetAllAsync(); await foreach (DnsZoneResource dnsZone in response) { Console.WriteLine(dnsZone.Data.Name); } ``` -------------------------------- ### Run Private DNS Migration Script Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-migration-guide Execute this command to start the private DNS zone migration process. The script will guide you through entering subscription IDs, selecting zones, and switching DNS resolution. ```PowerShell PrivateDnsMigrationScript.ps1 ``` -------------------------------- ### Ping Custom Record Output Example Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-getstarted-powershell Example output from a successful ping command to a custom DNS record within the private DNS zone, demonstrating successful resolution and connectivity. ```text PS C:\> ping db.private.contoso.com Pinging db.private.contoso.com [10.2.0.4] with 32 bytes of data: Reply from 10.2.0.4: bytes=32 time<1ms TTL=128 Reply from 10.2.0.4: bytes=32 time<1ms TTL=128 Reply from 10.2.0.4: bytes=32 time<1ms TTL=128 Reply from 10.2.0.4: bytes=32 time<1ms TTL=128 Ping statistics for 10.2.0.4: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milliseconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms PS C:\> ``` -------------------------------- ### Example Zone File for Azure Private DNS Import Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-import-export-portal This is a sample zone file content used for importing into Azure Private DNS. It includes MX, A, CNAME, PTR, TXT, and SRV record examples. Ensure SOA and NS records are handled as per Azure Private DNS requirements. ```text ; MX Records ; A Records aa1 3600 IN A 10.10.0.1 db1002 3600 IN A 10.1.1.2 myvm 10 IN A 10.10.2.5 server1 3600 IN A 10.0.1.1 server2 3600 IN A 10.0.1.2 ; AAAA Records ; CNAME Records app1 3600 IN CNAME aa1.private.contoso.com. ; PTR Records ; TXT Records ; SRV Records ``` -------------------------------- ### Verify Az.DnsResolver Module Installation Source: https://learn.microsoft.com/en-us/azure/dns/dns-private-resolver-get-started-powershell Confirms that the Az.DnsResolver module is installed and shows its current version. The expected version is 0.2.1. ```powershell Get-InstalledModule -Name Az.DnsResolver ``` -------------------------------- ### Classless IPv4 Delegation Example Source: https://learn.microsoft.com/en-us/azure/dns/dns-reverse-dns-overview This example demonstrates how to set up DNS delegation and CNAME records for a smaller IP range within the .in-addr.arpa zone. It shows the ISP's role in delegating a child zone and mapping IPs. ```dns $ORIGIN 2.0.192.in-addr.arpa ; Delegate child zone 128-26 NS 128-26 NS ; CNAME records for each IP address 129 CNAME 129.128-26.2.0.192.in-addr.arpa 130 CNAME 130.128-26.2.0.192.in-addr.arpa 131 CNAME 131.128-26.2.0.192.in-addr.arpa ; etc ``` -------------------------------- ### Get help for Azure DNS CLI commands Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-dnszones-cli Use the `--help` option to get help for Azure DNS CLI commands. This is useful for understanding available options and parameters. ```bash az network dns --help az network dns zone --help az network dns zone create --help ``` -------------------------------- ### Example of an A record set with multiple records Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-recordsets-cli This example shows a record set containing multiple A records for the same FQDN, mapping to different IP addresses. This is a common scenario for load balancing. ```dns www.contoso.com. 3600 IN A 134.170.185.46 www.contoso.com. 3600 IN A 134.170.188.221 ``` -------------------------------- ### Example DNS Zone File Source: https://learn.microsoft.com/en-us/azure/dns/dns-import-export-portal This is a sample DNS zone file for 'adatum.com' including SOA, NS, MX, and A records. It is used to demonstrate the import process into Azure DNS. ```dns $ORIGIN adatum.com. $TTL 86400 @ IN SOA dns1.adatum.com. hostmaster.adatum.com. ( 2023091201 ; serial 21600 ; refresh after 6 hours 3600 ; retry after 1 hour 604800 ; expire after 1 week 86400 ) ; minimum TTL of 1 day IN NS dns1.adatum.com. IN NS dns2.adatum.com. IN MX 10 mail.adatum.com. IN MX 20 mail2.adatum.com. dns1 IN A 203.0.113.2 dns2 IN A 203.0.113.1 server1 IN A 192.0.2.2 server2 IN A 192.0.2.3 ftp IN A 198.51.100.1 IN A 198.51.100.2 mail IN CNAME server1 mail2 IN CNAME server2 www IN CNAME server1 ``` -------------------------------- ### Exported Azure DNS Zone File Example Source: https://learn.microsoft.com/en-us/azure/dns/dns-import-export-portal This is an example of an exported zone file from Azure DNS. It includes SOA, NS, MX, A, and CNAME records. The file is downloaded as a text file. ```dns ; Exported zone file from Azure DNS ; Zone name: adatum.com ; Date and time (UTC): Tue, 12 Sep 2023 21:33:17 GMT $TTL 86400 $ORIGIN adatum.com ; SOA Record @ 3600 IN SOA SOA dns1.adatum.com. ( 0 ;serial 21600 ;refresh 3600 ;retry 604800 ;expire 86400 ;minimum ttl ) ; NS Records @ 172800 IN NS ns1-36.azure-dns.com. @ 172800 IN NS ns2-36.azure-dns.net. @ 172800 IN NS ns3-36.azure-dns.org. @ 172800 IN NS ns4-36.azure-dns.info. ; MX Records @ 3600 IN MX 10 mail.adatum.com. @ 3600 IN MX 20 mail2.adatum.com. ; A Records dns1 3600 IN A 203.0.113.2 dns2 3600 IN A 203.0.113.1 ftp 3600 IN A 198.51.100.1 ftp 3600 IN A 198.51.100.2 server1 3600 IN A 192.0.2.2 server2 3600 IN A 192.0.2.3 ; AAAA Records ; CNAME Records mail 3600 IN CNAME server1 mail2 3600 IN CNAME server2 www 3600 IN CNAME server1 ; PTR Records ; TXT Records ; SRV Records ; SPF Records ; CAA Records ; DS Records ; Azure Alias Records ``` -------------------------------- ### Example nslookup for Private Endpoint Resolution Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-fallback Demonstrates a typical nslookup query for a private endpoint, showing the resolution process when fallback to the internet is enabled. ```text C:\>nslookup remoteprivateendpoint.blob.core.windows.net Server: UnKnown Address: 168.63.129.16 Non-authoritative answer: Name: blob.mwh20prdstr02e.store.core.windows.net Address: 203.0.113.33 Aliases: remoteprivateendpoint.blob.core.windows.net remoteprivateendpoint.privatelink.blob.core.windows.net ``` -------------------------------- ### Install Azure DNS CLI Extension Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-dnszones-cli Install the 'dns' extension for the Azure CLI to enable management of Azure DNS Private Zones. This extension provides DNS-specific commands. ```bash az extension add --name dns ``` -------------------------------- ### PTR Records in Child Zone Example Source: https://learn.microsoft.com/en-us/azure/dns/dns-reverse-dns-overview This example shows how an organization manages individual PTR records within their delegated child zone for classless IPv4 delegation. These records map specific IPs to hostnames. ```dns $ORIGIN 128-26.2.0.192.in-addr.arpa ; PTR records for each UIP address. Names match CNAME targets in parent zone 129 PTR www.contoso.com 130 PTR mail.contoso.com 131 PTR partners.contoso.com ; etc ``` -------------------------------- ### Sample dig Output for DS Record Source: https://learn.microsoft.com/en-us/azure/dns/dnssec-how-to Example output from the `dig` command showing the DS record details for a domain. ```text ;; ANSWER SECTION: adatum.com. 86400 IN DS 26767 13 2 0B9E68FC1711B4AC4EC0FCE5E673EDB0AFDC18F27EA94861CDF08C71 00EA776C ``` -------------------------------- ### Connect to Azure Account Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-dnszones Use this command to sign in to your Azure account from PowerShell. Ensure you have the Azure PowerShell module installed. ```powershell Connect-AzAccount ``` -------------------------------- ### Create an 'A' record set using PowerShell Source: https://learn.microsoft.com/en-us/azure/dns/dns-getstarted-powershell Use the `New-AzDnsRecordSet` cmdlet to create a new DNS record set. This example creates an 'A' record for 'www.contoso.xyz' with a specific IP address and TTL. ```powershell New-AzDnsRecordSet -Name www -RecordType A -ZoneName contoso.xyz -ResourceGroupName MyResourceGroup -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "10.10.10.10") ``` -------------------------------- ### Sample Azure PowerShell Output for DS Record Source: https://learn.microsoft.com/en-us/azure/dns/dnssec-how-to Example output from `Get-AzDnsDnssecConfig` showing the delegation signer information, including digest algorithm type, digest value, and record details. ```powershell DigestAlgorithmType DigestValue Record ------------------- ----------- ------ 2 0B9E68FC1711B4AC4EC0FCE5E673EDB0AFDC18F27EA94861CDF08C7100EA776C 26767 13 2 0B9E68FC1711B4AC4EC0FCE5E673EDB0AFDC18F27EA94861CDF08C7100EA776C ``` -------------------------------- ### Verify DNS delegation with nslookup Source: https://learn.microsoft.com/en-us/azure/dns/dns-delegate-domain-azure-dns Use nslookup to query the Start of Authority (SOA) record for your domain to verify delegation. Ensure you wait at least 10 minutes for changes to propagate. ```bash nslookup -type=SOA contoso.xyz ``` ```text contoso.xyz primary name server = ns1-37.azure-dns.com responsible mail addr = azuredns-hostmaster.microsoft.com serial = 1 refresh = 3600 (1 hour) retry = 300 (5 mins) expire = 604800 (7 days) default TTL = 300 (5 mins) ``` -------------------------------- ### Query Private DNS Zones Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-arg A basic query to retrieve all private DNS zones. Use this to get started with querying DNS resources. ```kql dnsresources | project name, resourceGroup, location, tags ``` -------------------------------- ### Initialize Terraform Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-terraform Run terraform init to initialize the Terraform deployment. The -upgrade parameter upgrades provider plugins to the newest version. ```bash terraform init -upgrade ``` -------------------------------- ### Install Az.PrivateDns module for Azure PowerShell Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-migration-guide Install the Az.PrivateDns module for Azure PowerShell by running this command in an elevated PowerShell window. This module is required for the migration process. ```powershell Install-Module -Name Az.PrivateDns ``` -------------------------------- ### Create the first test virtual machine Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-getstarted-cli Create a virtual machine for testing your private DNS zone. This command creates a VM named 'myVM01' without a public IP address, suitable for private network testing. ```azurecli az vm create \ --name myVM01 \ --admin-username AzureAdmin \ --resource-group MyAzureResourceGroup \ --location eastus \ --subnet backendSubnet \ --vnet-name myAzureVnet \ --image win2016datacenter \ --public-ip-address "" ``` -------------------------------- ### Create a DNS zone with tags Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-dnszones-cli Create a DNS zone and assign Azure Resource Manager tags using the `--tags` parameter. Tags help organize and categorize resources. ```bash az network dns zone create --resource-group MyResourceGroup --name contoso.com --tags "project=demo" "env=test" ``` -------------------------------- ### Create a private DNS zone and link to a virtual network Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-getstarted-cli This sequence creates a virtual network, a private DNS zone, and links the zone to the virtual network, enabling automatic hostname registration. Use `--registration-enabled false` if you only need name resolution without automatic registration. ```bash az network vnet create \ --name myAzureVNet \ --resource-group MyAzureResourceGroup \ --location eastus \ --address-prefix 10.2.0.0/16 \ --subnet-name backendSubnet \ --subnet-prefixes 10.2.0.0/24 az network vnet subnet create \ --vnet-name myAzureVNet \ --resource-group MyAzureResourceGroup \ --name AzureBastionSubnet \ --address-prefix 10.2.1.0/26 az network private-dns zone create \ --resource-group MyAzureResourceGroup \ --name private.contoso.com az network private-dns link vnet create \ --resource-group MyAzureResourceGroup \ --name MyDNSLink \ --zone-name private.contoso.com \ --virtual-network myAzureVNet \ --registration-enabled true ``` -------------------------------- ### Example of an A record set with multiple records Source: https://learn.microsoft.com/en-us/azure/dns/dns-private-records This example shows a record set for 'www.contoso.com' with two A records, each pointing to a different IPv4 address. Azure DNS manages such collections as a single record set. ```dns www.contoso.com. 3600 IN A 10.10.1.5 www.contoso.com. 3600 IN A 10.10.1.10 ``` -------------------------------- ### Create a DNS zone Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-dnszones Use the `New-AzDnsZone` cmdlet to create a new DNS zone. Specify the zone name and the resource group. ```powershell New-AzDnsZone -Name contoso.com -ResourceGroupName MyDNSResourceGroup ``` -------------------------------- ### Deploy Bicep file using Azure CLI Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-bicep Use Azure CLI commands to create a resource group and then deploy the Bicep file to create the DNS zone and record. ```azurecli az group create --name exampleRG --location eastus az deployment group create --resource-group exampleRG --template-file main.bicep ``` -------------------------------- ### Create a DNS zone Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-dnszones-cli Create a DNS zone in a specified resource group. Use the `--name` parameter for the zone name and `--resource-group` for the resource group name. ```bash az network dns zone create --resource-group MyResourceGroup --name contoso.com ``` -------------------------------- ### Create the second test virtual machine Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-getstarted-cli Create a second virtual machine for testing. This command creates a VM named 'myVM02' without a public IP address, similar to the first VM, for comprehensive private DNS testing. ```azurecli az vm create \ --name myVM02 \ --admin-username AzureAdmin \ --resource-group MyAzureResourceGroup \ --location eastus \ --subnet backendSubnet \ --vnet-name myAzureVnet \ --image win2016datacenter \ --public-ip-address "" ``` -------------------------------- ### Get Azure Subscriptions Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-dnszones Lists all Azure subscriptions available for the connected account. This helps in selecting the correct subscription for subsequent operations. ```powershell Get-AzSubscription ``` -------------------------------- ### Create A Record using Azure CLI Source: https://learn.microsoft.com/en-us/azure/dns/dns-web-sites-custom-domain Use these Azure CLI commands to create an A record set and then add your web app's IPv4 address to it. The '@' symbol represents the root domain. ```bash # Create the A record set az network dns record-set a create \ --resource-group test-rg \ --zone-name contoso.com \ --name "@" \ --ttl 600 # Add the IP address to the A record set az network dns record-set a add-record \ --resource-group test-rg \ --zone-name contoso.com \ --record-set-name "@" \ --ipv4-address "" ``` -------------------------------- ### Get DNS Zone Name (Terraform Output) Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-terraform Extracts the DNS zone name from Terraform outputs. This is a prerequisite for subsequent verification commands. ```bash dns_zone_name=$(terraform output -raw dns_zone_name) ``` -------------------------------- ### Terraform Provider Configuration Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-terraform Defines the required Terraform version and providers (azurerm, random) for managing Azure resources. Ensure these providers are installed and configured. ```terraform terraform { required_version = ">=1.2" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~>3.0" } random = { source = "hashicorp/random" version = "~>3.0" } } } provider "azurerm" { features {} } ``` -------------------------------- ### Create a second virtual network and link it to your DNS forwarding ruleset Source: https://learn.microsoft.com/en-us/azure/dns/dns-private-resolver-get-started-powershell Creates a new virtual network and then links it to the existing DNS forwarding ruleset. This simulates an on-premises or other environment. ```powershell $vnet2 = New-AzVirtualNetwork -Name myvnet2 -ResourceGroupName myresourcegroup -Location westcentralus -AddressPrefix "12.0.0.0/8" $vnetlink2 = New-AzDnsForwardingRulesetVirtualNetworkLink -DnsForwardingRulesetName $dnsForwardingRuleset.Name -ResourceGroupName myresourcegroup -VirtualNetworkLinkName "vnetlink2" -VirtualNetworkId $vnet2.Id -SubscriptionId ``` -------------------------------- ### Get an existing DNS record set Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-recordsets Retrieves an existing DNS record set for a given name, zone, resource group, and record type. ```powershell Get-AzDnsRecordSet -Name www –ZoneName "contoso.com" -ResourceGroupName "MyResourceGroup" -RecordType A ``` -------------------------------- ### Create a resource group Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-getstarted-cli Creates a new resource group to contain your DNS zone and related resources. Ensure the resource group name and location are appropriate for your needs. ```bash az group create --name MyAzureResourceGroup --location "East US" ``` -------------------------------- ### Get DNS Zone Name (PowerShell) Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-terraform Extracts the DNS zone name from Terraform outputs using PowerShell. This is a prerequisite for subsequent verification commands. ```powershell $dns_zone_name=$(terraform output -raw dns_zone_name) ``` -------------------------------- ### Get Azure Resource Group Name (Terraform Output) Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-terraform Extracts the resource group name from Terraform outputs. This is a prerequisite for subsequent verification commands. ```bash resource_group_name=$(terraform output -raw resource_group_name) ``` -------------------------------- ### Create Azure DNS Zone and A Record with ARM Template Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-template This ARM template defines resources for creating a DNS zone and an 'A' record within that zone. It includes parameters for zone and record names, and specifies the IP addresses for the 'A' record. ```json { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "metadata": { "_generator": { "name": "bicep", "version": "0.30.23.60470", "templateHash": "418957128302192274" } }, "parameters": { "zoneName": { "type": "string", "defaultValue": "[format('{0}.azurequickstart.org', uniqueString(resourceGroup().id))]", "metadata": { "description": "The name of the DNS zone to be created. Must have at least 2 segments, e.g. hostname.org" } }, "recordName": { "type": "string", "defaultValue": "www", "metadata": { "description": "The name of the DNS record to be created. The name is relative to the zone, not the FQDN." } } }, "resources": [ { "type": "Microsoft.Network/dnsZones", "apiVersion": "2018-05-01", "name": "[parameters('zoneName')]", "location": "global" }, { "type": "Microsoft.Network/dnsZones/A", "apiVersion": "2018-05-01", "name": "[format('{0}/{1}', parameters('zoneName'), parameters('recordName'))]", "properties": { "TTL": 3600, "ARecords": [ { "ipv4Address": "203.0.113.1" }, { "ipv4Address": "203.0.113.2" } ] }, "dependsOn": [ "[resourceId('Microsoft.Network/dnsZones', parameters('zoneName'))]" ] } ], "outputs": { "nameServers": { "type": "array", "value": "[reference(resourceId('Microsoft.Network/dnsZones', parameters('zoneName')), '2018-05-01').nameServers]" } } } ``` -------------------------------- ### Get name server records for a zone Source: https://learn.microsoft.com/en-us/azure/dns/dns-getstarted-cli Retrieve the name server (NS) records for your DNS zone. This is a prerequisite for testing name resolution externally. ```bash az network dns record-set ns show --resource-group MyResourceGroup --zone-name contoso.xyz --name @ ``` -------------------------------- ### Exported Zone File Content Source: https://learn.microsoft.com/en-us/azure/dns/private-dns-import-export-portal This is an example of the content of an exported zone file from Azure Private DNS. It includes SOA, A, and CNAME records for the private.contoso.com zone. ```dns ; Exported zone file from Azure Private DNS ; Zone name: private.contoso.com ; Date and time (UTC): Mon, 17 Jun 2024 20:35:47 GMT $TTL 10 $ORIGIN private.contoso.com ; SOA Record @ 3600 IN SOA azureprivatedns.net azureprivatedns-host.microsoft.com ( 1 ;serial 3600 ;refresh 300 ;retry 2419200 ;expire 10 ;minimum ttl ) ; MX Records ; A Records aa1 3600 IN A 10.10.0.1 db1002 3600 IN A 10.1.1.2 myvm 10 IN A 10.10.2.5 server1 3600 IN A 10.0.1.1 server2 3600 IN A 10.0.1.2 ; AAAA Records ; CNAME Records app1 3600 IN CNAME aa1.private.contoso.com. ; PTR Records ; TXT Records ; SRV Records ``` -------------------------------- ### Get an A record set Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-recordsets-cli Retrieves an existing 'A' record set from a specified DNS zone and resource group. Ensure the record set name is relative to the zone. ```azurecli az network dns record-set a show --resource-group myresourcegroup --zone-name contoso.com --name www ``` -------------------------------- ### Get Azure Resource Group Name (PowerShell) Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-terraform Extracts the resource group name from Terraform outputs using PowerShell. This is a prerequisite for subsequent verification commands. ```powershell $resource_group_name=$(terraform output -raw resource_group_name) ``` -------------------------------- ### Create a TXT record Source: https://learn.microsoft.com/en-us/azure/dns/dns-operations-recordsets-cli This command creates a TXT record set, which allows administrators to associate arbitrary text with a host or domain. ```APIDOC ## az network dns record-set txt add-record ### Description Creates a TXT record set. ### Method az network dns record-set txt add-record ### Parameters #### Path Parameters - **--resource-group** (string) - Required - Name of resource group. - **--zone-name** (string) - Required - Zone name. - **--record-set-name** (string) - Required - Name of the record set. - **--value** (string) - Required - The text value of the record. ### Request Example ```bash az network dns record-set txt add-record --resource-group myresourcegroup --zone-name contoso.com --record-set-name test-txt --value "This is a TXT record" ``` ``` -------------------------------- ### Test DNS Records using nslookup Source: https://learn.microsoft.com/en-us/azure/dns/dns-web-sites-custom-domain Validate CNAME and A records by querying them with nslookup. This example shows how to query 'www.contoso.com' and 'contoso.com', and set the record type to TXT. ```powershell PS C:\> nslookup Default Server: Default Address: 192.168.0.1 > www.contoso.com Server: default server Address: 192.168.0.1 Non-authoritative answer: Name: .cloudapp.net Address: Aliases: www.contoso.com contoso.azurewebsites.net .vip.azurewebsites.windows.net > contoso.com Server: default server Address: 192.168.0.1 Non-authoritative answer: Name: contoso.com Address: > set type=txt > contoso.com Server: default server Address: 192.168.0.1 Non-authoritative answer: contoso.com text = "contoso.azurewebsites.net" ``` -------------------------------- ### Deploy Bicep file using Azure PowerShell Source: https://learn.microsoft.com/en-us/azure/dns/dns-get-started-bicep Use Azure PowerShell commands to create a resource group and then deploy the Bicep file to create the DNS zone and record. ```powershell New-AzResourceGroup -Name exampleRG -Location eastus New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep ```