Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
df command in Linux with Examples
Next article icon

dig Command in Linux with Examples

Last Updated : 06 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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

To-query-domain-A-recordThis 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

To-query-domain-A-record-with-shortBy 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

To-remove-comment-linesThis command makes a request and excludes the comment lines. 4. To set or clear all display flags.

dig geeksforgeeks.org +noall

To-set-or-clear-all-display-flagsWe 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

to-query-detailed-answersIf 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

to-query-all-dns-record-typesWe 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

to-query-ms-record-of-the-domainIf 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

to-trace-dns-path“+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

for-specifying-name-serversBy 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

TO-QUERY-STATISTICS-SECTIONWe 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.



Next Article
df command in Linux with Examples
author
khu5h1
Improve
Article Tags :
  • Linux-Unix
  • Technical Scripter
  • linux-command
  • Linux-networking-commands

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
  • df command in Linux with Examples
    Ever felt the chilling fear of a "disk full" error message on your Linux machine? Fear not, for the mighty df command stands ready to guide you through the treacherous terrain of disk space management! This article delves deep into the df command, equipping you with the knowledge and skills to navig
    5 min read
  • dstat Command in Linux With Examples
    dstat is a tool that is used to retrieve information or statistics form components of the system such as network connections, IO devices, or CPU, etc. It is generally used by system administrators to retrieve a handful of information about the above-mentioned components of the system. It itself perf
    3 min read
  • ctags command in Linux with examples
    The ctags command in Linux is commonly used with classic editors such as vi or vim to create an index or tags file for source code. This allows quick navigation across files, enabling users to jump to function definitions or references. ctags generates a cross-reference file that lists various sourc
    4 min read
  • egrep command in Linux with examples
    The 'egrep' command in Linux is a powerful pattern-searching utility that belongs to the family of grep functions. It functions similarly to 'grep -E' by treating patterns as extended regular expressions, allowing more complex pattern matching without the need to escape special characters. This comm
    3 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
  • doexec command in Linux with examples
    doexec command in the Linux system is used to run an executable with an arbitrary argv[0]. It allows the user to argv[0] other than the name of the executable, which is by default passed. Syntax: doexec /path/to/executable argv[0] [argv[1-n]] Options: The argv list is used to send all options to the
    1 min read
  • as command in linux with examples
    as command is the portable GNU assembler in Linux. Using as command, we can read and assemble a source file. The main purpose of 'as' is to assemble the output of the GNU compiler of the C language.as command reads and assembles the .s File. Also, whenever you do not specify the file, it normally re
    3 min read
  • cron command in Linux with Examples
    The cron is a software utility, offered by a Linux-like operating system that automates the scheduled task at a predetermined time. It is a daemon process, which runs as a background process and performs the specified operations at the predefined time when a certain event or condition is triggered w
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences