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 [email protected]:/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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章