During Public Preview you can use the Team plan for free, and get an early-adopter discount at GA. Sign in
Deploying a Private DNS Zone
This guide shows you how to deploy a Private DNS Zone against Locally, add records to it, link it to a Virtual Network, and look the records up with dig. As with the other guides we're going to use the Azure CLI, but the same resources can be provisioned with HashiCorp Terraform, Pulumi or Bicep too.
If you're after a zone for a domain the rest of the world can see, see DNS Zone.
Before you start
- The Azure CLI (
az) installed. diginstalled. It ships with macOS and most Linux distributions (in thednsutilsorbind-utilspackage).- Locally installed, with Locally Setup completed.
1. Start Locally
Firstly, we need to launch Locally which we can do from a terminal by running:
$
locally build
Once Locally has started, the Locally Dashboard will open automatically:
2. Create a Resource Group
Next we can create the Resource Group:
$
locally run az group create -n sample-private-dns -l berlin
There's two things to note here:
- The Azure CLI supports Automatic Configuration, meaning that it can automatically be configured to work against Locally just by prefixing commands with
locally run. - Locally intentionally uses a different set of locations to Azure as a safety precaution, so that you can be confident you're deploying against Locally rather than regular Azure. You can also configure Locally to use the Azure locations too, but you'll want to be extra sure that you're prefixing commands with
locally runwhen you do.
3. Create a Virtual Network
Private DNS Zones are linked to Virtual Networks, so we'll create one to link to:
$
locally run az network vnet create -g sample-private-dns -n sample-vnet --address-prefixes 10.0.0.0/16 --subnet-name internal --subnet-prefixes 10.0.1.0/24 --query "newVNet.{name:name, addressPrefixes:addressSpace.addressPrefixes, subnet:subnets[0].addressPrefix}"
{
"addressPrefixes": [
"10.0.0.0/16"
],
"name": "sample-vnet",
"subnet": "10.0.1.0/24"
}
4. Create the Private DNS Zone
Now the zone itself. Its name is a domain that only resolves within the networks you link it to, so it doesn't need to be registered anywhere:
$
locally run az network private-dns zone create -g sample-private-dns -n sample.internal --query "{name:name, provisioningState:provisioningState}"
{
"name": "sample.internal",
"provisioningState": "Succeeded"
}
5. Add some records
A zone with no records doesn't resolve anything, so let's add an A record pointing api at an address inside the subnet:
$
locally run az network private-dns record-set a add-record -g sample-private-dns -z sample.internal -n api -a 10.0.1.10 --query "{fqdn:fqdn, records:aRecords[].ipv4Address}"
{
"fqdn": "api.sample.internal.",
"records": [
"10.0.1.10"
]
}
Note
api in sample.internal gives api.sample.internal., with the trailing dot marking it as fully qualified.Then a CNAME, so that orders is another name for the same service:
$
locally run az network private-dns record-set cname set-record -g sample-private-dns -z sample.internal -n orders -c api.sample.internal --query "{fqdn:fqdn, cname:cnameRecord.cname}"
{
"cname": "api.sample.internal",
"fqdn": "orders.sample.internal."
}
And an SRV record, which tells clients that look it up which host and port the service runs on:
$
locally run az network private-dns record-set srv add-record -g sample-private-dns -z sample.internal -n _https._tcp.api -t api.sample.internal -r 443 -p 10 -w 5 --query "{fqdn:fqdn, records:srvRecords}"
{
"fqdn": "_https._tcp.api.sample.internal.",
"records": [
{
"port": 443,
"priority": 10,
"target": "api.sample.internal",
"weight": 5
}
]
}
We can list everything in the zone with:
$
locally run az network private-dns record-set list -g sample-private-dns -z sample.internal --query "[].{Name:name, Type:type, FQDN:fqdn}" -o table
Name Type FQDN
--------------- --------------------------------------- --------------------------------
@ Microsoft.Network/privateDnsZones/SOA sample.internal.
api Microsoft.Network/privateDnsZones/A api.sample.internal.
orders Microsoft.Network/privateDnsZones/CNAME orders.sample.internal.
_https._tcp.api Microsoft.Network/privateDnsZones/SRV _https._tcp.api.sample.internal.
The SOA record at the apex (@) is created with the zone.
6. Link the zone to the network
In Azure, nothing in a Virtual Network can resolve names from a Private DNS Zone until the zone is linked to it. This is the step that's easy to forget, and the symptom - names that simply don't resolve - gives you little to go on:
$
locally run az network private-dns link vnet create -g sample-private-dns -z sample.internal -n vnet-link -v sample-vnet -e false --query "{name:name, registrationEnabled:registrationEnabled, provisioningState:provisioningState}"
{
"name": "vnet-link",
"provisioningState": "Succeeded",
"registrationEnabled": false
}
The -e false turns off auto-registration, so you manage the records yourself. With -e true, Azure adds an A record for each Virtual Machine in the network instead.
We can see the zone, its records and the link in the Locally Dashboard too:
7. Look up the records
Locally's DNS server answers for the records in your Private DNS Zones too. Your machine only sends .locally lookups to it, so we ask it directly, on port 5673:
$
dig @127.0.0.1 -p 5673 api.sample.internal +short
10.0.1.10
Note
-p 5673.The CNAME comes back as the name it points to:
$
dig @127.0.0.1 -p 5673 orders.sample.internal +short
api.sample.internal.
And the SRV record gives the priority, weight, port and host we set:
$
dig @127.0.0.1 -p 5673 _https._tcp.api.sample.internal SRV +short
10 5 443 api.sample.internal.
Your machine isn't inside the Virtual Network, so Locally answers these lookups whether or not the zone is linked. Keep the link in your templates anyway, since in Azure the names won't resolve without it.
8. Tidy up
Finally, we can tidy up. To remove the Resource Group and everything within it:
$
locally run az group delete -n sample-private-dns --yes
There's nothing billable to clean up, since everything ran on your machine, but it's still worth checking your teardown scripts work here before you run them against Azure.
Doing this with other tooling
Whilst this guide used the Azure CLI, Private DNS Zones work the same way through any of the tooling that Locally supports - a Microsoft.Network/privateDnsZones resource, its record sets and its virtualNetworkLinks in HashiCorp Terraform or OpenTofu, Pulumi, Bicep or an ARM Template all provision against Locally in the same way, with only the location changed.
Next steps
The DNS Server page lists every record type Locally serves. For a zone the rest of the world can see, take a look at DNS Zone, and for more on the network the zone is linked to, see Virtual Network.
Should you encounter any issues, please take a look at the troubleshooting section, reach out in our Discord or open an issue and we'll take a look.
Resource types this guide uses
These are the Azure resource types this guide creates in Locally:
During Public Preview you can use the Team plan for free, and get an early-adopter discount at GA. Sign in