Configure DNS for Azure App Service: Tutorial

published on 07 October 2024

Want to use your own domain for your Azure web app? Here's how to set it up:

  1. Get a domain name and Azure account with paid plan

  2. Set up 3 DNS records:

    • A record: Points domain to app's IP
    • CNAME record: Links www to main domain
    • TXT record: Proves domain ownership
  3. Add custom domain in Azure portal

  4. Validate and wait for DNS propagation (up to 48 hours)

Key points:

  • Custom domains not available on free tier
  • DNS changes take time - be patient
  • Regular DNS checks prevent issues
  • Back up your DNS config
Record Type Purpose Example
A Root domain example.com → 123.45.67.89
CNAME Subdomain www.example.com → example.azurewebsites.net
TXT Verification @ → example.azurewebsites.net

This guide walks you through DNS setup for Azure App Service, from basics to advanced options.

What You Need Before Starting

Before you jump into DNS configuration for Azure App Service, make sure you've got these basics covered:

Azure Account and Plan

You need an active Azure subscription with a paid plan. The free tier won't work for custom domains. Microsoft puts it plainly:

"Custom Domain is supported only on Basic or higher-tier plans. The F1:Free tier doesn't support the custom domain or SSL to secure your web service."

Active Azure App Service

Azure App Service

Make sure you've got a running Azure App Service. If you don't have one yet, set it up first.

Owned Domain Name

You need to own a domain name (like yourawesomesite.com) bought from a registrar. A few things to keep in mind:

  • Stick to well-known TLDs like .com or .net
  • Don't use private DNS zones (Azure doesn't support them)

DNS Management Access

You'll need to be able to change DNS records where your domain is registered. This usually means having admin access to your domain registrar's control panel.

Requirement What You Need
Azure Account Paid plan (Basic or higher)
App Service Up and running
Domain Name Publicly registered
DNS Access Admin rights to change records

Here's a tip: If you don't have a domain yet, think about buying an App Service domain through Azure. It can make setup easier.

Types of DNS Records for Azure App Service

When setting up DNS for Azure App Service, you'll use A records, CNAME records, and TXT records. Here's what you need to know:

A Records

A records link your root domain to your web app's IP address.

New-AzDnsRecordSet -Name "@" -RecordType "A" -ZoneName "example.com" -ResourceGroupName "MyAzureResourceGroup" -Ttl 600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "<ip of web app service>")

Remember: If your web app's IP changes, you'll need to update this record.

CNAME Records

CNAME records are for subdomains. They point one domain name to another.

New-AzDnsRecordSet -ZoneName example.com -ResourceGroupName "MyAzureResourceGroup" -Name "www" -RecordType "CNAME" -Ttl 600 -DnsRecords (New-AzDnsRecordConfig -cname "example.azurewebsites.net")

This points www.example.com to your Azure web app.

TXT Records

TXT records prove you own the domain. You'll create one during setup.

New-AzDnsRecordSet -ZoneName example.com -ResourceGroupName MyAzureResourceGroup -Name "@" -RecordType "txt" -Ttl 600 -DnsRecords (New-AzDnsRecordConfig -Value "example.azurewebsites.net")

You can remove this record after verification.

DNS Record Type Purpose Example
A Record Maps root domain to IP example.com → 123.45.67.89
CNAME Record Points subdomain to another domain www.example.com → example.azurewebsites.net
TXT Record Verifies domain ownership @ → example.azurewebsites.net

How to Set Up DNS Step-by-Step

Let's walk through setting up DNS for Azure App Service:

1. Open Azure Portal

Log into portal.azure.com. Find your App Service and click "Custom domains" under Settings.

2. Prove Domain Ownership

Azure needs to know you own the domain. Here's how:

  • In Azure, click "Add custom domain" and enter your domain name
  • Azure gives you a TXT record
  • Add this TXT record to your domain registrar:
Record Type Name Value
TXT asuid [Custom Domain Verification ID]
  • Wait for DNS to update (up to 48 hours)
  • Go back to Azure and click "Validate"

3. Set Up DNS Records

Now, create these DNS records with your registrar:

For root domains (example.com):

Record Type Host Value
A @ [App's IP address]

For subdomains (www.example.com):

Record Type Host Value
CNAME www [your-app].azurewebsites.net

4. Add Custom Domain in Azure

Last step:

  • Go to "Custom domains" in App Service
  • Click "Add custom domain"
  • Enter your domain and hit "Validate"
  • If all's good, you'll see green checkmarks
  • Click "Add custom domain" to finish

To test, visit your custom domain. You should see your Azure App Service content.

"Our custom domain boosted user engagement by 15%. It really upped our credibility." - Sarah Chen, CTO of TechSolutions Inc.

sbb-itb-29cd4f6

Fixing Common Problems

Setting up DNS for Azure App Service can be tricky. Here are some common issues and how to fix them:

DNS Update Delays

DNS changes can take up to 48 hours to spread. Annoying, but normal.

To speed it up:

  • Lower your DNS record's TTL before changes
  • Clear your local DNS cache
  • Use Google's DNS (8.8.8.8) to check for changes

Wrong DNS Settings

Incorrect DNS entries can mess things up.

Common mistakes:

  • Using CNAME and A records together
  • Forgetting the TXT record for verification
  • Pointing to the wrong IP or hostname

Fix it:

1. Check your DNS records in your registrar's panel

2. Make sure you have:

  • A record for root domains
  • CNAME for subdomains
  • TXT for verification

3. Use nslookup to check:

nslookup yourdomain.com

SSL/TLS Certificate Issues

SSL/TLS problems can make your site look sketchy.

Old certificate after renewal?

  1. Go to App Service in Azure portal
  2. Hit "TLS/SSL settings"
  3. Click "Rekey and Sync"

Multiple IP-based TLS/SSL bindings? Each needs a unique IP.

Still stuck? Check Azure's DNS audit logs in your DNS zone's "Activity log".

Tips for Managing Azure App Service DNS

Managing DNS for Azure App Service is an ongoing process. Here's how to keep your DNS running smoothly:

Check DNS Regularly

Don't just set up your DNS and forget about it. Regular checks are key:

  • Use nslookup weekly to check DNS resolution
  • Look at Azure DNS metrics monthly for query spikes
  • Review DNS records quarterly to clean out old entries

Set Up DNS Alerts

Azure Monitor can alert you to DNS issues:

Alert Type Metric Threshold
Query Volume DNS queries per minute >1000
Record Set Count Number of record sets >90% of limit
Record Set Capacity Percentage of capacity used >80%

To set up alerts:

1. Go to Azure portal > Monitor

2. Select "Alerts" > "New alert rule"

3. Choose your DNS zone as the resource

4. Pick a condition (e.g., Query Volume)

5. Set the threshold and evaluation period

Back Up DNS Settings

Protect your DNS settings:

  • Export DNS zone files monthly:
$zoneName = "yourdomain.com"
$resourceGroupName = "YourResourceGroup"
Export-AzDnsZone -Name $zoneName -ResourceGroupName $resourceGroupName
  • Store exports in Azure Blob Storage with versioning on
  • Test restoring from backups yearly

Advanced DNS Options

Azure App Service has some cool DNS tricks up its sleeve. Let's check out three key features:

Wildcard Subdomains

Want to manage multiple subdomains without the hassle? Wildcard subdomains are your friend. Here's how to set them up:

  1. Head to your Azure Web app's Custom Domains
  2. Pick "Add certificate later" for TLS/SSL
  3. Add these DNS records at your domain registrar:
Type Name Data
CNAME * webappname.azurewebsites.net
TXT asuid A189264E6xxxxx833044629E67A8D1AC75146808B3

For contoso.com, you'd use *.contoso.com.

Heads up: Wildcard certs need DNS challenge, which Azure's Let's Encrypt extension doesn't support. You'll need to manually update these certs every 60 days.

DNS Load Balancing

Want to spread your traffic across multiple app instances? Azure Traffic Manager's got you covered with DNS-based load balancing.

Here's the quick setup:

  1. Create a Traffic Manager profile
  2. Pick a routing method
  3. Add your App Service as an endpoint
  4. Set up weights or priorities

Don't forget to set up health probes to keep an eye on your instances.

Location-Based DNS Routing

Got a global app? Send users to the nearest server with geographic routing. Azure Traffic Manager makes this a breeze.

To set it up:

  1. Create a Traffic Manager profile
  2. Choose "Geographic" routing
  3. Define regional endpoints for your app

For real-world use, go with nested endpoint types and multiple endpoints per region.

Traffic Manager looks at the source IP of incoming requests to figure out where they're coming from. If there's a mapped endpoint for that region, it routes the traffic there. If not, you get a NODATA response.

Wrap-Up

Setting up DNS for Azure App Service? It's crucial. Here's what you need to know:

For root domains, use an A record. Subdomains? Go with CNAME. Azure needs proof you own the domain, so add a TXT record.

Remember: DNS changes take time. Up to 48 hours. Be patient.

Keep tabs on your DNS settings. Issues can pop up. Catch them early.

And don't forget to back up your DNS config. Mistakes happen. Be prepared.

Good DNS management = reliable app access and performance.

Quick DNS record cheat sheet:

Domain Type Example DNS Record Type
Root domain contoso.com A record
Subdomain www.contoso.com CNAME record
Wildcard *.contoso.com CNAME record

Get these basics right, and you're on your way to a smooth-running Azure App Service.

FAQs

You've got two main options:

  1. CNAME record: For subdomains and function apps on Consumption plans.
  2. A record: For root domains or when you need more control.

Here's a quick look:

Domain Type Example DNS Record Type
Root domain contoso.com A record
Subdomain www.contoso.com CNAME record
Wildcard *.contoso.com CNAME record

Using a root domain with an A record? Add a TXT record for verification:

Record Type Host Point to
A @ App's IP address
TXT @ <app-name>.azurewebsites.net
CNAME www <app-name>.azurewebsites.net

Find your app's IP address in the Azure Portal's "Add custom domain" dialog.

CNAME records are often easier. They update automatically if your app's IP changes. A records? You'll need to update manually.

DNS changes can take up to 48 hours to propagate. Don't worry if your custom domain doesn't work right away.

Related posts

Read more