bind-utils是bind软件提供的一组DNS工具包,里面有一些DNS相关的工具。主要:dig,host,nslookup,nsupdate。使用这些工具可以进行域名解析和DNS调试工作。
1.dig的使用
dig是一个DNS查询工具.dig向DNS服务器发出请求,然后输出DNS服务器的返回结果。系统管理员可以使用dig来测试DNS服务器。dig会根据/etc/resolv.conf文件中列出的服务器,依次进行尝试。不加参数执行dig时,dig将执行一个.查询,即根查询。
a.dig命令的格式为:
dig [ @server ] [ -b address ] [ -c class ] [ -f filename ] [ -k filename ] [ -p port# ] [ -t type ] [ -x addr ] [ -y name:key ] [name ] [ type ] [ class ] [ queryopt... ]
dig [ -h ]
dig [ global-queryopt... ] [ query... ]
dig的简单使用:
dig @server name type
server是DNS服务器的域名或ip地址.可以是以"."分割的IPv4的IP地址,也可以是以":"分割的IPv6的IP地址.如果server是一个域名,则dig先解析这个域名,然后再进行后续的查询.如果没有server参数,dig将会读取/etc/resolv.conf文件中的服务器列表。
name是需要查询的资源记录的名称.
type表示需要进行什么类型的查询,类型包括:ANY,A,MX,SIG等.如果没有指定类型,dig将进行A记录查询。
示例:
# dig @172.23.3.1 www.baidu.com A ; <<>> DiG 9.2.4 <<>> @172.23.3.1 www.baidu.com A ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12603 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 4, ADDITIONAL: 4 ;; QUESTION SECTION: ;www.baidu.com. IN A ;; ANSWER SECTION: www.baidu.com. 292 IN CNAME www.a.shifen.com. www.a.shifen.com. 705 IN A 202.108.22.5 www.a.shifen.com. 705 IN A 202.108.22.43 ;; AUTHORITY SECTION: a.shifen.com. 75348 IN NS ns1.a.shifen.com. a.shifen.com. 75348 IN NS ns2.a.shifen.com. a.shifen.com. 75348 IN NS ns3.a.shifen.com. a.shifen.com. 75348 IN NS ns4.a.shifen.com. ;; ADDITIONAL SECTION: ns1.a.shifen.com. 916 IN A 202.108.22.101 ns2.a.shifen.com. 396 IN A 220.181.27.59 ns3.a.shifen.com. 994 IN A 202.108.22.102 ns4.a.shifen.com. 1016 IN A 220.181.27.58 ;; Query time: 172 msec ;; SERVER: 172.23.3.1#53(172.23.3.1) ;; WHEN: Mon Oct 15 15:42:50 2007 ;; MSG SIZE rcvd: 226b.参数选项
$ host www.baidu.com www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 202.108.22.5 www.a.shifen.com has address 202.108.22.43 $ host -T www.baidu.com www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 202.108.22.5 www.a.shifen.com has address 202.108.22.43 $ host www.gmail.com www.gmail.com is an alias for mail.google.com. mail.google.com is an alias for googlemail.l.google.com. googlemail.l.google.com has address 66.249.89.19 googlemail.l.google.com has address 66.249.89.83 googlemail.l.google.com has address 66.249.89.18 $ host -t MX www.gmail.com www.gmail.com is an alias for mail.google.com. mail.google.com is an alias for googlemail.l.google.com.3.nslookup的使用
$ nslookup > server 202.106.195.68 Default server: 202.106.195.68 Address: 202.106.195.68#53 > set debug > www.baidu.com Server: 202.106.195.68 Address: 202.106.195.68#53 ------------ QUESTIONS: www.baidu.com, type = A, class = IN ANSWERS: -> www.baidu.com canonical name = www.a.shifen.com. -> www.a.shifen.com internet address = 202.108.22.43 -> www.a.shifen.com internet address = 202.108.22.5 AUTHORITY RECORDS: ADDITIONAL RECORDS: ------------ Non-authoritative answer: www.baidu.com canonical name = www.a.shifen.com. Name: www.a.shifen.com Address: 202.108.22.43 Name: www.a.shifen.com Address: 202.108.22.5 > exit2)非交互模式
$ nslookup www.sohu.com 202.106.195.68 Server: 202.106.195.68 Address: 202.106.195.68#53 Non-authoritative answer: www.sohu.com canonical name = d7.a.sohu.com. d7.a.sohu.com canonical name = pagegrp7.a.sohu.com. Name: pagegrp7.a.sohu.com Address: 61.135.150.104 Name: pagegrp7.a.sohu.com Address: 61.135.150.108 Name: pagegrp7.a.sohu.com Address: 61.135.150.113 Name: pagegrp7.a.sohu.com Address: 61.135.150.126 Name: pagegrp7.a.sohu.com Address: 61.135.150.145 Name: pagegrp7.a.sohu.com Address: 61.135.150.93 Name: pagegrp7.a.sohu.com Address: 61.135.150.98 Name: pagegrp7.a.sohu.com Address: 61.135.150.1014.nsupdate的使用
zone "foo.ca" in { type master; file "db.foo.ca"; allow-transfer { 127.0.0.1; }; allow-update { 127.0.0.1; }; };建立/var/named/db.foo.ca区文件,内容如下:
$ORIGIN . $TTL 86400 ; 1 day foo.ca IN SOA foo.ca. root.foo.ca. ( 4 ; serial 10800 ; refresh (3 hours) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) $TTL 86400 ; 1 day NS foo.ca. A 192.168.0.1 ; A记录为192.168.0.1使用nsupdate更新这条记录:
# nsupdate > server 127.0.0.1 > update delete foo.ca A > > update add foo.ca 80000 IN A 192.168.0.2 > > quit停止bind服务:
# cat db.foo.ca $ORIGIN . $TTL 86400 ; 1 day foo.ca IN SOA foo.ca. root.foo.ca. ( 6 ; serial 10800 ; refresh (3 hours) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) NS foo.ca. $TTL 80000 ; 22 hours 13 minutes 20 seconds A 192.168.0.2 ; A记录为192.168.0.2 $TTL 86400 ; 1 day AAAA ::1使用nslookup查询域名foo.ca:
# nslookup > server 127.0.0.1 Default server: 127.0.0.1 Address: 127.0.0.1#53 > foo.ca Server: 127.0.0.1 Address: 127.0.0.1#53 Name: foo.ca Address: 192.168.0.2