Today we are going to take a quick look at dig. According to the man pages:
dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output.
Let’s see how to lookup the DNS servers for the domain karkomaonline.com:
dig karkomaonline.com -t ns
The -t option specifies the query type (a, any, mx, ns, txt… ), being a the default. The -t ns option will look-up the Name Servers for the domain karkomaonline.com. You should get something like this:
; <<>> DiG 9.4.2-P2 <<>> karkomaonline.com -t ns
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4825
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;karkomaonline.com. IN NS
;; ANSWER SECTION:
karkomaonline.com. 172800 IN NS dns010.d.register.com.
karkomaonline.com. 172800 IN NS dns024.c.register.com.
karkomaonline.com. 172800 IN NS dns071.a.register.com.
karkomaonline.com. 172800 IN NS dns150.b.register.com.
;; ADDITIONAL SECTION:
dns010.d.register.com. 48 IN A 216.21.236.10
;; Query time: 172 msec
;; SERVER: 192.168.1.9#53(192.168.1.9)
;; WHEN: Wed Apr 15 22:46:35 2009
;; MSG SIZE rcvd: 152
The interesting part is the ANSWER SECTION, that lists the name servers for the mentioned domain. You can get a shorter output of the same command:
dig karkomaonline.com -t ns +short
dns010.d.register.com.
dns071.a.register.com.
dns024.c.register.com.
dns150.b.register.com.
Now look up the mail servers for the same domain:
dig karkomaonline.com -t mx
...
;; ANSWER SECTION:
karkomaonline.com. 86400 IN MX 0 mailhost.karkomaonline.com.
...
From the output of the first example you can see that by default dig queried my internal DNS server (configured in /etc/resolv.conf):
...
;; SERVER: 192.168.1.9#53(192.168.1.9)
...
You can change this behaviour by instructing dig to query a specific name server:
dig @dns010.d.register.com karkomaonline.com -t mx
...
;; ANSWER SECTION:
karkomaonline.com. 86400 IN MX 0 mailhost.karkomaonline.com.
;; ADDITIONAL SECTION:
mailhost.karkomaonline.com. 86400 IN A 94.75.208.171
;; Query time: 181 msec
;; SERVER: 216.21.236.10#53(216.21.236.10)
...
Note that the queried server now is 216.21.236.10.
More info::