DNS network troubleshooting commands dig&nslookup

一、you

  • dig information
    The dig command stands for Domain Information Explorer. It is a network management command line tool for querying the Domain Name System (DNS). The dig command is useful for network troubleshooting and educational purposes. It can operate based on command line options and flag arguments, or in batch mode by reading requests from operating system files. When a specific nameserver is not specified in the command call, it uses the operating system's default resolver, typically configured in the file resolv.conf. Without any parameters, it queries the DNS root zone.

  • dig use

# dig  www.baidu.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.14 <<>> www.baidu.com
;; global options: +cmd

=====================================================================
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1682
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

=====================================================================

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com.                 IN      A

=====================================================================

;; ANSWER SECTION:
www.baidu.com.          276     IN      CNAME   www.a.shifen.com.
www.a.shifen.com.       12      IN      CNAME   www.wshifen.com.
www.wshifen.com.        188     IN      A       45.113.192.102
www.wshifen.com.        188     IN      A       45.113.192.101

=====================================================================

;; Query time: 0 msec
;; SERVER: 172.31.0.2#53(172.31.0.2)
;; WHEN: Sun Oct 01 03:29:24 UTC 2023
;; MSG SIZE  rcvd: 127

  • return explanation
第一部分显示 dig 命令的版本和输入的参数。
第二部分显示服务返回的一些技术详情,比较重要的是 status。如果 status 的值为 NOERROR 则说明本次查询成功结束。
第三部分中的 "QUESTION SECTION" 显示我们要查询的域名。
第四部分的 "ANSWER SECTION" 是查询到的结果。
第五部分则是本次查询的一些统计信息,比如用了多长时间,查询了哪个 DNS 服务器,在什么时间进行的查询等等。

默认情况下 dig 命令查询 A 记录,上图中显示的 A 即说明查询的记录类型为 A 记录。在尝试查询其它类型的记录前让我们先来了解一下常见的 DNS 记录类型。

2. nslookup

  • nslookup information

nslookup is a network management command-line tool available in many computer operating systems that queries the Domain Name System (DNS) for domain name or IP address mappings or other DNS records. The name "nslookup" means "name server lookup".

This command does not use the operating system's native Domain Name System resolver library to perform its queries, so its behavior may differ from dig. In addition, vendor-provided versions may include output from other sources of name information, such as hosts files and network information services. Some behaviors of nslookup may be modified by the contents of resolv.conf.

  • nslookup use

You can use nslookup in command line mode or interactive mode. In the first example, the command prints the output and returns to the system prompt. In the second example, issuing nslookup alone will take the user to a command prompt where command-specific input can be entered.

#  nslookup www.baidu.com 8.8.8.8
Server:         8.8.8.8
Address:        8.8.8.8#53

非权威答案:
Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 14.119.104.254
Name:   www.a.shifen.com
Address: 14.119.104.189
www.a.shifen.com        canonical name = www.wshifen.com.


# nslookup
>  www.baidu.com 
Server:         172.31.0.2
Address:        172.31.0.2#53

非权威答案:
Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
www.a.shifen.com        canonical name = www.wshifen.com.
Name:   www.wshifen.com
Address: 45.113.192.101
Name:   www.wshifen.com
Address: 45.113.192.102

3. Command installation

dig is the same as nslookup command

Ubuntu:

apt-get install dnsutils

Debian:

apt-get update
apt-get install dnsutils

Centos:

yum install bind-utils

4. Common types of DNS records

  • A record - A record that holds a domain's IP address.
  • AAAA record - A record that contains the IPv6 address of a domain (as opposed to an A record, which lists IPv4 addresses).
  • CNAME record - forwards one domain or subdomain to another domain without providing an IP address.
  • MX records - direct mail to the email server.
  • TXT records - Allows administrators to store text comments in records. These records are often used for email security.
  • NS records - Name servers that store DNS entries.
  • SOA record - Stores management information for a domain.
  • SRV Record - Specifies the port used for a specific service.
  • PTR record - Provides domain names in reverse lookups.

Guess you like

Origin blog.csdn.net/cljdsc/article/details/133460461