Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 57 ยท Networking

DNS and Traffic Manager

Learn Azure DNS zones and records, private DNS zones, Traffic Manager routing methods, and how TTL and caching affect failover, with runnable resolver simulations.

People type names; networks use addresses. The Domain Name System (DNS) translates a name like www.contoso.com into an IP address, and almost every request to your application begins with a DNS lookup. In Azure, DNS shows up in three places: Azure DNS hosts your public domains, Private DNS zones give names to resources inside virtual networks, and Traffic Manager uses DNS answers to steer users between endpoints.

The real services need an account, so the commands are read-only. The runnable examples are JavaScript stand-ins: a resolver with a cache, which makes the effect of TTL visible, and a simulation of Traffic Manager's routing methods. Read Load Balancer, Application Gateway and Front Door first if you want the comparison with HTTP-level balancing.

How a lookup works

A client asks a recursive resolver (usually provided by the network or ISP) for a name. If the resolver does not have the answer cached, it walks the hierarchy: root servers point to the servers for .com, which point to the authoritative name servers for your domain. The authoritative servers hold the real records and answer. The resolver then caches the answer for the record's TTL (time to live, in seconds) and passes it back. Azure DNS runs those authoritative servers for the zones you host there; it does not sell domain names (a registrar does that, though Azure also offers an App Service Domain product).

sequenceDiagram
    participant C as Client
    participant R as Recursive resolver
    participant A as Authoritative servers<br/>(Azure DNS)
    C->>R: www.contoso.com?
    R->>A: www.contoso.com?
    A-->>R: 20.50.0.10 (TTL 300)
    R-->>C: 20.50.0.10
    Note over R: caches the answer for 300 s

After the first lookup, the resolver answers from its cache until the TTL runs out.

Azure DNS zones and records

A DNS zone is the container for all records of one domain, such as contoso.com. When you create the zone, Azure assigns four name servers (names ending in azure-dns.com, .net, .org and .info). To make the zone live you set these as the domain's name servers at your registrar. This step is called delegation.

Record types you will use most:

Type Purpose Example
A Name to IPv4 address api -> 20.50.0.20
AAAA Name to IPv6 address api -> 2603:...
CNAME Name is an alias of another name www -> contoso-web.azurewebsites.net
MX Mail servers priority and host
TXT Free text, domain verification, SPF "v=spf1 ..."
NS / SOA Zone delegation and metadata created automatically
CAA Which certificate authorities may issue certificates 0 issue "letsencrypt.org"

Two rules trip people up. A CNAME cannot exist at the zone apex (contoso.com itself), because the apex must also hold NS and SOA records. And a name with a CNAME cannot have other record types. Azure solves the apex problem with alias records: an A or AAAA record that points at an Azure resource (a public IP, a Traffic Manager profile or a Front Door endpoint). When the resource's address changes, the alias follows automatically, and the record is cleaned up if the resource is deleted.

Terminal
az network dns zone create --resource-group rg-dns --name contoso.com

az network dns record-set a add-record \
  --resource-group rg-dns --zone-name contoso.com \
  --record-set-name api --ipv4-address 20.50.0.20

az network dns record-set cname set-record \
  --resource-group rg-dns --zone-name contoso.com \
  --record-set-name www --cname contoso-web.azurewebsites.net

az network dns record-set a list --resource-group rg-dns --zone-name contoso.com --output table

TTL and caching: a resolver in JavaScript

TTL is a trade-off. A long TTL means fewer queries and a faster experience, but a change takes a long time to reach everyone. A short TTL makes changes and failovers quick but increases query volume. This stand-in resolver has a clock that you control, an authoritative zone, a cache, and CNAME following. Each output line shows which steps hit the cache and which went to the zone.

JS A resolver with a TTL cache

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Study two lines. At t=100 s the api record was already changed to 20.50.0.99, but the resolver still answers 20.50.0.20 from its cache, because the one-hour TTL has not run out. Only at t=3700 s does the new address appear. This is DNS propagation: not a mysterious delay, just caches expiring at different times in different places. The practical rule: lower the TTL (for example to 60 seconds) a day or two before a planned change, make the change, then raise it again. The first www lookups also show that a CNAME costs an extra lookup, with each link in the chain cached by its own TTL.

Private DNS zones

Inside a virtual network you want names for VMs and private endpoints that never appear on the public internet. Without extra setup, Azure provides a built-in resolver (at the virtual address 168.63.129.16) that knows VM names within the same VNet. For custom names, create a Private DNS zone such as corp.internal and link it to one or more VNets. Linked networks resolve the zone's records; unlinked networks and the internet cannot. With auto-registration enabled on a link, VMs in the VNet add and remove their own A records automatically.

Private DNS zones also power Private Endpoints: a zone such as privatelink.blob.core.windows.net makes the normal storage name resolve to a private IP inside your VNet, a topic continued in Private Endpoints, VPN and ExpressRoute.

Terminal
az network private-dns zone create --resource-group rg-dns --name corp.internal

az network private-dns link vnet create \
  --resource-group rg-dns --zone-name corp.internal \
  --name link-app --virtual-network vnet-app --registration-enabled true

Traffic Manager

Azure Traffic Manager is a DNS-based traffic router. It does not sit in the data path or proxy anything: when a client asks for shop.trafficmanager.net (usually reached through a CNAME from your own domain), Traffic Manager answers with the address of whichever endpoint its routing method chooses, and the client then connects there directly. Because it only works with DNS, it handles any protocol, not only HTTP, and endpoints can be in Azure, on-premises, or elsewhere. Traffic Manager probes each endpoint's health and leaves out the ones that fail.

The routing methods:

Method Behavior
Priority Always the highest-priority healthy endpoint; others are failover backups
Weighted Spread across endpoints by weight, useful for gradual migrations
Performance The endpoint with the lowest network latency for the user
Geographic Route users by their location, e.g. data residency rules
Multivalue Return several healthy addresses, letting the client choose
Subnet Map specific client IP ranges to specific endpoints
JS Traffic Manager routing methods

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The real Traffic Manager measures latency with its own internet latency tables and uses random draws for weights; the simulation uses fixed numbers so that the output is predictable. The behavior to remember is the failover line: when westeurope is marked unhealthy, the next answer simply skips it.

Failover is limited by TTL

Traffic Manager's answer carries a TTL, set on the profile (commonly 30 to 60 seconds, often shorter than ordinary records). Detecting a failure takes several probe intervals, and then clients keep using the cached old answer until their TTL expires. So failover is minutes, not milliseconds, and some clients and resolvers ignore low TTLs. If you need instant failover for web traffic, put a layer 7 service such as Front Door in front, and use Traffic Manager when you need protocol-agnostic or DNS-level control.

Terminal
az network traffic-manager profile create \
  --resource-group rg-dns --name tm-shop \
  --routing-method Performance --unique-dns-name shop-contoso \
  --ttl 60 --protocol HTTPS --port 443 --path /healthz

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. You change an A record whose TTL is 3600 seconds. What should you expect?

    Caches keep an answer until its TTL expires, so a change spreads gradually. Lowering the TTL ahead of a planned change shortens this window.
  2. 2. Why can you not create a CNAME record at the zone apex (contoso.com)?

    A name with a CNAME cannot have other records, and the apex always has NS and SOA. Azure alias records solve this for Azure resources.
  3. 3. What does a Private DNS zone linked to a VNet do?

    Private zones are visible only to the networks they are linked to, which keeps internal names off the public internet.
  4. 4. Which statement about Traffic Manager is correct?

    Traffic Manager works at the DNS level, so it supports any protocol and non-Azure endpoints, but failover depends on TTL.
  5. 5. Which routing method sends users to the lowest-latency endpoint?

    Performance routing returns the endpoint with the best measured network latency for the client's location.

Summary

  • DNS turns names into addresses; resolvers cache answers for the record's TTL, which is why changes take time to spread.
  • Azure DNS hosts public zones (delegate them at your registrar); alias records solve the zone apex problem for Azure resources.
  • Private DNS zones linked to VNets give internal names, optionally with auto-registration, and power Private Endpoints.
  • Traffic Manager steers clients by DNS using Priority, Weighted, Performance, Geographic, Multivalue or Subnet routing, with health probes.
  • Failover through DNS is bounded by TTL and probe timing, so choose short TTLs for failover records and plan changes ahead.

Next: Private Endpoints, VPN and ExpressRoute.