How to manage DNS records in the Azure Private Zone

In a previous post, I showed you how to create a private DNS zone in Azure using PowerShell and Azure CLI. Today I will show you how to manage the DNS records of that area using PowerShell and Azure CLI.

Prerequisites

  • This tutorial assumes that you already have a Microsoft Azure account configured.
  • You already have a private DNS zone created and properly configured. If you want to know how to create it, see this link.

Azure PowerShell Workaround

If you want to know how to install the PowerShell Azure module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Once you set your default subscription, you’re ready to start.

Set the variables

Here, we define the characteristics of our environment and the resource’s properties.

Create DNS records

To create a record set containing multiple records, use New-AzPrivateDnsRecordConfig cmdlet with the following syntax.

New-AzPrivateDnsRecordConfig

instead to create a record with a single value, use the New-AzPrivateDnsRecordSet cmdlet with the following syntax.

Azure DNS Records

Update DNS records

if you want to add a record to an existing record set in a private DNS zone, use the following commands.

Set-AzPrivateDnsRecordSet

To update the existing record set, use the following command.

Azure DNS Records

List DNS records

To list all records in the private zone, use the cmdlet Get-AzPrivateDnsRecordSet with the following syntax.

Get-AzPrivateDnsRecordSet

Delete DNS records

To delete a specific record, use the Remove-AzPrivateDnsRecordSet cmdlet with the following syntax

Remove-AzPrivateDnsRecordSet

If instead, you want to delete all records of the same type, use the following commands.

Azure DNS Records

Azure CLI Workaround

In this case, we will use Azure Cloud Shell, a browser-based shell built into Azure Portal. This allows us to use the Azure command-line tools (Azure CLI and Azure PowerShell) directly from a browser. If you want to know more about Azure Cloud Shell, check out this link.

Create DNS records

To create an A record, use the following commands.

Azure DNS Records

Update DNS records

If you want to update the existing record set, use the following command.

Azure DNS Records

if instead, you want to add a record to an existing record set, use the following command

Azure DNS Records

List DNS records

To list all records in the private zone, use the following command.

Azure DNS Records

Delete DNS records

To only remove a specific record from a record set, use the following command.

Azure DNS Records

If you want to delete a record set and all associated records, use the following command.

Azure DNS Records

Thanks for reading my post. I hope you find it useful.

You can learn more about Azure Private DNS zone here: https://docs.microsoft.com/en-us/azure/dns/private-dns-overview