DNS - jasper-zanjani/azure GitHub Wiki
Notes
Azure DNS supports private zones, which provide name resolution for VMs on a VNet and between VNets without having to create a custom DNS solution.
Time-to-live for DNS record sets is provided in seconds.
Alias record sets
Azure DNS alias records allow other Azure resources, such as public IPs or CDN endpoints, to be referenced from the DNS zone. This allows these records to be automatically updated or deleted when the underlying Azure resource is changed.
- An A alias record set is a special type of record set that allows you to create an alternative name for a record set in your domain zone or for resources in your subscription.
- A CNAME alias record set can only point to another CNAME record set
Tasks
DNS zone
Create
New-AzDnsZone -Name examref.com -ResourceGroupName ExamRefRG
az network dns zone create --name examref.com --resource-group ExamRefRG
DNS record
Create empty A record
New-AzDnsRecordSet -Name www -RecordType A -ZoneName examref.com -ResourceGroupName ExamRefRG -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "1.2.3.4")
az network dns record-set a create --name www --zone-name examref.com --resource-group ExamRefRG --ttl 3600
Create multiple records
$records = @()
$records += New-AzDnsRecordConfig -IPv4Address "1.2.3.4"
$records += New-AzDnsRecordConfig -IPv4Address "5.6.7.8"
New-AzDnsRecordSet -Name "@" -RecordType A -ZoneName examref.com -ResourceGroupName ExamRefRG -Ttl 3600 -DnsRecords $records
az network dns record-set a add-record --record-set-name www --zone-name examref.com --resource-group ExamRefRG --ipv4-address 1.2.3.4
az network dns record-set a add-record --record-set-name www --zone-name examref.com --resource-group ExamRefRG --ipv4-address 5.6.7.8
Remove
PowerSehll
$recordset = Get-AzDnsRecordSet -Name www -RecordType A -ZoneName examref.com -ResourceGroupName ExamRefRG
Add-AzdnsRecordConfig -RecordSet $recordset -IPv4Address "5.6.7.8"
Remove-AzDnsRecordConfig -RecordSet $recordset -IPv4Address "1.2.3.4"
Set-AzDnsRecordSet -RecordSet $recordset
az network dns record-set a remove-record --record-set-name www --zone-name examref.com --resource-group ExamRefRG --ipv4-address 1.2.3.4
Read
Get-AzDnsRecordSet -ZoneName examref.com -ResourceGroupName ExamRefRG
az network dns record-set list --zone-name examref.com --resource-group ExamRefRG -o table
Configure custom DNS settings
Create a virtual network with custom DNS settings
New-AzVirtualNetwork -Name VNet1 -ResourceGroupName ExamRefRG -Location "North Europe" -AddressPrefix 10.1.0.0/16 -DNSServer 10.0.0.4,10.0.0.5 -Subnet (New-AzVirtualNetworkSubnetConfig -Name Default -AddressPrefix 10.1.0.0/24)
Modify the DNS server configuration of an existing VNET
$vnet = Get-AzVirtualNetwork -Name VNet1 -ResourceGroupName ExamRefRG
$vnet.DhcpOptions.DnsServers.Clear()
$vnet.DhcpOptions.DnsServers.Add("10.10.200.1")
$vnet.DhcpOptions.DnsServers.Add("10.10.200.2")
Set-AzVirtualNetwork -VirtualNetwork $vnet
Restart the VMs in the VNet to pick up the DNS change
$vm = Get-AzVM -Name VNet1-VM -ResourceGroupName ExamRefRG
Restart-AzVM -ID $vm.Id
Update the DNS settings on a NIC
$nic = Get-AzNetworkInterface -Name VM1-NIC -ResourceGroupName ExamRefRG
$nic.DnsSettings.DnsServers.Clear()
$nic.DnsSettings.DnsServers.Add("8.8.8.8")
$nic.DnsSettings.DnsServers.Add("8.8.4.4")
Commit the DNS change, causing the VM to restart
Set-AzNetworkInterface -NetworkInterface $nic
Create a virtual network with custom DNS settings
az network vnet create --name VNet1 --resource-group ExamRefRG --address-prefixes 10.0.0.0/16 --dns-servers 8.8.8.8 8.8.4.4
Set custom DNS servers on a VNet
az network vnet update --name VNet1 --resource-group ExamRefRG --dns-servers 10.0.0.254
Remove custom DNS servers from a VNET
az network vnet update --name VNet1 --resource-group ExamRefRG --remove DHCPOptions.DNSServers
Set custom DNS servers on a NIC
az network nic update --name VM1-NIC --resource-group ExamRefRG --dns-servers 8.8.8.8 8.8.4.4