|
1 |
| -COMING SOON ...... |
| 1 | +# DNS 查询工具 -- dig|host|nslookup |
| 2 | + |
| 3 | +`nslookup`、`host`和`dig` 是三个DNS查询工具,以下会分别介绍它们的使用方法。 |
| 4 | + |
| 5 | +## 一、nslookup |
| 6 | + |
| 7 | +>nslookup is a tried and true program that has weathered the ages. nslookup has been deprecated and may be removed from future releases. There is not even a man page for this program. |
| 8 | +
|
| 9 | +因此,这里不过多介绍。 |
| 10 | + |
| 11 | +## 二、host |
| 12 | + |
| 13 | +`host`命令和`dig`命令很相像,但是`host`命令的输出要更简洁,如下示例 |
| 14 | + |
| 15 | +``` bash |
| 16 | +# host www.google.com |
| 17 | +www.google.com has address 74.125.135.106 |
| 18 | +``` |
| 19 | + |
| 20 | +`host`命令只输出给我们`dig`命令的ANSWER section,相对`dig`提供的一些不必要的信息来说更简洁快速。也可指定DNS Server来查询,例如我想使用Google DNS`8.8.8.8`,named可以如下指定 |
| 21 | + |
| 22 | +``` bash |
| 23 | +# host www.google.com 8.8.8.8 |
| 24 | +Using domain server: |
| 25 | +Name: 8.8.8.8 |
| 26 | +Address: 8.8.8.8#53 |
| 27 | +Aliases: |
| 28 | + |
| 29 | +www.google.com has address 173.194.72.147 |
| 30 | +``` |
| 31 | + |
| 32 | +`host`当然也支持反解析 |
| 33 | + |
| 34 | +``` bash |
| 35 | +# host 173.194.72.147 |
| 36 | +147.72.194.173.in-addr.arpa domain name pointer tf-in-f147.1e100.net. |
| 37 | +``` |
| 38 | + |
| 39 | +指定查询类型可以使用`-t`选项 |
| 40 | + |
| 41 | +``` bash |
| 42 | +# host -t SOA google.com #查询SOA记录信息 |
| 43 | +google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300 |
| 44 | +``` |
| 45 | + |
| 46 | +查询`MX`记录 |
| 47 | + |
| 48 | +``` |
| 49 | +$ host -t MX google.com |
| 50 | +google.com mail is handled by 10 aspmx.l.google.com. |
| 51 | +google.com mail is handled by 40 alt3.aspmx.l.google.com. |
| 52 | +google.com mail is handled by 20 alt1.aspmx.l.google.com. |
| 53 | +google.com mail is handled by 50 alt4.aspmx.l.google.com. |
| 54 | +google.com mail is handled by 30 alt2.aspmx.l.google.com. |
| 55 | +``` |
| 56 | + |
| 57 | +`-C`对比认证DNS SOA信息 |
| 58 | + |
| 59 | +``` |
| 60 | +# host -C google.com |
| 61 | +Nameserver 216.239.34.10: |
| 62 | + google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300 |
| 63 | +Nameserver 216.239.36.10: |
| 64 | + google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300 |
| 65 | +Nameserver 216.239.32.10: |
| 66 | +... ... |
| 67 | +``` |
| 68 | + |
| 69 | +查询DNS Server软件版本信息,10.10.10.2为DNS Server |
| 70 | + |
| 71 | +``` bash |
| 72 | +# host -c CH -t txt version.bind 10.10.10.2 |
| 73 | +Using domain server: |
| 74 | +Name: 10.10.10.2 |
| 75 | +Address: 10.10.10.2#53 |
| 76 | +Aliases: |
| 77 | + |
| 78 | +version.bind descriptive text "9.8.1-P2" |
| 79 | +``` |
| 80 | + |
| 81 | +__host帮助__ |
| 82 | + |
| 83 | +``` bash |
| 84 | +# host |
| 85 | +Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time] |
| 86 | + [-R number] [-m flag] hostname [server] |
| 87 | + -a is equivalent to -v -t ANY |
| 88 | + -c specifies query class for non-IN data 搜索非网络数据时要指定要查找的类 |
| 89 | + -C compares SOA records on authoritative nameservers |
| 90 | + -d is equivalent to -v |
| 91 | + -l lists all hosts in a domain, using AXFR |
| 92 | + -i IP6.INT reverse lookups |
| 93 | + -N changes the number of dots allowed before root lookup is done |
| 94 | + -r disables recursive processing |
| 95 | + -R specifies number of retries for UDP packets |
| 96 | + -s a SERVFAIL response should stop query |
| 97 | + -t specifies the query type 指定要查询的记录类型 |
| 98 | + -T enables TCP/IP mode |
| 99 | + -v enables verbose output 输出更详细的信息 |
| 100 | + -w specifies to wait forever for a reply |
| 101 | + -W specifies how long to wait for a reply |
| 102 | + -4 use IPv4 query transport only |
| 103 | + -6 use IPv6 query transport only |
| 104 | + -m set memory debugging flag (trace|record|usage) |
| 105 | +``` |
| 106 | + |
| 107 | +## 三、dig |
| 108 | + |
| 109 | +dig也是一个很强大的命令,相对host来说输出较为繁杂,如下: |
| 110 | + |
| 111 | +``` bash |
| 112 | +$ dig www.google.com |
| 113 | +... ... |
| 114 | + |
| 115 | +;; ANSWER SECTION: |
| 116 | +www.google.com. 297 IN A 74.125.135.106 |
| 117 | +www.google.com. 297 IN A 74.125.135.104 |
| 118 | +... ... |
| 119 | + |
| 120 | +;; AUTHORITY SECTION: |
| 121 | +google.com. 172796 IN NS ns3.google.com. |
| 122 | +google.com. 172796 IN NS ns1.google.com. |
| 123 | +google.com. 172796 IN NS ns4.google.com. |
| 124 | +google.com. 172796 IN NS ns2.google.com. |
| 125 | + |
| 126 | +... ... |
| 127 | +``` |
| 128 | + |
| 129 | +查询`MX`记录 |
| 130 | + |
| 131 | +``` bash |
| 132 | +$ dig google.com MX | grep '^;; ANSWER SECTION:' -A 5 |
| 133 | +;; ANSWER SECTION: |
| 134 | +google.com. 368 IN MX 50 alt4.aspmx.l.google.com. |
| 135 | +google.com. 368 IN MX 40 alt3.aspmx.l.google.com. |
| 136 | +google.com. 368 IN MX 10 aspmx.l.google.com. |
| 137 | +google.com. 368 IN MX 30 alt2.aspmx.l.google.com. |
| 138 | +google.com. 368 IN MX 20 alt1.aspmx.l.google.com. |
| 139 | +``` |
| 140 | + |
| 141 | +查询`SOA`记录 |
| 142 | + |
| 143 | +``` bash |
| 144 | +$ dig google.com SOA | grep '^;; ANSWER SECTION:' -A 1 |
| 145 | +;; ANSWER SECTION: |
| 146 | +google.com. 85539 IN SOA ns1.google.com. dns-admin.google.com. 2013061100 7200 1800 1209600 300 |
| 147 | +``` |
| 148 | + |
| 149 | +指定DNS Server查询 |
| 150 | + |
| 151 | +``` bash |
| 152 | +$ dig www.baidu.com @8.8.8.8 |
| 153 | +... ... |
| 154 | +;; ANSWER SECTION: |
| 155 | +www.baidu.com. 1024 IN CNAME www.a.shifen.com. |
| 156 | +www.a.shifen.com. 166 IN A 119.75.217.56 |
| 157 | +www.a.shifen.com. 166 IN A 119.75.218.77 |
| 158 | +... ... |
| 159 | +``` |
| 160 | + |
| 161 | +`dig`查询版本号 |
| 162 | + |
| 163 | +``` bash |
| 164 | +$ dig chaos txt version.bind 10.10.10.2 | grep '^;; ANSWER SECTION:' -A 1 |
| 165 | +;; ANSWER SECTION: |
| 166 | +version.bind. 0 CH TXT "9.8.1-P2" |
| 167 | +``` |
| 168 | + |
| 169 | +`dig`反解析`-x` |
| 170 | + |
| 171 | +``` bash |
| 172 | +$ dig -x 74.125.135.105 |
| 173 | +;; QUESTION SECTION: |
| 174 | +;105.135.125.74.in-addr.arpa. IN PTR |
| 175 | + |
| 176 | +;; ANSWER SECTION: |
| 177 | +105.135.125.74.in-addr.arpa. 83205 IN PTR ni-in-f105.1e100.net. |
| 178 | +``` |
0 commit comments