Retrieve DNS Records with Dig

By  on  

One of the most difficult parts of my job is managing DNS settings. It's not that DNS is a particularly difficult thing to manage, but it's somewhat foreign to me because they don't teach it in school and there are huge consequences for messing things up. Not only can a business' website be down, but their email as well. Whenever I need to retrieve DNS records from a nameserver, I use Cygwin and dig.

For this example, we'll pretend that we need to retrieve the MX records for the davidwalsh.name domain. Here's the format of how you use dig:

dig @[nameserver] [domain] [record type]

To get a domains nameserver addresses, you'll need to do a WHOIS search. Click here to learn how to do that. I know that davidwalsh.name's nameserver is NS2.DREAMHOST.COM, so now I can find my domain's MX records:

dig @ns2.dreamhost.com davidwalsh.name MX

The above returns:

; <<>> DiG 9.3.2 <<>> @ns2.dreamhost.com davidwalsh.name mx
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 736
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2

;; QUESTION SECTION:
;davidwalsh.name.               IN      MX

;; ANSWER SECTION:
davidwalsh.name.        14400   IN      MX      0 mx1.balanced.frisky.mail.dreamhost.com.
davidwalsh.name.        14400   IN      MX      0 mx2.balanced.frisky.mail.dreamhost.com.

;; ADDITIONAL SECTION:
mx1.balanced.frisky.mail.dreamhost.com. 14400 IN A 208.113.200.12
mx2.balanced.frisky.mail.dreamhost.com. 14400 IN A 208.113.200.11

;; Query time: 77 msec
;; SERVER: 208.96.10.221#53(208.96.10.221)
;; WHEN: Mon Aug 04 17:09:23 2008
;; MSG SIZE  rcvd: 139

The MX servers are "mx1.balanced.frisky.mail.dreamhost.com" and "mx2.balanced.frisky.mail.dreamhost.com". Just the information we needed!

Recent Features

  • By
    Send Text Messages with PHP

    Kids these days, I tell ya.  All they care about is the technology.  The video games.  The bottled water.  Oh, and the texting, always the texting.  Back in my day, all we had was...OK, I had all of these things too.  But I still don't get...

  • By
    5 Ways that CSS and JavaScript Interact That You May Not Know About

    CSS and JavaScript:  the lines seemingly get blurred by each browser release.  They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely.  We have our .js files and our .css, but...

Incredible Demos

  • By
    Create a Sexy Persistent Header with Opacity Using MooTools or jQuery

    I've been working with the Magento eCommerce solution a lot lately and I've taken a liking to a technique they use with the top bar within their administrative control panel. When the user scrolls below a specified threshold, the top bar becomes attached to the...

  • By
    Making the Firefox Logo from HTML

    When each new t-shirt means staving off laundry for yet another day, swag quickly becomes the most coveted perk at any tech company. Mozilla WebDev had pretty much everything going for it: brilliant people, interesting problems, awesome office. Everything except a t-shirt. That had to change. The basic...

Discussion

  1. Not Me

    This is not about Cygwin. It’s about dig.

  2. @Anonymous Coward: True, you don’t NEED Cygwin. Windows based users will likely use Cygwin, otherwise there’s a Windows command line tool to do it. That said, I recommend Cygwin for Windows users.

  3. Not Me

    Not a coward. I just didn’t want your friends to know your mom is reading your blog. ;)

  4. You know David, if you keep posting about Linux apps you might have to just dive in and give Linux a test drive. You might even dump Windows as your primary work environment, as I did many years ago.

    These handy apps aren’t the only thing that give Linux a great reputation.

  5. @Anonymous Coward: Well played, sir! :)

    @Mark: I actually have an old machine to take home and install Linux. I’ll give it a try, but I doubt I’ll make that jump…yet.

  6. Well it seems you may be more successful at converting people than me!

    Nice post!

  7. ..why would anyone like to see a whole zone record?
    host -t MX domain.tld

  8. Grumble grumble

    So … which Cygwin package contains dig?

  9. Janis

    Exactly, Grumble grumble, I have Cygwin and I cannot see dig in their package list… :\

  10. Janis

    OK, I find the package – it’s “bind”.

  11. @Janis: ah! That’s what I was looking for!

    Maybe update the post to tell ppl that info as well?

  12. @Dominic B: Will do!

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!