Creating domain zones in AzureDns [cheat sheet]

  • Tutorial
Hello, Habr!
I want to publish a small cheat sheet for creating new domain zones in AzureDns. To my surprise, I did not find any visual editor for this in the new interface, so all actions will be performed from PowerShell.

After turning over a bunch of articles from the manual on creating a DNS in Azure, I made a small squeeze of the necessary commands.

Step one


Download and install PowerShell
Switch to Azure mode:
Switch-AzureMode -Name AzureResourceManager

Log in:
Add-AzureAccount

Switch to subscription:
Select-AzureSubscription -SubscriptionName "name"

If you don’t know which name to specify, then the list of subscriptions can be obtained with the command
Get-AzureSubscription

We are interested in the Name field, the data from it must be substituted into the -SubscriptionName option .

Read more about dns in Azure.

Second step


Create a new root zone (or get the existing one):
$zone = New-AzureDnsZone -Name domain.com -ResourceGroupName "Group-1"

or
$zone = Get-AzureDnsZone -Name domain.com -ResourceGroupName "Group-1"

Information on the created zone can be viewed with the command:
Get-AzureDnsRecordSet –Name “@” –RecordType NS –Zone $zone


Step three


Add A record:
New-AzureDnsRecordSet -Name "@" -Zone $zone -RecordType "A" -Ttl 300 | Add-AzureDnsRecordConfig -Ipv4Address "1.2.3.4" | Set-AzureDnsRecordSet

or by zone name
New-AzureDnsRecordSet -Name "@" –ZoneName domain.com -ResourceGroupName "Group-1" -RecordType "A" -Ttl 300 | Add-AzureDnsRecordConfig -Ipv4Address "1.2.3.4" | Set-AzureDnsRecordSet


Learn more about supported posts.

Step four


We look at ns-servers on a zone:
Get-AzureDnsRecordSet -Zone $zone -Name "@" -RecordType NS


And add them to your registrar.

Repeat the steps as many times as necessary. You can view the list of already added zones with the command:
Get-AzureDnsZone -ResourceGroupName Group-1


Add a subdomain


New-AzureDnsZone -Name "test.domain.com" -ResourceGroupName "Group-1"
New-AzureDnsRecordSet -Name "@" -ZoneName "test.domain.com" -ResourceGroupName "Group-1" -RecordType "A" -Ttl 300 | Add-AzureDnsRecordConfig -Ipv4Address "1.2.3.4" | Set-AzureDnsRecordSet
$parent = Get-AzureDnsZone -Name "domain.com" -ResourceGroupName "Group-1"
$child = Get-AzureDnsZone -Name "test.domain.com" -ResourceGroupName "Group-1"
$child_ns_recordset = Get-AzureDnsRecordSet -Zone $child -Name "@" -RecordType NS
$parent_ns_recordset = New-AzureDnsRecordSet -Zone $parent -Name "test" -RecordType NS -Ttl 3600
$parent_ns_recordset.Records = $child_ns_recordset.Records
Set-AzureDnsRecordSet -RecordSet $parent_ns_recordset 


PS: and it’s even better to use the leschenko habrayuzer utility , for which many thanks to him!

Thank you for attention.

Also popular now: