dig Command in Linux with Examples
Last Updated :
06 Nov, 2024
dig command stands for Domain Information Groper. It retrieves information about DNS name servers. Network administrators use it to verify and troubleshoot DNS problems and perform DNS lookups. The dignslookup 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
Syntax:
dig [server] [name] [type]
Working with Dig Command
1. To query domain "A" record
dig geeksforgeeks.org
This command causes dig to look up the "A" record for the domain name "geeksforgeeks.org".
A record refers to IPV4 IP.
Similarly, if record type is set as "AAAA", this would return IPV6 IP.
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 @8.8.8.8
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.
Reverse DNS Lookup
Reverse DNS lookup can be used to fetch domain name or the host name from the IP address.
"-x" option is used to perform reverse DNS lookup.
ex:
[xxxxxx ~]# dig +noall +answer -x 8.8.8.8
8.8.8.8.in-addr.arpa. 18208 IN PTR dns.google.
Note: DNS reverse look up will work only if the entry is present PTR.
PTR contents can be viewed using the command "dig -x xx.yy.zz.aa"
Batch Queries
Instead performing dig query for each domain at a time, a list of domains can be queried at once. To do so, enter the domain names in a file, only 1 domain name in each line and perform the dig query on file.
ex: let's say, file.txt has the list of domain names to be queried then,
dig -f file.txt +shortwill perform DNS queries and return all the resolved IPs.
Conclusion
The dig (Domain Information Groper) command in Linux is a powerful tool used for querying DNS (Domain Name Sysetm) servers troubleshooting network-relatd issues. It provides detailed information about DNS records, including types like A, AAAA, MX, NS, CNAME, and TXT records, making it invaluable for network administrators and developers. dig is especially helpful for verifying DNS records, ensuring that domain configuration are accurate and DNS propagation is complete.
Similar Reads
dirs command in Linux with examples dirs command shell builtin is used to display the list of currently remembered directories. By default, it includes the directory you are currently in. A directory can get into the list via pushd command followed by the dir name and can be removed via popd command. Syntax: dirs [-clpv] [+N] [-N] It
1 min read
curl Command in Linux with Examples curl is a command-line utility for transferring data to or from a server, employing a range of internet protocols such as HTTP, HTTPS, FTP, SCP, and SFTP.Whether you want to download a file, test a REST API, or simply verify that a website is up and running, curl is your best friend. It is accessed
5 min read
ip Command in Linux with Examples The ip command in Linux is a powerful utility for network configuration and management. It allows users to interact with various networking components such as network interfaces, routing tables, addresses, and more. Here, we will look into the 'ip' command, covering each aspect with examples, code,
7 min read
emacs command in Linux with examples Introduction to Emacs Editor in Linux/Unix Systems: The Emacs is referred to a family of editors, which means it has many versions or flavors or iterations. The most commonly used version of Emacs editor is GNU Emacs and was created by Richard Stallman. The main difference between text editors like
5 min read
od command in Linux with example The od (octal dump) command in Linux is a versatile tool used to display file contents in various formats, with the default being octal. This command is particularly useful for debugging scripts, examining binary files, or visualizing non-human-readable data like executable code. It allows users to
6 min read
domainname Command in Linux With Examples domainname command in Linux is used to return the Network Information System (NIS) domain name of the host. You can use hostname -d command as well to get the host domainname. If the domain name is not set up in your host then the response will be "none". In networking terminology, the domain name i
3 min read
help Command in Linux with examples If youâre new to the Linux operating system and struggling with command-line utilities, the help command is one of the first tools you should learn. As its name suggests, the 'help' command provides detailed information about built-in shell commands, making it an essential resource for beginners and
5 min read
zdiff command in Linux with Examples The zdiff command in Linux is used to invoke the diff program on files compressed via gzip. All options specified are passed directly to diff. By utilizing "zdiff," you can easily analyze differences between compressed files without the need to decompress them beforehand. Important Points:If only on
2 min read
uname command in Linux with Examples Linux, renowned for its open-source flexibility and powerful performance, offers a range of commands that reveal the inner workings of your system. Among these, the 'uname' command stands out as a versatile tool that provides key details about your Linux machine. Here, we will learn the basics of th
4 min read
getent command in Linux with examples The 'getent' command in Linux is a powerful tool that allows users to access entries from various important text files or databases managed by the Name Service Switch (NSS) library. This command is widely used for retrieving user and group information, among other data, stored in databases such as '
5 min read