How to create DNS zone and an A record by using Azure DNS


Below is a step-by-step guide for creating a DNS zone and adding an A (Address) Record using the Azure Portal.

Prerequisites

  • An active Azure subscription.

  • A domain name (optional, for public zones).

Step 1: Create a DNS Zone

  1. Sign in to Azure Portal:

  2. Navigate to DNS Zones:

    • In the search bar, type "DNS Zones" and select it from the search results.

  3. Create a New DNS Zone:

    • Click + Create to open the DNS Zone creation wizard.

  4. Provide the Zone Details:

    • Resource Group: Select an existing resource group or create a new one.

    • Name: Enter the domain name for the DNS zone (e.g., example.com for public zones or example.local for private zones).

    • Type: Choose between:

      • Public: For domains that resolve publicly.

      • Private: For internal resolution within VNets (requires VNet linking).

    • Click Review + Create, then click Create after validation.

Step 2: Add an A Record

  1. Open the DNS Zone:

    • Once the DNS zone is created, navigate to the resource by clicking its name.

  2. Add a Record Set:

    • On the DNS Zone page, click + Record set at the top.

  3. Configure the A Record:

    • Name: Enter the subdomain (e.g., www for www.example.com).

    • Type: Select A from the dropdown menu.

    • TTL (Time-to-Live): Specify the cache duration for DNS queries (e.g., 3600 seconds = 1 hour).

    • IP Address: Enter the IPv4 address of the resource (e.g., 192.168.1.10).

    • Click OK to save.

Step 3: Test the Configuration

  1. If it’s a public DNS zone:

    • Use tools like nslookup or dig to query the domain:

  2. If it’s a private DNS zone:

    • Ensure the virtual network is linked to the private DNS zone.

    • Log in to a virtual machine within the linked VNet and test name resolution using nslookup:

Example:

  • DNS Zone: example.com

  • A Record:

    • Name: www

    • TTL: 3600

    • IP Address: 192.168.1.10

  • Resulting Fully Qualified Domain Name (FQDN): www.example.com

Optional: Managing DNS Zone Settings

Azure DNS also allows you to:

  1. Add additional record types (e.g., CNAME, MX, TXT).

  2. Delete or modify records as needed.

  3. Use role-based access control (RBAC) to manage access to DNS zones.

Automating using Azure CLI

Azure CLI is a powerful tool for managing Azure resources from the command line.

Step 1: Install Azure CLI

Step 2: Sign in to Azure

Log in to your Azure account:

Step 3: Create a Resource Group

Create a resource group where the DNS zone will be hosted:

Step 4: Create a DNS Zone

Create a DNS zone for your domain:

Step 5: Add an A Record

Add an A record to the DNS zone:

Step 6: Verify DNS Records

List all DNS records in the zone:

Automating using ARM Templates

Azure Resource Manager (ARM) templates allow you to define infrastructure as code.

Step 1: Create an ARM Template

Here's an example JSON template to create a DNS Zone and an A Record:

Step 2: Deploy the ARM Template

Save the template as dns-zone-template.json, then deploy it using the Azure CLI:

3. Key Differences

FeatureAzure CLIARM Templates
Ease of UseBest for quick tasks and one-off commands.Ideal for repeatable, automated deployments.
Infrastructure as CodeRequires manual tracking.Provides a declarative approach.
FlexibilitySimple for basic setups.Supports complex dependencies and configurations.
   

Using Bicep or Terraform to automate further

To automate deployments further, consider integrating these scripts/templates into Azure DevOps or GitHub Actions workflows.

Use Azure Bicep (a simpler declarative language) for writing ARM templates.

Here’s how to create a DNS Zone and an A Record using Azure Bicep, a simpler and more readable alternative to ARM templates.

1. Introduction to Azure Bicep

Azure Bicep is an Infrastructure as Code (IaC) tool designed to simplify resource deployment on Azure. It is:

  • Declarative: Describe "what" you want, not "how" to do it.

  • Simplified Syntax: Easier to write and read compared to JSON-based ARM templates.

  • Azure-Native: Fully integrated with Azure Resource Manager (ARM).

2. Prerequisites

  • Install Azure CLI

  • Install Bicep CLI: Use the following Azure CLI command to install Bicep:

  • Access to Azure Portal: Ensure you have an active Azure subscription and the required permissions.

3. Create a Bicep File

Bicep Template for DNS Zone and A Record

Save the following as dns-zone.bicep:

Explanation:

  1. dnsZone Resource:

    • Creates the DNS zone with the domain name example.com.

  2. aRecord Resource:

    • Creates an A Record (www.example.com) with an IPv4 address.

4. Deploy the Bicep Template

Step 1: Deploy with Azure CLI

Run the following commands to deploy the Bicep file:

  1. Create a Resource Group:

  1. Deploy the Bicep Template:

Step 2: Verify the Deployment

  1. Go to the Azure Portal.

  2. Navigate to the DNS Zones blade.

  3. Open the created DNS Zone (example.com) and verify that the A Record (www.example.com) is present.

5. Key Benefits of Using Bicep

FeatureDescription
Simplified SyntaxCleaner and more readable compared to JSON ARM templates.
Modular DesignEnables reuse of code for multiple deployments.
Native Azure IntegrationBuilt into Azure CLI and Azure Resource Manager.
Error CheckingProvides better error feedback during template compilation.
  

6. Automate with Azure DevOps or GitHub Actions

Example Azure DevOps Pipeline:

  1. Pipeline YAML:

Example GitHub Actions Workflow:

  1. Workflow YAML:

Summary

By using Azure Bicep, you gain:

  • Simplicity: Cleaner and more intuitive templates.

  • Reusability: Modular and easy-to-parameterize templates.

  • Integration: Seamless deployment through Azure CLI, DevOps pipelines, or GitHub Actions.

Let me know if you'd like help setting up any of these automation methods!

 

Related Articles


Rajnish, MCT

Leave a Reply

Your email address will not be published. Required fields are marked *


SUBSCRIBE

My newsletter for exclusive content and offers. Type email and hit Enter.

No spam ever. Unsubscribe anytime.
Read the Privacy Policy.