Linux Dig commands

Source: Internet
Author: User
Tags domain name server mx record

The dig command is primarily used to query host address information from a DNS domain name server.

querying DNS information for a single domain name

The most typical use of the dig command is to query the information of a single host.

$ dig baidu.com

The dig command is rich in output information by default and can be divided into 5 parts.
The first section shows the version of the dig command and the input parameters.
The second section shows some of the technical details returned by the service, and more importantly the status. If the value of status is NoError, the query ends successfully.
The "QUESTION section" in part three shows the domain name we want to query.
The "ANSWER section" in part four is the result of the query.
Part Five is the query of some statistical information, such as how long it took to query which DNS server, at what time the query and so on.

By default, the dig command queries the A record, and a that shows the record type of the query is a record. Before attempting to query other types of records, let's look at common DNS record types.

types of common DNS records
Type Objective
A Address record, used to specify the IPV4 address of the domain name, if you need to point the domain name to an IP address, you need to add a record.
Aaaa Used to specify the host name (or domain name) corresponding to the IPV6 address record.
CNAME If you need to point a domain name to another domain name and then provide an IP address from another domain name, you need to add a CNAME record.
Mx If you need to set up a mailbox so that your mailbox can receive mail, you'll need to add an MX record.
Ns Domain Name server records, if you need to hand over the domain name to other DNS server resolution, you need to add NS records.
Soa This record of SOA is a mandatory record in all regional documents. It must be the first record in a file.
Txt You can write anything, with a length limit of 255. The vast majority of TXT records are used to make SPF records (anti-spam).
querying records for a CNAME type

In addition to the A record, common DNS records also have CNAME, and we can specify the DNS record type to query at query time:

$ dig abc.filterinto.com CNAME

This results in only the CNAME record. In fact, we can specify the type of any DNS record in the query.

querying from a specified DNS server

For some reasons, you might want to query from a specified DNS server (the results obtained from the default DNS server may not be accurate). Specify a DNS server by using the @ symbol:

$ dig @8.8. 8.8 abc.filterinto.com

The DNS server from which you can see this query is 8.8.8.8.

If you do not specify a DNS server, dig will use the address in the/etc/resolv.conf as the DNS server in turn:

$ dig abc.filterinto.com

The DNS server queried above becomes:

Reverse Query

In the previous query we specified the query server as 8.8.8.8, which is the home DNS server? In fact, we can use the Dig-X option to reverse resolve the domain name of the IP address:

8.8. 8.8 + Short

Well, it should be the Google home, you can rest assured that the use of.

Control Display Results

The dig command returns the results by default, showing detailed information, and if you want to get a streamlined result you can use the +short option:

$ dig + short abc.filterinto.com

This shows the result is much more refreshing.
In fact, we can also control the content of the output by more options, such as just want to display the content of "ANSWER section":

$ dig abc.filterinto.com +nocomments +noquestion +noauthority +noadditional +nostats

This result is very good, is the use of too many options (Dig command has many of these options, please refer to the user manual for details). We can achieve the same result as above in a graceful way:

$ dig abc.filterinto.com +noall +answer
View TTL (Time to Live)

TTL is an important metric in DNS resolution, primarily to control the cache time of DNS records on DNS servers:

$ dig abc.filterinto.com

The units in the query result are seconds. The following command shows you how to streamline some of the test results:

$ dig +nocmd +noall +answer +ttlid abc.filterinto.com

track the entire query process

If you are curious about the processes that dig commands to perform queries, you can try using the +trace option. It will output all the information from the root domain to the final result:

$ dig +trace abc.filterinto.com

is not a complete result, interested friends can try it on their own.

Summary

Dig is a very strong DNS query tool, this article only describes its common usage, more command options and how to use the man page to see.

Linux Dig commands

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.