Lessons

DNS Fundamentals

Level: Intermediate Module: TCP/IP & Networking 7 min read Lesson 16 of 66

Overview

  • What you’ll learn: How DNS works, the DNS hierarchy (root, TLD, authoritative), common record types (A, AAAA, CNAME, MX, NS, TXT, SOA, PTR), recursive vs iterative queries, caching, and tools for DNS troubleshooting.
  • Prerequisites: Lesson 15 – Network Configuration with Netplan
  • Estimated reading time: 22 minutes

Introduction

The Domain Name System (DNS) is often called the “phonebook of the Internet.” It translates human-friendly domain names like www.example.com into the IP addresses that computers use to identify each other on a network. Without DNS, you would have to memorize IP addresses for every website and service you use.

DNS is a distributed, hierarchical database that spans the entire Internet. It is one of the most critical infrastructure services — if DNS fails, virtually all Internet services become inaccessible. Understanding DNS is essential for Linux system administrators because misconfigured DNS is one of the most common causes of network connectivity issues.

In this lesson, you will learn how the DNS hierarchy is structured, what happens during a DNS query, the different record types, and how to use command-line tools to query and troubleshoot DNS on Ubuntu.

The DNS Hierarchy

DNS is organized as an inverted tree structure with the root at the top. Each level in the hierarchy is responsible for a specific portion of the domain name space.

  • Root zone (.): The top of the DNS tree. There are 13 root server clusters (a.root-servers.net through m.root-servers.net) distributed globally via anycast.
  • Top-Level Domains (TLDs): The first level below root — .com, .org, .net, .tw, .jp, and hundreds more. Managed by registry operators (e.g., Verisign for .com).
  • Second-Level Domains: Registered by organizations — example.com, topgiga.tw. Managed by the domain owner.
  • Subdomains: Further divisions created by the domain owner — www.example.com, mail.example.com.
# The FQDN (Fully Qualified Domain Name) includes a trailing dot
# representing the root zone:
# www.example.com.
#  |      |     |  |
#  |      |     |  └─ Root zone (.)
#  |      |     └──── TLD (.com)
#  |      └────────── Second-level domain (example)
#  └───────────────── Subdomain (www)

# Query the root servers
$ dig . NS +short
a.root-servers.net.
b.root-servers.net.
c.root-servers.net.
d.root-servers.net.
e.root-servers.net.

# Query the TLD servers for .com
$ dig com. NS +short
a.gtld-servers.net.
b.gtld-servers.net.

How DNS Resolution Works

When your application needs to resolve a domain name, a series of queries takes place. The process involves a stub resolver on your machine, a recursive resolver (usually your ISP or a service like 8.8.8.8), and multiple authoritative name servers.

The recursive resolver does the heavy lifting: it queries the root servers to find the TLD servers, queries the TLD servers to find the authoritative servers, and queries the authoritative servers to get the final answer. Each response may be cached according to its TTL (Time to Live) to reduce future query times.

# Trace the full resolution path for a domain
$ dig +trace www.example.com
;; Received 525 bytes from 127.0.0.53 in 0 ms

.                       518400  IN  NS  a.root-servers.net.
com.                    172800  IN  NS  a.gtld-servers.net.
example.com.            172800  IN  NS  a.iana-servers.net.
www.example.com.        86400   IN  A   93.184.216.34

# Check what DNS server your system is using
$ resolvectl status
Global
    DNS Servers: 192.168.1.1
    DNS Domain: ~.

Link 2 (ens33)
    Current Scopes: DNS
    DNS Servers: 8.8.8.8
                 8.8.4.4

DNS Record Types

DNS stores information in resource records (RRs). Each record has a name, type, class, TTL, and data. The most important record types are:

# A Record — Maps a name to an IPv4 address
$ dig example.com A +short
93.184.216.34

# AAAA Record — Maps a name to an IPv6 address
$ dig example.com AAAA +short
2606:2800:220:1:248:1893:25c8:1946

# CNAME Record — Alias; points one name to another
$ dig www.example.com CNAME +short
example.com.

# MX Record — Mail exchange servers (with priority)
$ dig example.com MX +short
10 mail.example.com.
20 mail2.example.com.

# NS Record — Authoritative name servers for a zone
$ dig example.com NS +short
a.iana-servers.net.
b.iana-servers.net.

# TXT Record — Arbitrary text (used for SPF, DKIM, verification)
$ dig example.com TXT +short
"v=spf1 -all"

# SOA Record — Start of Authority (zone metadata)
$ dig example.com SOA +short
ns.icann.org. noc.dns.icann.org. 2024010101 7200 3600 1209600 3600

# PTR Record — Reverse DNS (IP to name)
$ dig -x 93.184.216.34 +short
93.184.216.34.

DNS Configuration on Ubuntu

Ubuntu uses systemd-resolved as its local DNS stub resolver. It listens on 127.0.0.53 and forwards queries to upstream DNS servers configured via Netplan or DHCP. Understanding how systemd-resolved works is important for troubleshooting DNS issues.

# Check systemd-resolved status
$ resolvectl status
Global
    Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
    DNS Servers: 192.168.1.1

# Test DNS resolution
$ resolvectl query www.example.com
www.example.com: 93.184.216.34
                 2606:2800:220:1:248:1893:25c8:1946

# View the DNS cache statistics
$ resolvectl statistics
DNSSEC supported by current servers: no
Transactions
  Current:   0
  Total:     1234
Cache
  Current Size: 45
  Cache Hits:   890
  Cache Misses: 344

# Flush the DNS cache
$ sudo resolvectl flush-caches

# The /etc/resolv.conf file (symlinked to systemd-resolved)
$ cat /etc/resolv.conf
# This is /run/systemd/resolve/stub-resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad
search localdomain

DNS Troubleshooting Tools

Linux provides several powerful tools for querying and debugging DNS issues. The most commonly used are dig, nslookup, and host.

# dig — the most detailed DNS query tool
$ dig www.example.com
;; ANSWER SECTION:
www.example.com.    86400   IN  A   93.184.216.34

;; Query time: 23 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)

# Query a specific DNS server
$ dig @8.8.8.8 www.example.com

# nslookup — interactive or non-interactive DNS queries
$ nslookup www.example.com
Server:     127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
Name:   www.example.com
Address: 93.184.216.34

# host — simplified DNS lookup
$ host www.example.com
www.example.com has address 93.184.216.34
www.example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946

# Check for DNS propagation issues
$ dig +short @a.iana-servers.net example.com A
93.184.216.34
$ dig +short @b.iana-servers.net example.com A
93.184.216.34

Key Takeaways

  • DNS is a distributed, hierarchical system that translates domain names to IP addresses; it is one of the most critical Internet infrastructure services.
  • The DNS hierarchy consists of root servers, TLD servers, and authoritative name servers; recursive resolvers query these on behalf of clients.
  • Common record types include A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), NS (name server), TXT (text), SOA (zone metadata), and PTR (reverse).
  • Ubuntu uses systemd-resolved as its local DNS stub resolver, listening on 127.0.0.53 and forwarding to upstream servers.
  • Use dig for detailed DNS queries, resolvectl for managing systemd-resolved, and resolvectl flush-caches to clear the DNS cache.

What’s Next

In Lesson 17, you will learn how to set up a BIND 9 DNS Server — deploying your own authoritative DNS server on Ubuntu to host zones and resolve queries for your domain.

繁體中文

概述

  • 學習目標:DNS 的運作方式、DNS 層級結構(根伺服器、TLD、授權伺服器)、常見記錄類型(A、AAAA、CNAME、MX、NS、TXT、SOA、PTR)、遞迴與迭代查詢、快取,以及 DNS 排除問題的工具。
  • 先決條件:第 15 課 – 使用 Netplan 進行網路設定
  • 預計閱讀時間:22 分鐘

簡介

網域名稱系統(DNS)常被稱為「網際網路的電話簿」。它將人類友好的網域名稱(如 www.example.com)轉換為電腦用於在網路上互相識別的 IP 位址。沒有 DNS,您就必須記住每個使用的網站和服務的 IP 位址。

DNS 是一個跨越整個網際網路的分散式、階層式資料庫。它是最關鍵的基礎設施服務之一——如果 DNS 失敗,幾乎所有的網際網路服務都變得無法存取。了解 DNS 對 Linux 系統管理員來說至關重要,因為 DNS 設定錯誤是網路連線問題最常見的原因之一。

在本課程中,您將學習 DNS 層級結構如何組織、DNS 查詢過程中發生了什麼、不同的記錄類型,以及如何使用命令列工具在 Ubuntu 上查詢和排除 DNS 問題。

DNS 層級結構

DNS 以倒置樹狀結構組織,根在頂部。層級中的每一層負責網域名稱空間的特定部分。

  • 根域(.):DNS 樹的頂部。全球有 13 個根伺服器叢集,透過任播分布。
  • 頂級域(TLD):根以下的第一層——.com、.org、.net、.tw、.jp 等。
  • 二級域:由組織註冊——example.com、topgiga.tw。由網域擁有者管理。
  • 子域:由網域擁有者建立的進一步劃分——www.example.com、mail.example.com。

DNS 解析的運作方式

當您的應用程式需要解析網域名稱時,會進行一系列查詢。此過程涉及您機器上的存根解析器遞迴解析器(通常是您的 ISP 或如 8.8.8.8 的服務)和多個授權名稱伺服器

遞迴解析器執行主要工作:它查詢根伺服器以找到 TLD 伺服器,查詢 TLD 伺服器以找到授權伺服器,然後查詢授權伺服器以獲得最終答案。每個回應可能根據其 TTL(存活時間)被快取,以減少未來的查詢時間。

DNS 記錄類型

DNS 將資訊儲存在資源記錄(RR)中。每條記錄都有名稱、類型、類別、TTL 和資料。最重要的記錄類型包括:A(IPv4)、AAAA(IPv6)、CNAME(別名)、MX(郵件交換)、NS(名稱伺服器)、TXT(文字)、SOA(授權開始)和 PTR(反向)。

Ubuntu 上的 DNS 設定

Ubuntu 使用 systemd-resolved 作為其本地 DNS 存根解析器。它監聽 127.0.0.53 並將查詢轉發到透過 Netplan 或 DHCP 設定的上游 DNS 伺服器。了解 systemd-resolved 的工作方式對排除 DNS 問題很重要。

DNS 排除問題工具

Linux 提供了多種強大的工具來查詢和除錯 DNS 問題。最常用的是 dignslookuphost

重要觀念

  • DNS 是一個將網域名稱轉換為 IP 位址的分散式、階層式系統;它是最關鍵的網際網路基礎設施服務之一。
  • DNS 層級結構由根伺服器、TLD 伺服器和授權名稱伺服器組成;遞迴解析器代表用戶端查詢這些伺服器。
  • 常見記錄類型包括 A(IPv4)、AAAA(IPv6)、CNAME(別名)、MX(郵件)、NS(名稱伺服器)、TXT(文字)、SOA(區域中繼資料)和 PTR(反向)。
  • Ubuntu 使用 systemd-resolved 作為本地 DNS 存根解析器,監聽 127.0.0.53 並轉發到上游伺服器。
  • 使用 dig 進行詳細的 DNS 查詢,使用 resolvectl 管理 systemd-resolved,使用 resolvectl flush-caches 清除 DNS 快取。

下一步

在第 17 課中,您將學習如何設定 BIND 9 DNS 伺服器——在 Ubuntu 上部署您自己的授權 DNS 伺服器來託管區域並解析您網域的查詢。

日本語

概要

  • 学習内容:DNSの仕組み、DNS階層(ルート、TLD、権威サーバー)、一般的なレコードタイプ(A、AAAA、CNAME、MX、NS、TXT、SOA、PTR)、再帰クエリと反復クエリ、キャッシュ、DNSトラブルシューティングツール。
  • 前提条件:レッスン15 – Netplanによるネットワーク設定
  • 推定読了時間:22分

はじめに

ドメインネームシステム(DNS)は「インターネットの電話帳」と呼ばれることがよくあります。www.example.comのような人間に分かりやすいドメイン名を、コンピュータがネットワーク上で互いを識別するために使用するIPアドレスに変換します。DNSがなければ、使用するすべてのウェブサイトやサービスのIPアドレスを暗記する必要があります。

DNSはインターネット全体にまたがる分散型の階層データベースです。最も重要なインフラストラクチャサービスの1つであり、DNSが失敗すると事実上すべてのインターネットサービスにアクセスできなくなります。DNSの理解はLinuxシステム管理者にとって不可欠です。なぜなら、DNSの設定ミスはネットワーク接続問題の最も一般的な原因の1つだからです。

このレッスンでは、DNS階層の構造、DNSクエリ中に何が起こるか、さまざまなレコードタイプ、UbuntuでのDNSのクエリとトラブルシューティングにコマンドラインツールを使用する方法を学びます。

DNS階層

DNSはルートを頂点とする逆ツリー構造で組織されています。階層の各レベルはドメイン名前空間の特定の部分を担当しています。

  • ルートゾーン(.):DNSツリーの頂点。13のルートサーバークラスターがエニーキャストでグローバルに分散されています。
  • トップレベルドメイン(TLD):ルートの下の最初のレベル——.com、.org、.net、.tw、.jpなど。
  • セカンドレベルドメイン:組織によって登録——example.com、topgiga.tw。ドメインオーナーが管理。
  • サブドメイン:ドメインオーナーが作成するさらなる分割——www.example.com、mail.example.com。

DNS解決の仕組み

アプリケーションがドメイン名を解決する必要があるとき、一連のクエリが行われます。このプロセスには、マシン上のスタブリゾルバ再帰リゾルバ(通常はISPまたは8.8.8.8のようなサービス)、複数の権威ネームサーバーが関与します。

再帰リゾルバが主要な作業を行います:ルートサーバーにTLDサーバーを問い合わせ、TLDサーバーに権威サーバーを問い合わせ、権威サーバーに最終的な回答を問い合わせます。各応答はTTL(生存時間)に従ってキャッシュされ、将来のクエリ時間を短縮します。

DNSレコードタイプ

DNSはリソースレコード(RR)に情報を格納します。各レコードには名前、タイプ、クラス、TTL、データがあります。最も重要なレコードタイプは:A(IPv4)、AAAA(IPv6)、CNAME(エイリアス)、MX(メール交換)、NS(ネームサーバー)、TXT(テキスト)、SOA(ゾーンメタデータ)、PTR(逆引き)です。

UbuntuでのDNS設定

Ubuntuはローカルのスタブリゾルバとしてsystemd-resolvedを使用しています。127.0.0.53でリッスンし、NetplanまたはDHCP経由で設定された上流DNSサーバーにクエリを転送します。systemd-resolvedの仕組みを理解することは、DNS問題のトラブルシューティングに重要です。

DNSトラブルシューティングツール

Linuxは、DNSの問題をクエリおよびデバッグするための強力なツールをいくつか提供しています。最もよく使用されるのはdignslookuphostです。

重要ポイント

  • DNSはドメイン名をIPアドレスに変換する分散型の階層システムであり、最も重要なインターネットインフラストラクチャサービスの1つです。
  • DNS階層はルートサーバー、TLDサーバー、権威ネームサーバーで構成され、再帰リゾルバがクライアントに代わってこれらにクエリを送信します。
  • 一般的なレコードタイプにはA(IPv4)、AAAA(IPv6)、CNAME(エイリアス)、MX(メール)、NS(ネームサーバー)、TXT(テキスト)、SOA(ゾーンメタデータ)、PTR(逆引き)があります。
  • UbuntuはローカルDNSスタブリゾルバとしてsystemd-resolvedを使用し、127.0.0.53でリッスンして上流サーバーに転送します。
  • 詳細なDNSクエリにはdig、systemd-resolvedの管理にはresolvectl、DNSキャッシュのクリアにはresolvectl flush-cachesを使用します。

次のステップ

レッスン17では、BIND 9 DNSサーバーのセットアップ方法を学びます——ゾーンをホストしドメインのクエリを解決するために、Ubuntu上に独自の権威DNSサーバーをデプロイします。

You Missed