• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

dig Command Examples in Linux

by admin

Dig is a DNS lookup utility. If it’s not installed on your system, you can find it as part of dnsutils on Debian-based package managers and bind-utils on Fedora, CentOS, and Arch.

The dig command is used to query DNS servers; it is more flexible than the deprecated nslookup command. When invoked with just the -h option, it displays a list of options for the command. If you use it without any options or arguments, it will search for the root server.

The standard arguments are:

  • server: The server to query. If no server is supplied, dig will check thenameservers listed in /etc/resolv.conf. The address may be anIPv4 dotted address or an IPv6 colon-delimited address. It mayalso be a hostname, which dig will resolve (through thenameservers in /etc/resolv.conf).
  • name: The domain name to look up.
  • type: The type of query to perform, such as A, ANY, MX, SIG, andso forth. The default is A, but you may use any valid BIND9 query type.

The format of the command is demonstrated here:

# dig google.com
; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56840
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512

;; QUESTION SECTION:
;google.com.      IN  A

;; ANSWER SECTION:
google.com.    268  IN  A  216.58.217.206
;; Query time: 36 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Sun Mar 05 17:01:08 PST 2017
;; MSG SIZE rcvd: 55

To query a specific DNS server, rather than the default DNS servers for your host, use the following syntax:

# dig @server host_to_lookup

dig Command Examples

1. To dig into any domain name server:

# dig centos.com

2. To hide any particular section from the output:

# dig centos.com +noanswer
# dig centos.com +noadditional 
# dig centos.com +nostats
# dig centos.com +noauthority
# dig centos.com +nocomments

3. To query all types of records:

# dig centos.com -t ANY

4. To query MX records (Mail Exchanger records):

# dig centos.com MX
# dig centos.com -t MX

5. To query SIG records (Signature Records):

# dig centos.com -t SIG

6. To query NS records (Name server records):

# dig centos.com -t NS

7. To query TXT records (Text records):

# dig centos.com -t TXT

8. To see the summarized output:

# dig centos.com +short

9. To do the reverse DNS lookup of the server:

# dig -x centos.com

10. Perform iterative queries and display the entire trace path to resolve a domain name:

# dig +trace example.com

11. Find authoritative name servers for the zone and display SOA records:

# dig +nssearch example.com

12. Query a specific DNS record type associated with a given domain name:

# dig +short example.com A|MX|TXT|CNAME|NS

13. Lookup the IP(s) associated with a hostname (A records):

# dig +short example.com

14. Get a detailed answer for a given domain (A records):

# dig +noall +answer example.com

Filed Under: Linux

Some more articles you might also be interested in …

  1. mixxx Command Examples
  2. uname Command Examples in Linux
  3. Linux Command line Basics – Executing commands from the command line
  4. home-manager Command Examples
  5. a2query Command Examples in Linux
  6. “az account” Command Examples
  7. binwalk Command Examples in Linux
  8. lwp-request Command Examples
  9. cloud-init Command Examples in Linux
  10. parted: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright