$ host google.com
google.com has address 74.125.236.72
google.com has address 74.125.236.78
google.com has address 74.125.236.73
google.com has address 74.125.236.71
google.com has address 74.125.236.65
google.com has address 74.125.236.69
google.com has address 74.125.236.66
google.com has address 74.125.236.64
google.com has address 74.125.236.67
google.com has address 74.125.236.68
google.com has address 74.125.236.70
google.com has IPv6 address 2404:6800:4007:801::1004
google.com mail is handled by 10 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.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
从命令的运行结果我们可以看到主机的 IP (IPV4 和 IPV6)以及邮件服务器相关的信息。
如果您还想查看 DNS 记录,可以使用 -a 参数
代码如下:
$ host -a google.com
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34210
;; flags: qr rd ra; QUERY: 1, ANSWER: 21, AUTHORITY: 0, ADDITIONAL: 0</p> <p>;; QUESTION SECTION:
;google.com. IN ANY</p> <p>;; ANSWER SECTION:
google.com. 211 IN AAAA 2404:6800:4007:800::1009
google.com. 299 IN MX 10 aspmx.l.google.com.
google.com. 299 IN MX 50 alt4.aspmx.l.google.com.
google.com. 299 IN MX 20 alt1.aspmx.l.google.com.
google.com. 299 IN MX 30 alt2.aspmx.l.google.com.
google.com. 299 IN MX 40 alt3.aspmx.l.google.com.
google.com. 267 IN A 74.125.236.168
google.com. 267 IN A 74.125.236.165
google.com. 267 IN A 74.125.236.166
google.com. 267 IN A 74.125.236.167
google.com. 267 IN A 74.125.236.164
google.com. 267 IN A 74.125.236.174
google.com. 267 IN A 74.125.236.163
google.com. 267 IN A 74.125.236.169
google.com. 267 IN A 74.125.236.162
google.com. 267 IN A 74.125.236.161
google.com. 267 IN A 74.125.236.160
google.com. 136467 IN NS ns3.google.com.
google.com. 136467 IN NS ns1.google.com.
google.com. 136467 IN NS ns4.google.com.
google.com. 136467 IN NS ns2.google.com.</p> <p>Received 412 bytes from 127.0.1.1#53 in 30 ms
如果您需要查看域名服务器或者 SOA 信息,可以使用 -C 参数
代码如下:
$ host -C google.com
Nameserver 216.239.38.10:
google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300
Nameserver 216.239.34.10:
google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300
Nameserver 216.239.36.10:
google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300
Nameserver 216.239.32.10:
google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300
或者您可以使用 -d 或者 -v 参数来输出详细信息
代码如下:
$ host -v google.com
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52674
;; flags: qr rd ra; QUERY: 1, ANSWER: 11, AUTHORITY: 0, ADDITIONAL: 0</p> <p>;; QUESTION SECTION:
;google.com. IN A</p> <p>;; ANSWER SECTION:
google.com. 77 IN A 74.125.236.40
google.com. 77 IN A 74.125.236.38
google.com. 77 IN A 74.125.236.34
google.com. 77 IN A 74.125.236.37
google.com. 77 IN A 74.125.236.36
google.com. 77 IN A 74.125.236.41
google.com. 77 IN A 74.125.236.35
google.com. 77 IN A 74.125.236.33
google.com. 77 IN A 74.125.236.46
google.com. 77 IN A 74.125.236.32
google.com. 77 IN A 74.125.236.39</p> <p>Received 204 bytes from 127.0.1.1#53 in 33 ms
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31473
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0</p> <p>;; QUESTION SECTION:
;google.com. IN AAAA</p> <p>;; ANSWER SECTION:
google.com. 28 IN AAAA 2404:6800:4007:800::1002</p> <p>Received 56 bytes from 127.0.1.1#53 in 28 ms
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2871
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0</p> <p>;; QUESTION SECTION:
;google.com. IN MX</p> <p>;; ANSWER SECTION:
google.com. 13 IN MX 40 alt3.aspmx.l.google.com.
google.com. 13 IN MX 50 alt4.aspmx.l.google.com.
google.com. 13 IN MX 10 aspmx.l.google.com.
google.com. 13 IN MX 20 alt1.aspmx.l.google.com.
google.com. 13 IN MX 30 alt2.aspmx.l.google.com.</p> <p>Received 136 bytes from 127.0.1.1#53 in 29 ms
5. dig 命令
dig 命令是 DNS 查看工具,使用此命令可以查看域名服务器的主机地址
代码如下:
$ dig google.com</p> <p>; <<>> DiG 9.9.2-P1 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40090
;; flags: qr rd ra; QUERY: 1, ANSWER: 11, AUTHORITY: 0, ADDITIONAL: 1</p> <p>;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.com. IN A</p> <p>;; ANSWER SECTION:
google.com. 227 IN A 74.125.236.33
google.com. 227 IN A 74.125.236.38
google.com. 227 IN A 74.125.236.46
google.com. 227 IN A 74.125.236.40
google.com. 227 IN A 74.125.236.32
google.com. 227 IN A 74.125.236.37
google.com. 227 IN A 74.125.236.34
google.com. 227 IN A 74.125.236.35
google.com. 227 IN A 74.125.236.41
google.com. 227 IN A 74.125.236.39
google.com. 227 IN A 74.125.236.36</p> <p>;; Query time: 30 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Sat Jun 22 15:38:58 2013
;; MSG SIZE rcvd: 215