In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the domain name resolution command dig in Linux, which has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article.
The dig command is a commonly used domain name query tool, which can be used to test whether the domain name system is working properly.
Query the DNS information of a single domain name
The most typical use of the dig command is to query the information of a single host.
Linuxidc@linuxidc:~$ dig www.linuxidc.com; > DiG 9.11.3-1Ubuntu1.5-Ubuntu > www.linuxidc.com;; global options: + cmd;; Got answer:;;-> > HEADER#53 (127.0.0.53); WHEN: Sun Mar 03 10:55:35 CST 2019; MSG SIZE rcvd: 77dig command default output information is relatively rich, probably can be divided into. 5 parts
The first part shows the version of the dig command and the parameters entered. The second part shows some technical details returned by the service, and more importantly, status. If the value of status is NOERROR, this query ends successfully. The "QUESTION SECTION" in the third part shows the domain name we are looking for. The "ANSWER SECTION" in the fourth part is the result of the query. The fifth part is some statistical information of this query, such as how long it took, which DNS server was queried, when the query was conducted, and so on.
By default, the dig command queries the A record, and the A shown in the figure above indicates that the record type of the query is A record. Before trying to query other types of records, let's take a look at the common DNS record types.
Types of common DNS records
Type purpose
An address record, which is 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 the A record. AAAA is used to specify the IPv6 address record corresponding to the hostname (or domain name). CNAME if you need to point the domain name to another domain name, and then another domain name provides the ip address, you need to add the CNAME record. MX if you need to set up a mailbox so that it can receive mail, you need to add a MX record. NS domain name server record. If you need to hand over the subdomain name to another DNS server for resolution, you need to add the NS record. Records like SOA SOA are mandatory in all culture files. It must be the first record in a file. TXT can write anything, and the length is limited to 255. The vast majority of TXT records are used for SPF records (anti-spam).
Query records of type CNAME
In addition to A record, the common DNS record is CNAME. We can specify the type of DNS record to be queried when querying:
Linuxidc@linuxidc:~$ dig m.linuxidc.com CNAME; > DiG 9.11.3-1ubuntu1.5-Ubuntu > m.linuxidc.com CNAME;; global options: + cmd;; Got answer:;;-> > HEADER#53 (127.0.0.53); WHEN: Sun Mar 03 11:20:34 CST 2019; MSG SIZE rcvd: 43
In this way, there is only a record of CNAME in the result. We can actually specify any type of DNS record in the query.
Query from the specified DNS server
For some reason, you want to query from the specified DNS server (the results obtained from the default DNS server may be inaccurate). Specify that the DNS server uses the @ symbol:
Linuxidc@linuxidc:~$ dig @ 8.8.8m.linuxidc.com; > DiG 9.11.3-1ubuntu1.5-Ubuntu > @ 8.8.8.8m.linuxidc.com; (1 server found);; global options: + cmd;; Got answer:;;-> > HEADER#53 (8.8.8.8); WHEN: Sun Mar 03 11:21:48 CST 2019; MSG SIZE rcvd: 75
From the figure above, you can see that the DNS server for this query is 8.8.8.8.
If you do not specify a DNS server, dig will use the address in / etc/resolv.conf as the DNS server in turn:
Linuxidc@linuxidc:~$ dig m.linuxidc.com
The DNS server queried above becomes:
Reverse query in the previous query, we specified the query server as 8.8.8.8. Whose DNS server is this? In fact, we can use the-x option of dig to reverse resolve the domain name corresponding to the IP address: linuxidc@linuxidc:~$ dig-x 8.8.8.8 + shortgoogle-public-dns-a.google.com.
Well, it should be Google, so you can rest assured to use it.
The results returned by the dig command show detailed information by default. If you want to get a concise result, you can use the + short option: linuxidc@linuxidc:~$ dig + short m.linuxidc.com122.228.238.15106.119.182.141.
The result shown here is much more refreshing.
In fact, we can also have more options to control the output, such as only want to display the "ANSWER SECTION" content:
The result is good, but there are too many options used (there are many of these options for the dig command, please refer to the user manual for details). We can achieve the same result in a more elegant way:
Linuxidc@linuxidc:~$ dig m.linuxidc.com + noall + answer; > DiG 9.11.3-1ubuntu1.5-Ubuntu > m.linuxidc.com + noall + answer;; global options: + cmdm.linuxidc.com. 5 IN A 113.107.238.212m.linuxidc.com. 5 IN A 122.228.238.15 tracks the entire query process
If you are curious about what process the dig command goes through when executing a query, you can try using the + trace option. It outputs all the information from the root domain to the final result:
Linuxidc@linuxidc:~$ dig sohu.com @ 202.102.134.68-p53-t MX + trace; > DiG 9.11.3-1ubuntu1.5-Ubuntu > sohu.com @ 202.102.134.68-P 53-t MX + trace;; global options: + cmd. 482761 IN NS f.rootMurphy servers.net.. 482761 IN NS a.rootcopyright servers.net.net.. 482761 IN NS c. Roothouse servers.net.. 482761 IN NS b.rootcopyright servers.net.. 482761 IN NS j.rootcopyright servers.net.. 482761 IN NS d.rootcopyright servers.net.net.. 482761 IN NS k.rootcopyright servers.net.net.. 482761 IN NS e.rootconversation servers.net.. 482761 IN NS h. Rootcomp servers.net.. 482761 IN NS i.rootMurservers.net.net.. 482761 IN NS m.rootlyservers.net.. 482761 IN NS g.rootcopyright servers.net.. 482761 IN NS l.rootcopyright servers.net.politic; Received 239 bytes from 202.102.134.68 mscom 53 (202.102.134.68) in 40 mscom. 172800 IN NS d.gtld-servers.net.
The picture above is not a complete result. Interested friends can try it on their own.
Show 13 root domain servers
There are 13 root domain servers on internet, which are displayed using the dig command with no parameters
Linuxidc@linuxidc:~$ dig; > DiG 9.11.3-1ubuntu1.5-Ubuntu >; global options: + cmd;; Got answer:;;-> > HEADER#53 (127.0.0.53); WHEN: Sun Mar 03 11:37:11 CST 2019 MSG SIZE rcvd: 239.Thank you for reading this article carefully. I hope the article "how to use dig to resolve domain names in Linux" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.