DNS Private Zones
π― Lab Objective
In this hands-on lab, you will learn how to:
- Create and configure Azure Private DNS Zones for internal name resolution
- Link Private DNS Zones to Virtual Networks with auto-registration
- Add custom DNS records (A and CNAME) for application access
- Validate DNS resolution from client VMs within the network
- Troubleshoot common DNS issues and implement fixes
Goal: Make http://app.corp.local
and http://www.corp.local
accessible from the Client VM using Azure Private DNS.
π Please sign in to launch lab.
ποΈ Pre-Provisioned Environment
The following Azure resources have been pre-deployed in your environment:
Resource Overview
Resource Type | Resource Name | Configuration | Purpose |
---|---|---|---|
Resource Group | rg-privdns-lab | Contains all lab resources | Logical container |
Virtual Network | privdns-lab-vnet | Private network segment | Network foundation |
VM-App | Ubuntu Server | NGINX on port 80 (internal) | Web application server |
VM-Client | Ubuntu Server | dnsutils & curl installed | DNS testing client |
Network Architecture
privdns-lab-vnetβββ VM-App (Ubuntu + NGINX)β βββ Internal web server on port 80βββ VM-Client (Ubuntu + DNS tools) βββ DNS resolution testing
Platform Outputs
The deployment provides these values for your use:
vmAppPrivateIp
- Private IP of the app servervmClientPrivateIp
- Private IP of the client VMvmAppPublicIp
- Public IP for SSH access (if enabled)vmClientPublicIp
- Public IP for SSH access (if enabled)vmAppName
- Application VM hostnamevmClientName
- Client VM hostname
π Lab Exercises
Task 1: Create a Private DNS Zone
Create a private DNS zone named corp.local
for internal name resolution.
Using Azure CLI (Recommended)
# Set variables (replace with your actual values)RG="rg-privdns-lab"ZONE="corp.local"
# Create the private DNS zoneaz network private-dns zone create \ --resource-group "$RG" \ --name "$ZONE"
Verification
# List private DNS zones to confirm creationaz network private-dns zone list \ --resource-group "$RG" \ --output table
π‘ Key Learning: Private DNS zones are not resolvable from the internetβthey only work within linked virtual networks.
Task 2: Link the Zone to Virtual Network
Link the private DNS zone to your VNet and enable auto-registration for VM hostnames.
Configure VNet Link
VNET_NAME="privdns-lab-vnet"LINK_NAME="corp-local-link"SUB_ID="<your-subscription-id>"
# Create VNet link with auto-registration enabledaz network private-dns link vnet create \ --resource-group "$RG" \ --zone-name "$ZONE" \ --name "$LINK_NAME" \ --virtual-network "/subscriptions/$SUB_ID/resourceGroups/$RG/providers/Microsoft.Network/virtualNetworks/$VNET_NAME" \ --registration-enabled true
Auto-Registration Check
After approximately 1-2 minutes, verify that VM hostnames are automatically registered:
# List all A records in the zoneaz network private-dns record-set a list \ --resource-group "$RG" \ --zone-name "$ZONE" \ --output table
Expected Result: You should see A records for your VMs (e.g., privdns-lab-vm-app.corp.local
)
π What Happened: Auto-registration automatically creates DNS records for VMs in the linked VNet.
Task 3: Add Custom DNS Records
Create user-friendly DNS records for easier application access.
Create A Record for Application
APP_NAME="app"APP_IP="<vmAppPrivateIp>" # Use the value from deployment outputs
# Create A record: app.corp.local -> VM-App private IPaz network private-dns record-set a add-record \ --resource-group "$RG" \ --zone-name "$ZONE" \ --record-set-name "$APP_NAME" \ --ipv4-address "$APP_IP"
Create CNAME Alias
WWW_NAME="www"
# Create CNAME record: www.corp.local -> app.corp.localaz network private-dns record-set cname set-record \ --resource-group "$RG" \ --zone-name "$ZONE" \ --record-set-name "$WWW_NAME" \ --cname "${APP_NAME}.${ZONE}"
Verify Record Creation
# List A recordsaz network private-dns record-set a show \ --resource-group "$RG" \ --zone-name "$ZONE" \ --name "$APP_NAME"
# List CNAME recordsaz network private-dns record-set cname show \ --resource-group "$RG" \ --zone-name "$ZONE" \ --name "$WWW_NAME"
Task 4: Validate DNS Resolution
Test DNS resolution and connectivity from the client VM.
Connect to Client VM
# SSH to client VM (use appropriate method based on your setup)ssh azureuser@<vmClientPublicIp>
# If no public IP is available, use Azure Bastion from the portal
Test DNS Resolution
# Test A record resolutionnslookup app.corp.local
# Test CNAME resolutionnslookup www.corp.local
# Alternative using dig (more detailed output)dig +short app.corp.localdig +short www.corp.local
Expected Results:
app.corp.local
β resolves to VM-Appβs private IPwww.corp.local
β resolves toapp.corp.local
(CNAME)
Test HTTP Connectivity
# Test application access via custom DNS namescurl -s http://app.corp.local | head -n 10curl -s http://www.corp.local | head -n 10
# Test with verbose output for troubleshootingcurl -v http://app.corp.local
Expected Result: You should see the βWelcome to the Internal Appβ HTML content from NGINX.
Task 5: Troubleshooting Exercise
Practice diagnosing and fixing common DNS issues.
Scenario A: VNet Link Issues
Simulate the Problem:
# Disable auto-registrationaz network private-dns link vnet update \ --resource-group "$RG" \ --zone-name "$ZONE" \ --name "$LINK_NAME" \ --registration-enabled false
# OR completely remove the VNet linkaz network private-dns link vnet delete \ --resource-group "$RG" \ --zone-name "$ZONE" \ --name "$LINK_NAME" \ --yes
Test the Impact:
# From Client VM - these should failnslookup app.corp.localcurl http://app.corp.local
Expected Symptoms:
- DNS resolution fails
curl
returns βcould not resolve hostβ error
Fix the Issue:
# Recreate the VNet link with auto-registrationaz network private-dns link vnet create \ --resource-group "$RG" \ --zone-name "$ZONE" \ --name "$LINK_NAME" \ --virtual-network "/subscriptions/$SUB_ID/resourceGroups/$RG/providers/Microsoft.Network/virtualNetworks/$VNET_NAME" \ --registration-enabled true
Scenario B: Incorrect A Record
Simulate the Problem:
# Remove correct A recordaz network private-dns record-set a remove-record \ --resource-group "$RG" \ --zone-name "$ZONE" \ --record-set-name "$APP_NAME" \ --ipv4-address "$APP_IP"
# Add incorrect A recordaz network private-dns record-set a add-record \ --resource-group "$RG" \ --zone-name "$ZONE" \ --record-set-name "$APP_NAME" \ --ipv4-address "10.10.10.10"
Test the Impact:
# From Client VMnslookup app.corp.local # This resolves to wrong IPcurl http://app.corp.local # This times out or fails
Expected Symptoms:
- DNS resolves to incorrect IP address
- HTTP connection times out or gets βconnection refusedβ
Fix the Issue:
# Remove incorrect recordaz network private-dns record-set a remove-record \ --resource-group "$RG" \ --zone-name "$ZONE" \ --record-set-name "$APP_NAME" \ --ipv4-address "10.10.10.10"
# Add correct record backaz network private-dns record-set a add-record \ --resource-group "$RG" \ --zone-name "$ZONE" \ --record-set-name "$APP_NAME" \ --ipv4-address "$APP_IP"
π§ Common Troubleshooting
DNS Resolution Issues
Issue | Possible Cause | Solution |
---|---|---|
nslookup fails completely | VNet not linked to DNS zone | Create or fix VNet link |
Resolves to wrong IP | Incorrect A record | Update A record with correct IP |
CNAME doesnβt resolve | Target record missing | Verify target A record exists |
Intermittent failures | DNS caching | Wait 30-60 seconds or flush DNS cache |
Connectivity Issues
Issue | Possible Cause | Solution |
---|---|---|
DNS works, HTTP fails | Application not running | Check NGINX status on VM-App |
Connection timeout | Firewall blocking traffic | Verify NSG rules allow port 80 |
Wrong content returned | Resolving to wrong server | Verify A record points to correct IP |
π§ͺ Additional Experiments
Try these optional exercises to deepen your understanding:
- Multiple Zones: Create additional DNS zones (e.g.,
dev.local
,test.local
) - Record Types: Experiment with other record types (TXT, MX, SRV)
- Conditional Forwarding: Set up forwarding to external DNS servers
- Cross-VNet Resolution: Link multiple VNets to the same DNS zone
π Key Takeaways
After completing this lab, you should understand:
- Private DNS Zones provide internal name resolution within Azure VNets
- VNet linking is required for DNS resolution to work
- Auto-registration automatically creates records for VMs
- Custom records (A, CNAME) provide user-friendly application access
- Troubleshooting DNS involves checking both resolution and connectivity
- Private DNS is isolated from internet DNS for security