dig command stands for Domain Information Groper. It is used for retrieving information about DNS name servers. It is basically used by network administrators. It is used for verifying and troubleshooting DNS problems and to perform DNS lookups. Dig command replaces older tools such as nslookup and the host.
Installing Dig command
In case of Debian/Ubuntu
$sudo apt-get install dnsutils
In case of CentOS/RedHat
$sudo yum install bind-utils
dig [server] [name] [type]
Working with Dig Command
1. To query domain “A” record
This command causes dig to look up the “A” record for the domain name “geeksforgeeks.org”.
2. To query domain “A” record with +short
dig geeksforgeeks.org +short
By default dig is verbose and by using “+short” option we can reduce the output drastically as shown.
3. To remove comment lines.
dig geeksforgeeks.org +nocomments
This command makes a request and excludes the comment lines.
4. To set or clear all display flags.
dig geeksforgeeks.org +noall
We use the “noall” query option, when we want to set or clear all display flags.
5. To query detailed answers.
dig geeksforgeeks.org +noall +answer
If we want to view the answers section information in detail, we first stop the display of all section using “+noall” option and then query the answers section only by using “+answer” option with the dig command.
6. To query all DNS record types.
dig geeksforgeeks.org ANY
We use “ANY” option to query all the available DNS record types associated with a domain. It will include all the available record types in the output.
7. To query MX record for the domain.
dig geeksforgeeks.org MX
If we want only the mail exchange – MX – answer section associated with a domain we use this command.
8. To trace DNS path
dig geeksforgeeks.org +trace
“+trace” command is used for tracing the DNS lookup path. This option makes iterative queries to resolve the name lookup. It will query the name servers starting from the root and subsequently traverses down the namespace tree using iterative queries following referrals along the way.
9. For specifying name servers
dig geeksforgeeks.org @126.96.36.199
By default, dig command will query the name servers listed in “/etc/resolv.conf” to perform a DNS lookup. We can change it by using @ symbol followed by a hostname or IP address of the name server.
10. To query the statistics section
dig geeksforgeeks.org +noall +answer +stats
We use “+stats” option with dig command, to see the statistics section.
- bc command in Linux with examples
- arp command in Linux with examples
- tar command in Linux with examples
- gdb command in Linux with examples
- wc command in Linux with examples
- apt command in linux with examples
- mv command in Linux with examples
- atd command in Linux with examples
- bg command in Linux with Examples
- fg command in Linux with examples
- seq command in Linux with Examples
- if command in linux with examples
- for command in Linux with Examples
- pv command in Linux with Examples
- rev command in Linux with Examples
- ip command in Linux with examples
- tty command in Linux with examples
- look command in Linux with Examples
- atq command in linux with examples
- apm Command in Linux With Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.