当前位置--> 首 页 --> 文 章 -->C/C++

※阅读文章※

Unix编程/应用问答中文版 ---7.DNS相关问题


作者:不祥 [文章出自: www.fanqiang.com]


7.1   如何进行DNS区传输 
7.2   如何获知权威名字服务器 
7.3   如何配置DNS的委托解析 
7.4   如何获知BIND的版本号 
7.5   Solaris/FreeBSD/Linux如何指定域名解析的顺序 
-------------------------------------------------------------------------- 

7. DNS相关问题 

7.1 如何进行DNS区传输 

A: scz <scz@nsfocus.com> 

   用nslookup是最普遍适用的 
   nslookup 
   > server ns.tsinghua.edu.cn 
   > set type=axfr 
   > ls tsinghua.edu.cn [> tsinghua.txt] (方括号里的可选) 

   有些系统提供了dig命令 
   dig @ns.tsinghua.edu.cn axfr tsinghua.edu.cn 

A: lgwu 

   有些系统提供了host命令,这个命令不太保险 
   host -l net.tsinghua.edu.cn (后面指定域) 
   host -l ncic.ac.cn 

7.2 如何获知权威名字服务器 

A: scz <scz@nsfocus.com> 

   nslookup 
   > set query=ns 
   > ncic.ac.cn (获知管辖该域的权威名字服务器) 
   Authoritative answers can be found from: 
   gatekeeper.ncic.ac.cn   internet address = 159.226.41.188 
   > server gatekeeper.ncic.ac.cn 
   > set type=axfr (准备区传输) 
   > ls ncic.ac.cn > ncic.txt 

7.3 如何配置DNS的委托解析 

Q: 我想把子域DNS解析下放到下面去,在我这里如何配置 

A: zhangql@bbs.tsinghua.edu.cn 

子域  IN  NS  <负责子域DNS解析的IP> 

7.4 如何获知BIND的版本号 

Q: 如何识别当前运行的bind是什么版本 

A: M. Zuber <helmlein@hotmail.com> 

   dig @<victim_ip> txt chaos version.bind 

   或者 

   nslookup 
   server <victim_ip> 
   set query=txt 
   set class=chaos 
   version.bind 

   但是这个返回结果可以通过/etc/named.conf自己设置,并不可靠。如果你正在运 
   行BIND 8,可以执行 

   /usr/sbin/ndc status 

A: backend <backend@nsfocus.com> 

#!/bin/sh 
# bv (Bind Version) script 
# written by backend@nsfocus.com 

USAGE="Usage: $0 <address>" 

if [ $# -ne 1 ]; then 
        echo $USAGE 
        exit 
fi 

if [ ! -f /usr/bin/dig ]; then 
        echo -en "\\033[1;31mCan't find \"dig\" program.\\033[0;39m\n\n" 
        exit 
fi 

VER=`/usr/bin/dig @$1 version.bind chaos txt | grep "VERSION.BIND"` 

if [ "x$VER" = "x" ]; then 
        echo -en "\\033[1;31mSorry. Can't get BIND version.\\033[0;39m\n\n" 
else 
        echo -en "BIND version of \\033[1;33m$1\\033[0;39m = " 
        echo -en "\\033[1;33m" 
        echo $VER | awk '{print $5;}' 

        echo -en "\\033[0;39m\n" 
fi 

A: deepin <deepin@nsfocus.com> 

很多主机没有dig,最方便的办法是 
nslookup -q=txt -class=chaos version.bind IP-addr 
如果要美观一点,所以可以用这样的一个小脚本 

#!/bin/sh 
if [ $# = 0 ];then echo "useage: $0 IP-Addr."; exit 1;fi 
VER=`nslookup -q=txt -class=chaos version.bind $1 | grep "VERSION.BIND"` 
if [ $? = 0 ];then 
        echo -en "BIND version of \\033[1;33m$1\\033[0;39m = " `echo $VER | awk 
'{print $4,$5,$6;}'` "\\033[0;39m\n" 
else 
        echo -en "\\033[1;31mSorry. Can't get BIND version.\\033[0;39m\n\n" 
fi 

命令行上直接指定IP,会进行反向域名解析,有可能失败,进入nslookup之后server 
指定IP,则无此问题。 

7.5 Solaris/FreeBSD/Linux如何指定域名解析的顺序 

Q: 如何在Solaris中使/etc/resolv.conf的设置生效 

A: cp /etc/nsswitch.dns /etc/nsswitch.conf 
   或者 
   vi /etc/nsswitch.conf 

   hosts: files dns 

Q: FreeBSD中有类似Solaris的/etc/nsswitch.conf的文件吗 

A: /etc/host.conf 

-------------------------------------------------------------------------- 
# First try the /etc/hosts file 
hosts 
# Now try the nameserver next. 
# 如果不希望做反向域名解析,则注释掉下面这行 
# bind 
# If you have YP/NIS configured, uncomment the next line 
# nis 
-------------------------------------------------------------------------- 

Q: Linux中有类似Solaris的/etc/nsswitch.conf的文件吗 

D: /etc/host.conf 

-------------------------------------------------------------------------- 
order hosts, bind, nis 
multi on 
-------------------------------------------------------------------------- 

D: rai@SMTH Unix 2001-11-28 09:42 

改了/etc/host.conf还是不行,后来试了一下/etc/nsswitch.conf就可以了,Linux 
也有这个文件的,必须保证下一行中有dns 

-------------------------------------------------------------------------- 
# hosts:     db files nisplus nis dns 
hosts:      files nisplus nis dns 
-------------------------------------------------------------------------- 

文章加入时间: 2004-11-17 14:53:10 责任编辑: w9   (2675 人次查阅)
 
Copyright © 1998-2004 中国PHP联盟 All rights reserved.