您的位置:首页 > 运维架构 > Linux

Linux DNS之常用工具dig、rndc等

2015-03-30 15:38 316 查看
dig工具
Domain Information Gropher,DNSlookup utility。
/usr/bin/dig

#dig [OPTION] [@]SERVER|IP
[OPTION]
-t TYPE 指定资源记录类型
SOA
A
MX
NS
PTR
AXFR ZONENAME 得到指定区域内的全部数据。
IFXR=SERIALNUM 得到序列号为SERIALNUM的增量更新。

-x IP 查找IP地址对应的FQDN,即反向解析。

@ 指定查询服务器,直接向该服务器查询

+[NO]KEYWORD=VALUE 使用或禁用工作特性
KEYWORD
recurse 递归
trace 跟踪解析过程

例如:
#dig -t NS . 从本地服务器查询根域的NS记录
#dig -t NS . @a.root-servers.net. 指定从a.root-servers.net查询根域的NS记录。
#dig -t NS test.com.
#dig -t MX test.com.
#dig -t A www.test.com.
#dig -x 10.0.0.2
#dig +norescures -t A www.baidu.com @10.0.0.2 不使用递归的方式查询。默认情况下dig查询就是递归的。
#dig +trace -t A www.baidu.com @10.0.0.2
#dig -t AXFR test.com @10.0.0.3
#dig -t IXFR=2 @10.0.0.3

#host [OPTION] SERVER|IP
[OPTION]
-t TYPE 指定资源记录类型

例如:
#host -t A www.test.com
#host -t NS test.com
#host -t MX test.com
#host -t SOA test.com

#nslookup
1.交互模式
#nslookup
server IP 指定查询服务器的IP
set q=TYPE 设定资源记录类型
ZONENAME|IP 指定区域名称或IP

例如:
#nslookup
server 10.0.0.3
set q=A
www.test.com
10.0.0.2
set q=NS
test.com
ns1.test.com.
10.0.0.3

2.命令行模式
#nslookup [OPTION]
[OPTION]

#named-checkconf
检查/etc/named.conf文件是否有错误。

#named-checkzone "ZONENAME" ZONEFILE
例如:
#named-checkzone "." /var/named/named.ca 检查根区域的配置是否有错。
#name-checkzone "test.com" /var/named/test.com.zone

rndc
#rndc [OPTION] COMMAND
[OPTION]
-c CFGFILE 指定配置文件
-s SERVER 指定远程服务器
-p PORT 指定以PORT端口进行连接。
-k KEYFILE 指定使用KEYFILE对外进行发送

COMMAND
reload 重读某个区域的数据文件配置文件和区域数据文件
reload zone ZONENAME 重读某个区域的数据文件
refresh zone ZONENAME 重新刷新某个区域
retransfer zone ZONENAME 重新进行主从传递
freeze 冻结所有动态区域
freeze zone ZNONNAME 冻结指定区域
notify zone ZONENAME 重新发送通知
reconfig 只重读配置文件和新的区域
status 手机服务器统计信息并写入统计文件。
querylog 是否启动查询日志
stop 停止服务
flush 刷新全部缓存

#rndc-confgen > FILE 生成rndc配置文集
例如:
#rndc-confgen > /etc/rndc.conf

/etc/rndc.conf 配置文件
# Start of rndc.conf
key "rndc-key" {
algorithm hmac-md5;
secret "qvlbS23pY2t5Uq6WLqxaXA==";
};

options {
default-key "rndc-key";
default-server 127.0.0.1;
default-port 953;
};
# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndc-key" {
# algorithm hmac-md5;
# secret "qvlbS23pY2t5Uq6WLqxaXA==";
# };
#
# controls {
# inet 127.0.0.1 port 953
# allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf

实例1:控制本机的DNS:
1.生成配置文件:
#rndc-confgen > /etc/rndc.conf
2.将生成的配置文件追加到DNS配置文件中
#cat /etc/rndc.conf >> /etc/named.conf
#vim /etc/named.conf
options {
directory "/var/named";
allow recursion {172.16.0.0/16;};
};
zone "." IN {
type hint;
file "named.ca"

};

zone "localhost" IN {
type master;
file "named.localhost";
allow-transfer {none;};
};

zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback"
allow-transfer {none;};
};

zone "test.com" IN {
type master;
file "test.com.zone";
allow-transfer {10.0.0.6;};
};

zone "0.0.10.in-addr.arpa" IN {
type master;
file "10.0.0.zone";
allow-transfer {10.0.0.6;};
};

key "rndc-key" {
algorithm hmac-md5;
secret "qvlbS23pY2t5Uq6WLqxaXA==";
};

controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};

#service named reload

3.使用rndc命令
#rndc -c /etc/rndc.conf status
#rndc -c /etc/rndc.conf notify "test.com"
#rndc -c /etc/rndc.con flush
#rndc -c /etc/rndc.con stop

实例2:控制远程DNS:
1.在远程DNS生成配置文件:
#rndc-confgen > /etc/rndc.conf
2.在远程DNS上,将生成的配置文件追加到DNS配置文件中,并修改rndc监听的地址和允许控制的地址。
#cat /etc/rndc.conf >> /etc/named.conf
#vim /etc/named.conf
options {
directory "/var/named";
allow-recursion {172.16.0.0/16;};
};
zone "." IN {
type hint;
file "named.ca"

};

zone "localhost" IN {
type master;
file "named.localhost";
allow-transfer {none;};
};

zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback"
allow-transfer {none;};
};

zone "test.com" IN {
type master;
file "test.com.zone";
allow-transfer {10.0.0.6;};
};

zone "0.0.10.in-addr.arpa" IN {
type master;
file "10.0.0.zone";
allow-transfer {10.0.0.6;};
};

key "rndc-key" {
algorithm hmac-md5;
secret "qvlbS23pY2t5Uq6WLqxaXA==";
};

controls {
inet 10.0.0.3 port 953
allow { 10.0.0.3; } keys { "rndc-key"; };
};

#service named reload

3.将远程DNS生成的rndc.conf复制到本地:
#scp root@10.0.0.6:/etc/rndc.conf /root/rndc.conf
4.编辑传输过来的rndc.conf,将服务器改为本地DNS服务器地址。
#vim /root/rndc.conf
# Start of rndc.conf
key "rndc-key" {
algorithm hmac-md5;
secret "qvlbS23pY2t5Uq6WLqxaXA==";
};

options {
default-key "rndc-key";
default-server 10.0.0.3;
default-port 953;
};
# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndc-key" {
# algorithm hmac-md5;
# secret "qvlbS23pY2t5Uq6WLqxaXA==";
# };
#
# controls {
# inet 127.0.0.1 port 953
# allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf

5.使用rndc命令显示远程DNS状态。
#rndc -rndc.conf status

本文出自 “小私的blog” 博客,请务必保留此出处http://ggvylf.blog.51cto.com/784661/1626449
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: