DNS工具

本文介绍了四种常用的DNS查询工具:host命令、nslookup命令、whois命令及dig命令。通过这些工具,用户可以查询域名解析记录、域名注册信息等关键数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(1)host 命令

host命令可以看作dig命令的简化版本,返回当前请求域名的各种记录。

$ host github.com

github.com has address 192.30.252.121
github.com mail is handled by 5 ALT2.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 10 ALT4.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 10 ALT3.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 5 ALT1.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 1 ASPMX.L.GOOGLE.COM.
$ host facebook.github.com

facebook.github.com is an alias for github.map.fastly.net.
github.map.fastly.net has address 103.245.222.133

host命令也可以用于逆向查询,即从IP地址查询域名,等同于dig -x 。

$ host 192.30.252.153

153.252.30.192.in-addr.arpa domain name pointer pages.github.com.

(2)nslookup 命令

nslookup命令用于互动式地查询域名记录。

➜  dist git:(dev) ✗ nslookup www.baidu.com
Server:     10.39.1.10
Address:    10.39.1.10#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 220.181.112.244
Name:   www.a.shifen.com
Address: 220.181.111.188

(3)whois 命令

whois命令用来查看域名的注册情况。

➜  dist git:(dev) ✗ whois github.com
   Domain Name: GITHUB.COM
   Registry Domain ID: 1264983250_DOMAIN_COM-VRSN
   Registrar WHOIS Server: whois.markmonitor.com
   Registrar URL: http://www.markmonitor.com
   Updated Date: 2017-06-26T16:02:39Z
   Creation Date: 2007-10-09T18:20:50Z
   Registry Expiry Date: 2020-10-09T18:20:50Z
   Registrar: MarkMonitor Inc.
   Registrar IANA ID: 292
   Registrar Abuse Contact Email: abusecomplaints@markmonitor.com
   Registrar Abuse Contact Phone: +1.2083895740
   Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
   Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
   Name Server: NS-1283.AWSDNS-32.ORG
   Name Server: NS-1707.AWSDNS-21.CO.UK
   Name Server: NS-421.AWSDNS-52.COM
   Name Server: NS-520.AWSDNS-01.NET
   Name Server: NS1.P16.DYNECT.NET
   Name Server: NS2.P16.DYNECT.NET
   Name Server: NS3.P16.DYNECT.NET
   Name Server: NS4.P16.DYNECT.NET
   DNSSEC: unsigned
   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
>>> Last update of whois database: 2017-10-16T01:40:30Z <<<

For more information on Whois status codes, please visit https://icann.org/epp

NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar.  Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.

TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability.  VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.

The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.

(4)dig 命令

➜  dist git:(dev) ✗ dig www.baidu.com 

; <<>> DiG 9.8.3-P1 <<>> www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39734
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.baidu.com.         IN  A

;; ANSWER SECTION:
www.baidu.com.      528 IN  CNAME   www.a.shifen.com.
www.a.shifen.com.   528 IN  A   220.181.111.188
www.a.shifen.com.   528 IN  A   220.181.112.244

;; Query time: 22 msec
;; SERVER: 10.39.1.10#53(10.39.1.10)
;; WHEN: Mon Oct 16 09:41:54 2017
;; MSG SIZE  rcvd: 90

参考文章
http://www.ruanyifeng.com/blog/2016/06/dns.html

### 常见的 DNS 工具推荐 以下是几款常见的 DNS 工具及其功能描述: #### 1. **nslookup** `nslookup` 是一个基本的命令行工具,用于查询 Internet 域名服务 (DNS) 的信息。它可以用来查找域名对应的 IP 地址或者反向解析 IP 地址为域名。此工具适合快速验证简单的 DNS 解析问题。 ```bash nslookup example.com ``` 该工具适用于初学者和技术人员日常排查网络连接问题时使用[^1]。 --- #### 2. **dig** `dig`(Domain Information Groper)是一个更强大且灵活的 DNS 查找工具,相比 `nslookup` 提供了更多的选项和详细的输出信息。它支持多种记录类型的查询,例如 A、MX、TXT 和 SOA 等,并能显示完整的 DNS 查询过程细节。 ```bash dig +short TXT example.com ``` 对于需要深入了解 DNS 配置或调试复杂问题的人来说,这是一个不可或缺的工具。 --- #### 3. **nscd** 名称服务缓存守护进程 (`nscd`) 可以加速名字服务请求的速度,比如主机名到 IP 地址的转换。通过减少重复查询外部 DNS 服务器的需求,`nscd` 能够显著提高本地系统的性能。 配置文件通常位于 `/etc/nscd.conf` 中,管理员可以根据需求调整其行为设置。 --- #### 4. **systemd-resolved** 作为现代 Linux 发行版的一部分,`systemd-resolved` 提供了一个集成式的 DNS 缓存和服务发现机制。它不仅能够处理传统的 DNS 请求,还支持 mDNS 和 LLMNR 协议,在局域网内的设备间实现无缝通信。 要查看当前使用的 DNS 服务器列表,可以运行以下命令: ```bash resolvectl status ``` 这款工具特别适配基于 systemd 的操作系统环境。 --- #### 5. **BIND** Berkeley Internet Name Domain (BIND) 是最广泛部署的 DNS 实现之一。除了充当权威 DNS 服务器外,还可以配置成递归解析器来满足内部用户的查询需求。由于其高度可定制性和稳定性,许多企业和机构都依赖 BIND 来构建自己的 DNS 架构。 启动 BIND 服务可能涉及编辑主配置文件 `/etc/named.conf` 并确保防火墙允许必要的端口流量。 --- #### 6. **DNSdiag** 这是一套专门设计用于诊断各种 DNS 故障场景的强大工具集合。其中包括但不限于以下几个子模块: - **dnsping**: 测量不同目标之间的平均响应时间; - **dnstraceroute**: 追踪从客户端到指定域名所经过的所有中间节点; - **dnseval**: 对多个远程 DNS 服务器执行一致性检查和其他高级测试。 示例用法如下所示: ```bash dnsping google-public-dns-a.google.com ``` 开发者 Babak Farrokhi 将该项目开源以便社区贡献改进[^2]。 --- #### 7. **dnsspoof** 虽然主要用于教育目的演示潜在的安全威胁模型,但 `dnsspoof` 同样值得提及因为它揭示了如何利用 DNS 欺骗技术篡改合法的数据交换流程。借助 ARP 欺诈或其他方法捕获未加密传输中的敏感信息成为可能。 注意:仅限授权环境下学习用途!非法操作可能导致法律责任风险。 ```python from scapy.all import * def dns_spoof(pkt): ... sniff(filter="udp port 53", prn=dns_spoof) ``` 上述脚本片段展示了基础框架逻辑[^4]。 --- ### 结论 以上列举了几种主流的 DNS 相关工具,每种都有各自的特点和适用范围。具体选择哪一种取决于实际应用场景和个人偏好等因素。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值