DNS: How a Name Becomes an IP Address
The name hierarchy, recursive resolvers and iterative resolution, caching and TTL, record types, port 53, local DNS on OPNsense, the link with DHCP, troubleshooting and security.
We type www.example.com into the browser and a fraction of a second later the page opens, yet the network carries packets to numeric addresses, not to names. The translation is done by the DNS, a database distributed across thousands of servers all over the world. In this article we look at the hierarchy of names, step-by-step resolution, caching and TTL, the record types, DNS inside the local network with OPNsense, and the most common problems.
Why we need names
Every device on an IP network is reached through an address, for example 192.0.2.80 in IPv4 or 2001:db8::80 in IPv6. Such addresses are hard for people to remember and, above all, they change: if a service moves to another server, all it takes is to update the mapping between its name and the new address.
In the early days of the Internet the mappings lived in a single file, which survives today as the hosts file of operating systems. In 1987 RFC 1034 and RFC 1035 defined the DNS: a hierarchical, distributed system in which no server knows every name, but each one knows whom to ask.
The hierarchy: root, TLD and authoritative domain
A domain name is read from right to left. In www.example.com. the final dot, which is usually omitted, stands for the root. Below the root are the top-level domains (TLDs): generic ones such as .com and .org, country-code ones such as .it, and technical ones such as .arpa. Below the TLD is the registered domain, here example.com, and below that the names chosen by its owner, such as www or mail.
Management is delegated. The root servers do not know the address of www.example.com, but they know which servers are responsible for .com. Those servers, in turn, know which servers are responsible for example.com: the zone's authoritative servers, the only ones that actually hold that domain's records. There are thirteen root server identities, from a.root-servers.net to m.root-servers.net, each replicated at many sites using anycast.
Recursive resolver and iterative resolution
The computer does not walk the hierarchy by itself. The operating system includes a stub resolver, a simple component that sends the question to a recursive resolver, a server that takes on the job of finding the complete answer. Often this is the network's router or firewall. The resolver, in turn, queries the authoritative servers iteratively: each server answers with what it knows, even if that is only a pointer to the next server.
Let us follow an example that uses addresses reserved for documentation. The PC 192.168.1.20 wants to reach www.example.com and uses the firewall 192.168.1.1 as its resolver, whose cache is empty.
- The PC asks the resolver: “what is the IPv4 address (A record) of
www.example.com?”. The query carries the RD flag (recursion desired): the PC wants the final answer. - The resolver asks a root server, whose addresses it knows from a preinstalled list (root hints). The root does not know the answer but returns a referral: the NS records of the
.comservers, with their addresses. - The resolver repeats the question to a .com TLD server, which answers with another referral: the authoritative servers of
example.com, for examplens1.example.comat 203.0.113.53. The server addresses included in the referral are called glue records. - The resolver asks the authoritative server, which answers with the A record:
www.example.com→ 192.0.2.80, with a TTL of 3600 seconds. The response carries the AA flag (authoritative answer). - The resolver caches the answer and the referrals, then delivers the answer to the PC, which can open the connection to 192.0.2.80.
Caching and TTL: why DNS is fast
If every request started again from the root, DNS would be slow and the root servers would be overwhelmed. That is why every record has a TTL (time to live), a number of seconds set by the zone owner that states how long an answer may be reused. The resolver keeps the answer in its cache and answers later requests immediately, with the remaining TTL. If another PC asks for www.example.com 600 seconds later, it receives the answer from the cache with a TTL of 3000 seconds. Referrals are cached too.
Negative answers are also kept: if a name does not exist, the authoritative server answers NXDOMAIN and the resolver remembers the result for the time set in the zone (RFC 2308). Caches exist in the resolver, in the operating system and often in the browser: after a change, some users keep seeing the old address until their copies expire. Before moving a service, it is wise to lower the TTL. On Windows, ipconfig /displaydns shows the local cache and ipconfig /flushdns clears it.
The main record types
A DNS zone is a set of resource records, each with a name, a type, a TTL and data. These are the types you meet most often.
| Type | What it contains | Example |
|---|---|---|
| A | IPv4 address of a name | www.example.com → 192.0.2.80 |
| AAAA | IPv6 address of a name (RFC 3596) | www.example.com → 2001:db8::80 |
| CNAME | Alias: points to another name, which must then be resolved | shop.example.com → www.example.com |
| MX | Mail servers of the domain, with a preference (the lowest value is preferred) | example.com → 10 mail.example.com |
| TXT | Free text, used for example for mail policies (SPF) and ownership checks | example.com → "v=spf1 mx -all" |
| NS | Authoritative servers of the zone; in the parent zone they create the delegation | example.com → ns1.example.com |
| PTR | Reverse lookup: from address to name | 80.2.0.192.in-addr.arpa → www.example.com |
A name that has a CNAME record cannot have any other records: that is why it is not used on the domain name itself, which has at least the NS records and the SOA record that opens every zone. Reverse lookups use a dedicated branch, in-addr.arpa for IPv4 and ip6.arpa for IPv6, in which the address is written backwards.
Port 53: UDP and TCP
DNS uses port 53. Ordinary queries travel over UDP, without a connection. The original DNS limited UDP responses to 512 bytes; the EDNS(0) extension (RFC 6891) allows larger ones. When a response still does not fit in the packet, the server truncates it by setting the TC flag and the client repeats the query over TCP, again on port 53. TCP is also used for zone transfers, and RFC 7766 makes its support mandatory: a rule that only allows UDP 53 causes errors that are hard to diagnose.
DNS inside the local network
In a well-organised network the clients use a local resolver, usually the router or the firewall. This gives a shared cache, a single point of control for DNS traffic and the ability to resolve local names, which do not exist on the Internet.
In OPNsense this role is usually played by Unbound DNS, a recursive resolver with caching and DNSSEC validation, configured under Services › Unbound DNS. In the overrides section (Overrides) you can define local names, for example nas.home.arpa → 192.168.1.50: the resolver answers directly, without asking the Internet. Unbound's options can also register automatically the names of the devices that receive their address from DHCP. Menus and options may change between versions: check the official documentation of the version you have installed.
For local names, use a domain that cannot clash with public ones: home.arpa is reserved for home networks (RFC 8375), or you can use a subdomain of a registered domain, such as lan.example.com. Avoid .local, which is reserved for multicast DNS (RFC 6762).
DNS and DHCP
How does a client know which resolver to use? The DHCP server tells it, together with the address, mask and gateway, through option 6 of RFC 2132; the local domain name travels in option 15. In IPv6 the same information arrives in Router Advertisement messages (RDNSS option, RFC 8106) or through DHCPv6. If DHCP hands out the wrong resolver, the device has a valid address but cannot resolve names.
“The network works, but websites don't”
The device has an IP address, but the browser cannot reach any website. If a ping to a known IP address works while nslookup www.example.com returns an error or a timeout, the fault lies with DNS. The most frequent causes:
- the client uses a wrong or stopped resolver: on Windows,
ipconfig /allshows the DNS server received from DHCP; - a firewall rule blocks port 53 between the client network and the resolver, or between the resolver and the Internet;
- the cache holds an old answer, for example after a service has moved;
- a local override or an entry in the
hostsfile points to a wrong address; - DNSSEC validation fails because the firewall's clock is far behind: signatures appear expired or not yet valid.
Privacy and security in brief
Classic DNS travels in clear text and without authentication. Anyone observing the network can see which names are requested, and an attacker can try to insert false answers into a resolver's cache (cache poisoning).
- DNSSEC (RFC 4033–4035) adds digital signatures to records. A validating resolver checks the chain of trust from the root down to the zone and discards altered answers. It provides authenticity and integrity, not confidentiality.
- DNS over TLS (DoT, RFC 7858) encrypts the queries between client and resolver in a TLS connection on port 853.
- DNS over HTTPS (DoH, RFC 8484) carries the queries inside HTTPS, on port 443, together with the rest of the web traffic.
DoT and DoH protect the path between the client and the resolver, but not the work the resolver does towards the authoritative servers. In companies there is one more effect to be aware of: a browser that uses DoH towards an external resolver bypasses the local resolver, with its overrides and its controls.
Tools: nslookup and dig
nslookup is available on Windows, Linux and macOS; dig, common on Linux and macOS, gives more detail. A few examples:
nslookup www.example.com: queries the configured resolver;nslookup -type=MX example.com: asks for the domain's mail servers;dig www.example.com AAAA: IPv6 address, with flags and TTL;dig @192.168.1.1 www.example.com: queries a specific resolver;dig +trace www.example.com: repeats the iterative path from the root, one referral at a time;dig -x 192.0.2.80: performs a reverse lookup (PTR).
Conclusions
DNS turns names into addresses through a delegated hierarchy, resolvers that follow referrals and a cache governed by the TTL. Knowing the record types, the local resolver and the link with DHCP helps you design tidy networks and recognise a fault quickly: when the network works but websites don't, the first suspect is DNS.
The video
Further reading
- Book: LOCAL AREA NETWORKS (LAN) — Volume 2: IP Addressing and Network Services (English edition)
- Book: LOCAL AREA NETWORKS (LAN) — Volume 4: Routing, NAT, and Internet Access (English edition)
- Book: OPNsense® in Practice — Volume 1: The Foundations of a Professional Journey (English edition)
- Video course: Reti LAN da Zero: Switch, IP, Router, Wi-Fi e Internet (video course in Italian)
- Video course: Capire i Firewall con OPNsense (video course in Italian)
- Related article: DHCP: How a Device Gets Its IP Address
- Related article: IP Address and Subnet Mask: How to Tell Which Network a Device Is On
- Related article: NAT and Port Forwarding: How a Private Network Talks to the Internet
- Specialization: LAN Networks
Technical sources
- RFC 1034 e RFC 1035 — Domain Names: Concepts and Facilities; Implementation and Specification — Definition of DNS: hierarchical name space, zones and delegation, resolvers, recursive and iterative queries, resource records (A, CNAME, MX, NS, PTR, SOA, TXT), TTL, port 53 over UDP and TCP, the 512-byte limit and the RD, AA and TC flags.
- RFC 2308, RFC 3596, RFC 6891 e RFC 7766 — Negative caching (NXDOMAIN), AAAA records for IPv6, the EDNS(0) extension for larger UDP responses, mandatory support for TCP transport.
- RFC 4033, RFC 4034 e RFC 4035 — DNS Security Extensions (DNSSEC) — Digital signatures on records and a chain of trust checked by validating resolvers: authenticity and integrity, not confidentiality.
- RFC 7858 e RFC 8484 — DNS over TLS e DNS over HTTPS — Encryption of queries between client and resolver: TLS on port 853 (DoT) and HTTPS on port 443 (DoH).
- RFC 2132, RFC 8106, RFC 8375 e RFC 6762 — DHCP options 6 (DNS servers) and 15 (domain name), the RDNSS option of IPv6 Router Advertisements, the home.arpa domain for home networks, .local reserved for multicast DNS.
- RFC 2606, RFC 6761, RFC 5737, RFC 3849 e RFC 1918 — Names and addresses used in the examples: example.com reserved for documentation, 192.0.2.0/24 and 203.0.113.0/24 (RFC 5737), 2001:db8::/32 (RFC 3849) and the private network 192.168.1.0/24.
- Documentazione ufficiale di OPNsense — Unbound DNS — Recursive resolver with caching and DNSSEC validation under Services › Unbound DNS, overrides for local names and registration of DHCP names; menus and options depend on the version.
Standards and official documentation available from the respective organisations.