Linux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命令类似。linux命令在系统中有两种类型:内置Shell命令和Linux命令。本文主要介绍Linux host 命令。

1、命令简介

host:用于查询 DNS(域名系统)服务器以获取主机名(域名)对应的 IP 地址或反向查询,即通过 IP 地址查找对应的主机名。

2、命令语法

host [-aCdlnrsTwv] [-c class] [-N ndots] [-R number] [-t type] [-W wait] [-m flag] [-4] [-6] {name} [server]

3、命令描述

host 是一个用于执行 DNS 查询的简单实用工具。通常用于将名称转换为 IP 地址,反之亦然。

当没有提供任何参数或选项时,host 将打印其命令行参数和选项的简短摘要。

4、命令选项

选项

描述

-a

-a(all)选项等效于设置 -v 选项,

并要求 host 执行 ANY 类型的查询。

-C

当使用 -C 选项时,

host 将尝试显示区域名的所有权威名称服务器的 SOA 记录。

名称服务器列表

由为该区域找到的 NS 记录定义。

-c class

-c 选项指示 host 进行类别为 class 的 DNS 查询。这可以用于查找 Hesiod

或 Chaosnet 类别的资源记录。

默认类别为 IN(互联网)。

-d

使用 -d 或 -v 选项时,

host 会生成详细输出。

这两个选项是等效的。

它们是为了向后兼容而提供的。

在以前的版本中,

-d 选项开启了调试跟踪,

-v 选项启用了详细输出。

-l

通过 -l 选项选择列表模式。

这使 host 为区域名称执行区域传输。

传输区域并打印出 NS、PTR 和地址记录(A/AAAA)。如果与 -a 结合使用,

将打印出所有记录。

-i

-i 选项指定反向查找 IPv6 地址时

应使用 RFC1886 中定义的 IP6.INT 域。

默认情况下,使用 IP6.ARPA。

-N ndots

-N 选项设置在名称中

必须有多少个点才能被视为绝对名称。

-R number

可以通过 -r 选项进行非递归查询。

设置此选项会清除 host 进行

查询时的 RD("递归期望")位。

-T

host 在进行查询时默认使用 UDP。

-T 选项使其在查询名称服务器时使用 TCP 连接。

对于需要使用 TCP 的查询

(例如区域传输(AXFR)请求),

将自动选择 TCP。

-4

-4 选项强制 host 仅使用 IPv4 查询传输。

-6

-6 选项强制 host 仅使用 IPv6 查询传输。

-s

-s 选项告诉 host

如果任何服务器响应 SERVFAIL 响应,

则不要将查询发送到下一个名称服务器,

这与正常的存根解析器行为相反。

-m flag

-m 可用于设置内存使用调试标志记录、

使用和跟踪。

-6

-6 选项强制 host 仅使用 IPv6 查询传输。

5、使用示例

1)对于任意站点,例如 google.com,使用 sitename 进行简单查询

$ host google.com

输出:

google.com has address 172.217.26.174
google.com has IPv6 address 2404:6800:4007:801::200e
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.

2)使用 IP 地址进行 host 查询

$ host 172.217.26.174

输出:

174.26.217.172.in-addr.arpa domain name pointer maa03s22-in-f14.1e100.net.

3)显示 google.com 域的 MX 记录

$ host -n -t mx google.com

输出:

#  host -n -t mx google.com
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.

4)查找 google.com 域的域名服务器

$ host -t ns google.com

output:
# host -t ns google.com
google.com name server ns3.google.com.
google.com name server ns1.google.com.
google.com name server ns2.google.com.
google.com name server ns4.google.com.

5)查找 google.com 域的 TXT 记录

$ host -t txt google.com

输出:

google.com descriptive text "v=spf1 include:_spf.google.com ~all"

6)查找 google.com 域的 SOA 记录

$ host -t soa google.com

输出:

google.com has SOA record ns4.google.com. dns-admin.google.com. 143179694 900 900 1800 60

7)查询特定的名称服务器

$ host google.com ns4.google.com

输出:

Using domain server:
Name: ns4.google.com
Address: 216.239.38.10#53
Aliases:

google.com has address 216.58.196.110
google.com has IPv6 address 2404:6800:4007:806::200e
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.

8)显示有关域记录和区域的所有信息

$ host -a amazon.in

output:
Trying "amazon.in"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26969
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 7, ADDITIONAL: 12

;; QUESTION SECTION:
;amazon.in.                     IN      ANY

;; ANSWER SECTION:
amazon.in.              5       IN      A       178.236.7.18
amazon.in.              5       IN      A       54.239.32.8
amazon.in.              5       IN      A       54.239.34.40

;; AUTHORITY SECTION:
in.                     5       IN      NS      c0.in.afilias-nst.info.
in.                     5       IN      NS      a2.in.afilias-nst.info.
in.                     5       IN      NS      b2.in.afilias-nst.org.
in.                     5       IN      NS      a0.in.afilias-nst.info.
in.                     5       IN      NS      b1.in.afilias-nst.in.
in.                     5       IN      NS      b0.in.afilias-nst.org.
in.                     5       IN      NS      a1.in.afilias-nst.in.

;; ADDITIONAL SECTION:
a0.in.afilias-nst.info. 5       IN      A       199.7.87.1
a0.in.afilias-nst.info. 5       IN      AAAA    2001:500:29::1
a1.in.afilias-nst.in.   5       IN      A       115.249.164.142
a2.in.afilias-nst.info. 5       IN      A       199.249.117.1
a2.in.afilias-nst.info. 5       IN      AAAA    2001:500:45::1
b0.in.afilias-nst.org.  5       IN      A       199.253.56.1
b0.in.afilias-nst.org.  5       IN      AAAA    2001:500:50::1
b1.in.afilias-nst.in.   5       IN      A       180.179.215.70
b1.in.afilias-nst.in.   5       IN      AAAA    2401:8800:411:8::70
b2.in.afilias-nst.org.  5       IN      A       199.249.125.1
b2.in.afilias-nst.org.  5       IN      AAAA    2001:500:4d::1
c0.in.afilias-nst.info. 5       IN      A       199.253.57.1

Received 498 bytes from 192.168.134.2#53 in 498 ms

9)获取 TTL 信息

$ host -v -t a google.com

output:
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37908
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 4

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             5       IN      A       172.217.26.174

;; AUTHORITY SECTION:
google.com.             5       IN      NS      ns2.google.com.
google.com.             5       IN      NS      ns4.google.com.
google.com.             5       IN      NS      ns1.google.com.
google.com.             5       IN      NS      ns3.google.com.

;; ADDITIONAL SECTION:
ns1.google.com.         5       IN      A       216.239.32.10
ns2.google.com.         5       IN      A       216.239.34.10
ns3.google.com.         5       IN      A       216.239.36.10
ns4.google.com.         5       IN      A       216.239.38.10

Received 180 bytes from 192.168.134.2#53 in 54 ms

推荐文档