CentOS uses host, dig, and nslookup to query DNS commands

Source: Internet
Author: User
Tags nslookup nslookup command
1. install the software packages dig and nslookup. Centos: # yuminstallbind-utilsDebian: # apt-getupdate # apt-getinstalldnsutils set the dns server IP address in/etc/resolv. conf before querying. II. usage

1. install the software package
Install related software packages for dig and nslookup.

Centos:

# yum install bind-utils

Debian:

# apt-get update
# apt-get install dnsutils


In addition, you must set the dns server IP address in/etc/resolv. conf before querying.

II. usage
1. host command
The host command is a simple DNS query tool.

General format:
Host domain name
Host-a domain name

Common options:
-A: equivalent to "-v-t any ".
-T type: specifies the record type to be queried. Query A, AAAA, and MX records by default.
-V: detailed output.

Example:

# host www.163.com
www.163.com is an alias for www.163.com.lxdns.com.
www.163.com.lxdns.com is an alias for 163.xdwscache.glb0.lxdns.com.
163.xdwscache.glb0.lxdns.com has address 113.107.76.19


2. dig command
The dig command is a powerful DNS query command.

General format:
Dig [@ global-server] [domain] [q-type] [q-class] {q-opt} {d-opt}

Parameter description:
@ Global-server: by default,/etc/resolv. conf is used as the DNS query host. you can enter the IP addresses of other DNS hosts here.
Domain: The domain name to query.
Q-type: query record type, such as a, any, mx, ns, soa, hinfo, axfr, and txt. a is queried by default.
Q-class: the query type, which is equivalent to the set class in nslookup. The default value is in (Internet ).
Q-opt: query option. There are several methods, for example,-f file is used to parse multiple addresses through batch files; -p port specifies another port (the default DNS port is 53.
D-opt: dig-specific option. You must add the "+" sign before the parameter.

Common d-opt options:
+ Vc: query using TCP protocol.
+ Time = ####: Set the timeout time.
+ Trace: trace the query results from the root domain.

Example:
1)

# dig www.163.com; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> www.163.com;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60034;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:;www.163.com.INA;; ANSWER SECTION:www.163.com.40INCNAMEwww.163.com.lxdns.com.www.163.com.lxdns.com.600INCNAME163.xdwscache.glb0.lxdns.com.163.xdwscache.glb0.lxdns.com. 120 INA113.107.76.19;; Query time: 779 msec;; SERVER: 8.8.8.8#53(8.8.8.8);; WHEN: Fri Jan 31 03:23:36 2014;; MSG SIZE  rcvd: 110


2)

# dig +trace www.163.com; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> +trace www.163.com;; global options: +cmd.8854INNSf.root-servers.net..8854INNSc.root-servers.net..8854INNSd.root-servers.net..8854INNSk.root-servers.net..8854INNSa.root-servers.net..8854INNSb.root-servers.net..8854INNSi.root-servers.net..8854INNSg.root-servers.net..8854INNSj.root-servers.net..8854INNSm.root-servers.net..8854INNSe.root-servers.net..8854INNSh.root-servers.net..8854INNSl.root-servers.net.;; Received 228 bytes from 8.8.8.8#53(8.8.8.8) in 583 mscom.172800INNSj.gtld-servers.net.com.172800INNSb.gtld-servers.net.com.172800INNSk.gtld-servers.net.com.172800INNSl.gtld-servers.net.com.172800INNSh.gtld-servers.net.com.172800INNSf.gtld-servers.net.com.172800INNSm.gtld-servers.net.com.172800INNSg.gtld-servers.net.com.172800INNSd.gtld-servers.net.com.172800INNSc.gtld-servers.net.com.172800INNSi.gtld-servers.net.com.172800INNSa.gtld-servers.net.com.172800INNSe.gtld-servers.net.;; Received 501 bytes from 192.33.4.12#53(192.33.4.12) in 542 ms163.com.172800INNSns2.nease.net.163.com.172800INNSns3.nease.net.163.com.172800INNSns4.nease.net.163.com.172800INNSns5.nease.net.163.com.172800INNSns6.nease.net.163.com.172800INNSns1.nease.net.;; Received 242 bytes from 192.43.172.30#53(192.43.172.30) in 471 mswww.163.com.600INCNAMEwww.163.com.lxdns.com.;; Received 61 bytes from 61.135.255.140#53(61.135.255.140) in 278 ms


3. nslookup
The nslookup command is more frequently used than dig, probably because there is no dig command on windows.

General format:
Nslookup [-option] [name |-] [server]

Parameter description:
Option: indicates some options. These options can be modified through the set command.
Name: the domain name to be queried.
Server: you can specify the IP address of the DNS host.

Set command description:
Set all: print the current option value.
Set calss = value: set the query type, which is generally Internet.
Set debug: set the debugging mode.
Set d2: set the detailed debugging mode.
Set domin = name: set the default domain name.
Set search:
Set port = value: set the DNS port.
Set querytype = value: changes the type of the queried information. The default type is A record.
Set type = value: same as set querytype.
Set recurse: set the query type to recursion. if set norecurse is set, the query type is down generation. the default value is the former.
Set retry = number: set the number of retries.
Set timeout = number: set the limit time (in seconds) for waiting for the response. if the limit is exceeded, the system times out. if you can try again, the system doubles the long timeout value and queries again.
Set vc: query over tcp.
Set fail:

For more information, see the man manual.

Example:

# nslookup www.163.com 4.2.2.2Server:4.2.2.2Address:4.2.2.2#53Non-authoritative answer:www.163.comcanonical name = www.163.com.lxdns.com.www.163.com.lxdns.comcanonical name = 163.xdwscache.glb0.lxdns.com.Name:163.xdwscache.glb0.lxdns.comAddress: 113.107.76.19

 

References:
Http://linux.chinaunix.net/techdoc/system/2008/08/19/1026154.shtml
Http://blog.csdn.net/a8572785/article/details/8641581
Http://blog.chinaunix.net/uid-20615025-id-29801.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.