• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Computing / Command Line DNS Lookup with dig

Command Line DNS Lookup with dig

Last updated on April 21, 2017 by Sal Ferrarello

dig is command line DNS Lookup program pre-installed on *nix and Macs. If you don’t have access to dig from the command line, there are some websites that offer a web interface to dig (e.g. Google Toolbox’s Online Dig).

Basic Lookup (Similar to ping)

dig example.com

Advantages over ping:

  • Doesn’t get grumpy when you include http:// at the beginning
  • Includes CNAME information if the lookup involves a CNAME record

Lookup Nameserver for a Specific URL

dig NS example.com

This generally returns something like

;; ANSWER SECTION:
example.com.        86400   IN  NS  a.iana-servers.net.
example.com.        86400   IN  NS  b.iana-servers.net.

Basic Lookup Using a Specific Nameserver

dig example.com @a.iana-servers.net

Where a.iana-servers.net is one of the nameservers returned when you queried with dig NS.

This is particularly useful when you want to confirm a new nameserver is properly configured before changing nameserver settings.

Lookup IPv6 Record

You can lookup a IPv6 record by requesting a AAAA record.

dig AAAA example.com

If a record exists, you’ll get a value like 2607:f8b0:4004:801::200e. For many domains, no AAAA record is set, in which case you will not get any value.

MX Records

dig MX example.com

Reverse DNS (lookup by IP)

dig -x 127.0.0.1

photo credit: FrodoBabbs via photopin cc

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Computing Tagged With: DNS, network

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in