Hello everyone, I am Xianyu. I don’t know how often you use the dig command in your daily study or work. dig is the abbreviation of Domain Information Groper. It is a very common and useful tool for network administrators and friends working in the field of Domain Name System (DNS). Whether it's a simple DNS resolution lookup or more advanced troubleshooting and analysis, dig can do it. So today, Xianyu will share with you some common uses and examples of the dig command. In addition to the dig command, there is another command nslookup that has similar functions to dig. InstallIf your Linux distribution does not have the dig command installed, you can install it using the following command. Debian and Debian-based distributions: Red Hat and RHEL-based distributions: Arch Linux and Arch-based distributions: Take my test environment as an example (CentOS 7.9): Common usage
For example, if I want to resolve the domain name www.baidu.com, I would specify to use Google's DNS server (8.8.8.8): To find your MX records: As we mentioned earlier, the dig command will display the A record in the ANSWER section by default. Let's take a look at the command output: You can see that there are five columns in total. Let's take the last row as an example:
As we can see from the previous output, there is quite a lot of content. At this time, some friends may wonder: How to reduce the content output by the dig command? I only want the most useful ones, and I am dizzy when reading the rest. You can add the +nocomments option: As you can see, some comments are removed from the returned content after adding the +nocomments option. At this time, some friends will say: No, no, there is still too much information, I only want the ANSWER part. How can I make the command output only the ANSWER part? As you can see, adding the +noall and +answer options results in a clean and easy-to-read display. What if I only want to return the parsed result? I can use the +short option: Advanced Usage(1) Specify return type information As we mentioned earlier, there are many types of DNS records, such as A, AAAA, CNAME, MX, NS, PTR, CERT, SRV, TXT, SOA, etc. We can add the corresponding type name at the end of the command to return the parsed specific type information: Or use the special keyword ALL to put all type records together: (2) View the DNS resolution process If we are not sure where the problem is in the DNS configuration, we can use the dig command to view each process of DNS resolution by adding the +trace option. (3) DNS reverse lookup DNS forward lookup is to find the resolved IP through the domain name; reverse lookup is to find the domain name through the IP address: (4) Batch query Some friends may think: It is too slow to query one domain name at a time. Can I query multiple domain names at a time? Yes, dig supports batch query. First, we put the domain names to be queried in a file, one per line: Then add the -f option when executing the dig command: Modify dig default optionsWhen we used the dig command earlier, in order to simplify the output information, we had to include the +nocomments option each time we typed the command. So can we set this option to the default value so that we don't need to add this option when typing the command? The answer is yes, we need to create a ~/.digrc file in the home directory and add the options: In this way, even if we don't add them when we execute the dig command, these two options will be used by default. |
<<: Where does the strength of 5G factories that “take over” 5G+Industrial Internet come from?
The computer networks we typically imagine involv...
Enterprises that need to upgrade their traditiona...
The State Council Executive Meeting reviewed and ...
First we must understand that a TCP socket in the...
On November 27, 2021, the "Jiandao Cloud Zer...
Today we're taking a look at home network har...
[[405370]] Linkerd provides many features, such a...
The most direct users of the campus network - Int...
In the field of network technology, "gateway...
Today we are going to learn about NGINX. Nginx is...
On June 28, 2023 MWC Shanghai opened, and Huawei ...
[Shenzhen, China] On April 12, 2017, the 14th Hua...
[[222946]] Activities surrounding "3.15"...
1. Network card model There are mainly two types ...
IoT connection environment In addition to smart h...