dig命令实战

简介:

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

linux, bind, dig, rndc






      本文转自rshare 51CTO博客,原文链接:http://blog.51cto.com/1364952/2045276,如需转载请自行联系原作者




相关文章
|
3月前
|
网络协议 安全
DNS查询工具 - dig
【1月更文挑战第4天】
89 0
|
3月前
|
域名解析 网络协议 Ubuntu
Linux 上的 dig 和 nslookup 命令
Linux 上的 dig 和 nslookup 命令
96 0
|
6月前
|
缓存 网络协议 Linux
dig 简明教程
dig 简明教程
|
域名解析 网络协议 Linux
Linux Command dig 查询DNS
Linux Command dig 查询DNS
|
缓存 网络协议 Shell
|
网络协议 Linux 数据安全/隐私保护
Linux命令ping,nc的学习
今天看了下《Linux大棚命令百篇》网络和系统篇,发现了几个很不错的命令,我是看着目录然后根据自己的需要选了3个命令,没想到3个命令都让人眼前一亮,刷新了我原本的认知。 首先第一个命令还是老生常谈的ping 传统的ping就是下面的样子,这个也是我们熟悉的ping # ping 10.
1258 0
|
Linux 数据安全/隐私保护 Ubuntu
Linux基础命令---nslookup查询域名工具
nslookup nslookup是一个查询DNS域名的工具,它有交互和非交互两种工作模式。 此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、Fedora。 1、语法 nslookup [-option] [name | -] [server] 2、进入交...
1350 0
|
网络协议 Linux 数据安全/隐私保护
Linux基础命令---dig
dig dig是一个DNS查询工具,多数管理员会使用dig命令来解决DNS的问题。 此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、Fedora。 1、语法 dig [选项] 2、参数列表 @server 指定服务器地址 -b hos...
791 0
|
缓存 网络协议 数据库