Fundamentals 14 min read

Master DNS: From Basics to Advanced Queries with dig

This article explains the fundamentals of the Domain Name System, demonstrates how to use the dig tool to view detailed query processes, explores DNS record types, hierarchical lookups, root servers, and additional utilities like host, nslookup, and whois, providing a comprehensive guide for developers and network engineers.

Open Source Linux
Open Source Linux
Open Source Linux
Master DNS: From Basics to Advanced Queries with dig

DNS is one of the core Internet protocols; understanding its basics is essential for browsing and development.

一、DNS 是什么?

DNS (Domain Name System) translates domain names to IP addresses, acting like a massive phone book. For example, math.stackexchange.com resolves to 151.101.129.69.

二、查询过程

The DNS query involves multiple steps, which can be displayed using the dig tool. $ dig math.stackexchange.com The command outputs six sections: query parameters, query content, server responses, NS records, server IPs, and transmission details.

Using +short simplifies the output to just the IP addresses. $ dig +short math.stackexchange.com Result: four A records for the domain.

三、DNS服务器

The local machine must know the DNS server IP, typically configured in /etc/resolv.conf. DNS servers can be dynamic (via DHCP) or static, e.g., Google’s 8.8.8.8 or Level 3’s 4.2.2.2.

$ dig @4.2.2.2 math.stackexchange.com

四、域名的层级

Domain names have a hierarchical structure: host.sld.tld.root. The root zone is implicit, and the top‑level domain (TLD) follows, then the second‑level domain (SLD), and finally the host.

host.sld.tld.root

五、根域名服务器

Root servers store NS records for each TLD. There are thirteen root server groups (A‑M) with fixed IPs.

六、分级查询的实例

Using dig +trace shows the full hierarchical lookup from root servers to the final A records.

$ dig +trace math.stackexchange.com

七、NS 记录的查询

Specific NS records can be queried with:

$ dig ns com
$ dig ns stackexchange.com

Adding +short yields concise results.

$ dig +short ns com
$ dig +short ns stackexchange.com

八、DNS的记录类型

Common DNS record types include:

A – address record (IP address)

NS – name server record

MX – mail exchange record

CNAME – canonical name (alias)

PTR – reverse lookup record

CNAME provides domain aliasing, while PTR enables reverse lookups, useful for spam prevention.

$ dig facebook.github.io
$ dig -x 192.30.252.153

九、其他DNS工具

Additional utilities:

host – simplified dig, shows all records.

nslookup – interactive query tool.

whois – displays domain registration information.

十、参考文章

DNS: The Good Parts, by Pete Keen

DNS 101, by Mark McDonnell

附:DNS百科

DNS maps domain names to IP addresses, operating over UDP on port 53. It supports static and dynamic mappings, hierarchical queries, and various record types, with security considerations such as DDoS attacks, hijacking, and misconfigurations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxDNSDomain Name Systemdig
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.