0
0
Azurecloud~5 mins

Azure DNS basics - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to make your website or app reachable by a friendly name instead of numbers, you use DNS. Azure DNS helps you manage these names easily and reliably in the cloud.
When you want to host your domain's DNS records in Azure for better integration with other Azure services.
When you need to create custom domain names for your web apps or services hosted in Azure.
When you want to manage DNS records like A, CNAME, or MX for your domain without running your own DNS servers.
When you want fast and reliable DNS resolution with Azure's global network.
When you want to automate DNS record management using Azure CLI or templates.
Config File - dns-zone.json
dns-zone.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Network/dnsZones",
      "apiVersion": "2018-05-01",
      "name": "exampledomain.com",
      "location": "global",
      "properties": {}
    },
    {
      "type": "Microsoft.Network/dnsZones/A",
      "apiVersion": "2018-05-01",
      "name": "exampledomain.com/www",
      "dependsOn": [
        "Microsoft.Network/dnsZones/exampledomain.com"
      ],
      "properties": {
        "TTL": 3600,
        "ARecords": [
          {
            "ipv4Address": "20.50.40.30"
          }
        ]
      }
    }
  ]
}

This JSON file is an Azure Resource Manager template that creates a DNS zone named exampledomain.com in Azure DNS.

It also creates an A record for www.exampledomain.com pointing to the IP address 20.50.40.30.

The TTL is set to 3600 seconds, which means DNS servers will cache this record for one hour.

This template can be deployed to Azure to set up DNS hosting and records automatically.

Commands
This command creates a DNS zone named exampledomain.com in the resource group myResourceGroup. This is the first step to manage DNS records for your domain in Azure.
Terminal
az network dns zone create --resource-group myResourceGroup --name exampledomain.com
Expected OutputExpected
{ "etag": "00000000-0000-0000-0000-000000000000", "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/dnsZones/exampledomain.com", "location": "global", "maxNumberOfRecordSets": 5000, "name": "exampledomain.com", "numberOfRecordSets": 2, "resourceGroup": "myResourceGroup", "tags": {}, "type": "Microsoft.Network/dnsZones" }
--resource-group - Specifies the Azure resource group where the DNS zone will be created.
--name - Specifies the DNS zone name to create.
This command adds an A record named www to the exampledomain.com DNS zone, pointing to the IP address 20.50.40.30 with a TTL of 3600 seconds.
Terminal
az network dns record-set a add-record --resource-group myResourceGroup --zone-name exampledomain.com --record-set-name www --ipv4-address 20.50.40.30 --ttl 3600
Expected OutputExpected
No output (command runs silently)
--record-set-name - Specifies the DNS record set name to add the record to.
--ipv4-address - Specifies the IPv4 address for the A record.
--ttl - Sets how long DNS servers cache this record.
This command shows the details of the A record named www in the exampledomain.com DNS zone to verify it was created correctly.
Terminal
az network dns record-set a show --resource-group myResourceGroup --zone-name exampledomain.com --name www
Expected OutputExpected
{ "fqdn": "www.exampledomain.com.", "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/dnsZones/exampledomain.com/A/www", "name": "www", "properties": { "metadata": {}, "ttl": 3600, "aRecords": [ { "ipv4Address": "20.50.40.30" } ] }, "type": "Microsoft.Network/dnsZones/A" }
--name - Specifies the DNS record set name to show.
Key Concept

If you remember nothing else from this pattern, remember: Azure DNS lets you manage your domain names and their IP addresses easily in the cloud without running your own DNS servers.

Common Mistakes
Trying to add DNS records before creating the DNS zone.
DNS records must belong to an existing DNS zone; without the zone, records cannot be created.
Always create the DNS zone first using 'az network dns zone create' before adding any records.
Using incorrect resource group names or zone names in commands.
Azure commands require exact resource group and zone names; typos cause errors or create resources in wrong places.
Double-check resource group and zone names before running commands to ensure they match your Azure setup.
Not specifying TTL or using very low TTL values without reason.
TTL controls caching; very low TTL can increase DNS query traffic and slow down resolution.
Set TTL to a reasonable value like 3600 seconds unless you have a specific need for faster updates.
Summary
Create a DNS zone in Azure to start managing your domain's DNS records.
Add DNS records like A records to point domain names to IP addresses.
Verify DNS records exist and have correct values using Azure CLI commands.