Networking Fundamentals Series

🧭 Understanding How DNS Works from a "Top 1%" Perspective — From the Hierarchy of Name Resolution to Juggling Multiple DNS Servers

Introduction

This article is part of the Top 1% Series’ full article guide. DNS server assignment via IPCP during VPN connection is covered in Understanding How L2TP/IPsec Works from a “Top 1%” Perspective.

Prerequisites

Getting the Big Picture

In a Nutshell

DNS (Domain Name System) is a worldwide, distributed database system for translating between “hierarchical names that are easy for humans to remember” (domain names) and “IP addresses that machines use for communication.” Rather than one giant server managing every name, the namespace itself is structured as a hierarchy (a tree), with management split up level by level — that’s the single most important premise for understanding DNS.

graph TB
    Root["Root (.)<br/>13 root server systems worldwide"]
    Root --> ComTld["TLD: .com"]
    Root --> JpTld["TLD: .jp"]
    ComTld --> ExampleAuth["Authoritative server: manages example.com"]
    JpTld --> CoJpAuth["Authoritative server: manages example.co.jp"]
    ExampleAuth --> Www["A record for<br/>www.example.com"]

At every level of this tree, the design is the same: each level is responsible only for the range it has been delegated, and delegates everything below that to a different managing entity. A root server only needs to know that “.com is managed by this set of TLD servers”; the .com TLD servers only need to know that “example.com is managed by this authoritative server.” Responsibility is cleanly split level by level like this, and it’s precisely this distributed design that lets the entire world’s domain names be managed without creating a single point of failure.

Fundamentals, Thoroughly Explained

Authoritative Servers and Recursive Resolvers: “The Side That Knows” vs. “The Side That Goes and Asks”

The first distinction to make when understanding how DNS works is between two servers with completely different roles: the authoritative server and the recursive resolver.

The Actual Name-Resolution Sequence: How Many Hops Does a Recursive Resolver Really Make?

Tracing what happens from the moment a client asks a recursive resolver for the IP address of www.example.com to the moment it actually gets an answer looks like this.

sequenceDiagram
    participant C as Client
    participant R as Recursive resolver
    participant Root as Root server
    participant TLD as .com TLD server
    participant Auth as example.com authoritative server

    C->>R: What's the IP for www.example.com?
    R->>Root: What's the IP for www.example.com?
    Root-->>R: Don't know, but .com is managed by this set of TLD servers (referral)
    R->>TLD: What's the IP for www.example.com?
    TLD-->>R: Don't know, but example.com is managed by this authoritative server (referral)
    R->>Auth: What's the IP for www.example.com?
    Auth-->>R: It's 203.0.113.10 (authoritative answer)
    R-->>C: It's 203.0.113.10

The key point here is that neither the root server nor the TLD server ever returns “the actual answer” — each just returns information about where to ask next (a referral), pointing to whoever it delegated that range to. Only the authoritative server that actually manages that zone can return the final, official answer (an Authoritative Answer). This whole process — going and chasing down the answer through however many hops it takes, on the client’s behalf — is called a recursive query, which is where “recursive resolver” gets its name.

Stub resolvers vs. full-service resolvers

The DNS functionality built into a client’s (PC’s or smartphone’s) OS doesn’t perform the entire recursive query process described above by itself. In most cases it’s a lightweight implementation called a stub resolver, which essentially just forwards the query to a single configured recursive resolver and passes back whatever answer comes back — hearsay, in effect. The actual work of a “full-service resolver” — walking from root, to TLD, to authoritative server — is handled on the recursive resolver side, provided by an ISP or a public DNS service. It helps, going into the next section on “DNS server settings on Windows/Linux,” to keep in mind that what’s actually being configured there is which recursive resolver the stub resolver sends its queries to.

Caching and TTL: Why Doesn’t It Ask the Root Every Single Time?

If the sequence above had to be dutifully repeated on every single lookup, root servers and TLD servers would be flooded with queries from around the world. What prevents that is caching. A recursive resolver holds on to an answer it has already obtained (along with the referral information along the way) for a period called the TTL (Time To Live), specified by the authoritative server, and answers instantly from cache if the same name is queried again before the TTL expires. Because it doesn’t need to re-query the authoritative server until the TTL expires, this both prevents queries from piling up on recursive resolvers worldwide and makes responses faster.

TTL length is a trade-off parameter that the side managing a DNS record (the authoritative server side) sets explicitly in the zone file. A longer TTL raises the cache hit rate, easing load on the authoritative server and improving response latency — but it also extends how long stale data can linger in caches around the world after a record’s content (such as an IP address) changes. When a server migration or load-balancer cutover is planned, the standard practice is to shorten the TTL beforehand, and only lengthen it again once the cutover is complete.

Major Record Types

The data DNS holds isn’t limited to name-to-IP mappings. The representative record types are as follows.

Record typeRole
AThe most basic record, mapping a hostname to an IPv4 address
AAAAMaps a hostname to an IPv6 address
CNAMEDefines a name as an alias for another name
MXSpecifies the mail server(s) that receive mail for that domain (with priority ordering)
NSIndicates the authoritative server(s) that manage that zone — the delegation information itself, discussed above
TXTA general-purpose record that holds an arbitrary string (used for mail-sender authentication such as SPF/DKIM, and for domain-ownership verification)
PTRA “reverse lookup” record for resolving a hostname from an IP address

The View from the Top 1% (What Experts See)

When Multiple DNS Servers Are Registered, Which One Actually Gets Used? (Windows)

A frequent source of confusion in practice is: when a single PC has multiple network adapters (wired LAN, Wi-Fi, a virtual adapter created by a VPN connection, and so on), each configured with a different DNS server, which one actually gets used?

On Windows, DNS server settings are held per network adapter. Open the properties for the relevant adapter from ncpa.cpl (the “Network Connections” panel in Control Panel), then open the properties for “Internet Protocol Version 4 (TCP/IPv4)” (or the “Advanced” tab), and you’ll see the list of DNS servers (preferred/alternate, or multiple candidates) tied to that specific adapter. In other words, the premise to grasp first is that the PC does not have a single, PC-wide DNS setting — instead, there can be as many DNS server lists as there are adapters.

When multiple adapters are active at once (say, a wired LAN and a VPN connection’s virtual adapter running simultaneously), the interface metric (a number indicating how strongly traffic over that adapter is preferred — lower means higher priority) also affects which DNS server gets used for name resolution. On top of that, whether “Use default gateway on remote network” is enabled for the VPN connection (i.e., a full-tunnel setup) also affects DNS resolution priority, alongside routing. However, this prioritization alone cannot achieve routing only a specific domain (such as an internal corporate domain) to a specific DNS server. That’s what the mechanism covered next, NRPT, is for.

NRPT (Name Resolution Policy Table): Routing Only Specific Domains to Specific DNS Servers

Windows has a mechanism called the NRPT (Name Resolution Policy Table). It lets you explicitly define a domain-level routing rule: “queries for the corp.example.com namespace, specifically, should go to a designated DNS server (such as an internal corporate DNS server) instead of the regular per-adapter DNS server.” It can be configured via Group Policy or the netsh namespace command. It was originally designed for DirectAccess (a certificate-based, always-on corporate VPN technology), but the same mechanism can be used with a regular VPN connection to control name resolution in a split-tunnel environment.

In an environment without NRPT configured, when a VPN connection uses split tunneling (only traffic destined for the corporate network goes over the VPN, while everything else continues to use the regular internet connection directly), even though “internal corporate DNS server information gets assigned during the VPN connection” is true on its own (via IPCP, as covered earlier), you can end up with inconsistent behavior — general, non-corporate name resolution also getting sent to the VPN-side DNS server, or, conversely, queries for corporate-internal domains getting sent to the regular DNS server (and failing) depending on how the interface metrics happen to shake out. Only by explicitly configuring NRPT (or an equivalent split-DNS setup) do you get deterministic control — “queries for this domain reliably go to this DNS server.”

When Multiple DNS Servers Are Registered, Which One Actually Gets Used? (Linux/systemd-resolved)

The situation on Linux depends on the distribution and DNS-resolution implementation in use.

Configuration when connecting to a VPN via NetworkManager

When NetworkManager manages a VPN connection, the VPN connection profile has settings for “which DNS server to use for this VPN connection” and “which domains (search domains) should be resolved via this VPN,” and these get reflected internally into systemd-resolved’s routing domain configuration. If internal name resolution isn’t working correctly over a VPN connection, the first thing to check is whether resolvectl status shows the correct DNS server and routing domain (a domain prefixed with ~) configured on the VPN’s virtual interface.

How DNS Resolution Differs Between Full-Tunnel and Split-Tunnel VPNs

Putting the above together, the behavior of DNS resolution over a VPN connection can be organized around the combination of tunnel type (full vs. split) and DNS routing configuration (whether NRPT/routing domains are set up).

ConfigurationGeneral name resolutionInternal-domain name resolution
Full tunnel (all traffic over the VPN)Uses the VPN-side DNS server (because the default gateway itself switches to the VPN side)Uses the VPN-side DNS server
Split tunnel, no NRPT/routing domainUsually favors the existing DNS server, but can become unreliable depending on interface metricsNo guarantee — can fail
Split tunnel, with NRPT/routing domainContinues using the existing DNS server as-is (internal domains are outside the split rule’s scope)Reliably routed to the VPN-side DNS server for the specified internal domain(s)

Keeping in mind that “connecting to a VPN automatically makes internal name resolution use the VPN server’s DNS information as top priority” only holds true for a full-tunnel configuration, or a split-tunnel configuration where NRPT/routing domains are properly set up — this makes DNS-related troubleshooting much faster in practice.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

DNS-related trouble is best approached by narrowing down which layer of cache or configuration is stale or wrong.

  1. Only one PC can’t resolve a specific name, or gets a stale IP: Suspect that PC’s local DNS cache. On Windows, check current cache contents with ipconfig /displaydns and clear it with ipconfig /flushdns. On Linux (systemd-resolved), the equivalents are resolvectl statistics and resolvectl flush-caches.
  2. Only internal-domain names fail to resolve (while connected to a VPN): Check whether NRPT (Windows) or the routing domain (Linux — check with resolvectl status) is configured correctly. A classic cause is queries for a specific domain not being routed correctly to the VPN-side DNS server.
  3. A device can’t resolve any name at all, internal or external: Use nslookup or dig to check whether the DNS server actually in use is even reachable. Also check whether reachability to the DNS server itself (UDP/TCP port 53) is being blocked somewhere, such as by a firewall.
  4. A newly changed record isn’t propagating globally: Stale cached data may still be sitting in recursive resolvers worldwide until the TTL expires. You can verify whether the change was actually applied correctly on the authoritative server side, unaffected by any caching, by querying that authoritative server directly (dig @<authoritative server IP> <hostname>).
  5. A specific internal authoritative/DNS server isn’t responding at all: Suspect the server process itself having stopped, a startup failure caused by a zone-file syntax error, or a mismatch in the delegation information (the NS record) from the parent zone above it.

Prevention and Long-Term Countermeasures

Summary

Starting Today

  1. When you hit a “can’t resolve DNS” issue, narrow down which layer is at fault: the local cache, the OS-level name-resolution configuration (per-adapter DNS servers, NRPT/routing domains), or the authoritative server itself.
  2. If internal name resolution is unreliable over a VPN, check the NRPT (Windows) or routing domain (Linux) configuration first.

Everything so far has been from the perspective of “using” name resolution. The perspective of actually building and operating a DNS server is covered starting with Understanding DNS Server Fundamentals.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).