Wednesday, November 10, 2010

Updating a DNS record

SkyHi @ Wednesday, November 10, 2010

Changing DNS records can result in your website being unreachable for a while.
This article explains how you can minimize downtime while changing domain name records.



NS records


When changing nameserver records, first ensure that your new nameserver(s) define
the same records as your old nameservers. That is to say, your new nameservers
must be in a ready-to-use state.

Now you can change your NS records so that they point to the new nameserver(s).
But pay attention to the fact, that the NS records of your parent DNS servers are usually
cached for 48 hours. Thus you should keep your old nameservers online for at
least 48 hours after making the changes to your NS records.


Other records


For A records, MX records, PTR records and the like there is a nice way to
update a record while still not having inconsistent data. What I mean by "inconsistent"
is the following scenario:

Suppose you have an A record for www.dnswatch.info pointing to the IP address
193.111.199.111 with a "Time To Live" value set to 3600 (1 hour). And let's further
assume that you now want to update this A record so that it points to the IP
address 193.111.199.214.

If you just changed the record now, DNS resolvers all over the world who don't
have the old data cached would instantly see the new IP address (193.111.199.214).
But DNS resolvers who do have this record cached (e.g. a resolver who already queried
your nameserver 8 minutes ago) would still see the old IP address (193.111.199.111).
So if a resolver queried your nameserver 8 minutes ago, it would see the old
data for the next 52 minutes because the "Time To Live" value's set
to 1 hour meaning that the record may be cached for 1 hour.

If for example, there was some webserver behind those IPs, some browsers would now be accessing
your old webserver (on the old IP) and some would request data from your new webserver (on the new IP).



The easy solution to this inconsistent state is as follows:

First reduce the TTL of the record that you want to change to a minimal value,
e.g. 30 seconds. Then wait "old TTL value" seconds. So we'd
have had to wait 1 hour in our last example after reducing the TTL to 30 because
the old TTL was 1 hour. After that period you can change your data. Or you can
now even further reduce the TTL to 5 seconds. Then wait 30 seconds, and then do
the actual update to the record. This results in your DNS data being inconsistent
for only 5 seconds instead of an hour as in the initial example.
Don't forget however to increase the TTL again, after changing the record
and assuring that your change was successful. If you leave the TTL at 5 seconds,
your DNS servers could get overwhelmed by lookup requests. In addition a DNS lookup
can take quite some time (sometimes even half a second), thus the end user would need many coffe breaks.

REFERENCES
http://www.dnswatch.info/articles/dns-update

Tuesday, November 9, 2010

Shell Scripting With mail Command

SkyHi @ Tuesday, November 09, 2010
How do I send e-mails from a shell script including file attachments?

The easiest solution is to send email from within shell scripts is mail command as follows. To send a message to one or more people, mail can be invoked with arguments which are the names of people to whom the mail will be sent:
mail -s 'subject' username
mail -s 'subject' vivek@nixcraft.net.in
mail -s 'Duplicate ip detected' -c vivek@nixcraft.net.in  ipadmin@nixcraft.net.in </var/log/ipscan.log
mail -s 'yum update failed' -c vivek@nixcraft.net.in -b  sysadins@groups.nixcraft.net.in </var/log/yum.log
mail -s 'Disk failure'  vivek@nixcraft.net.in < /tmp/message
Where,

* -s 'word1 word2' : Specify subject on command line.
* -c : Send carbon copies to list of users.
* -b : Send blind carbon copies to list. List should be a comma-separated list of names.
* < /path/to/file : Read email body using this /path/to/file.

Method #1: Sending File Attachments

The mail command will not work. You need to use uuencode command to send a binary file called reports.tar.gz:
uuencode reports.tar.gz reports.tar.gz | mail -s "Weekly Reports for $(date)" admin@groups.mgmt.nixcraft.net.i
You can email images or any file using the same format:
uuencode file1.png file1.png | mail -s "Funny" users@groups.nixcraft.net.i

Method #2: File Attachments with mutt Command

The mutt is a MUA (mail user agent) - an email client for text based session. It can be used for reading electronic mail under unix like operating systems, including support color terminals, MIME (attachments), and a threaded sorting mode. You can use mutt command as follows to send email attachments:
mutt -s "Filewall logs" -a /tmp/fw.logs.gz vivek@nixcraft.net.in < /tmp/emailmessage.txt
Tip # 1: Empty Mail Body

To use an empty line as the mail body use special file /dev/null or echo command as follows:
echo | mutt -s 'Subject' -a attachment.tar.gz vivek@nixcraft.net.in
mutt -s 'Subject' -a attachment.tar.gz vivek@nixcraft.net.in </dev/null
mail -s "Disk failed @ $(hostname)" mobilenumber@services.api.nixcraft.net.in </dev/null
Tip #2: Writing Mail Body Using Here documents

The here documents (redirection) tells the shell to read input from the current source (HERE) until a line containg only word (HERE) is seen:
#!/bin/bash
...
....
mail -s "Disk Failed" vivek@nixcraft.net.in<<EOF
NAS server [ mounted at $(hostname) ] is running out of disk space!!!
Current allocation ${_SPACE} @ $(date)
EOF
...
..

Tip # 3: Conditional Mail

Use the if else if and the exit status of a command as follows:
[ $(grep -c -i "hardware error" /var/log/mcelog) -gt 0 ] && { echo "Hardware errors found on $(hostname) @ $(date). See log file for the details /var/log/mcelog." | mail -s "HW Errors" mobilephone@api.nixcraft.net.in ;}


OR
#!/bin/bash
....
.....
# backup dirs using gnu/tar
/usr/bin/tar --exclude "*/proc/*" --exclude "*/dev/*" --exclude '*/cache/*' -zcvf /nas05/backup.tar.gz /var/www/html /home/vivek
 
# send an email if backup failed
if [ $? -ne 0 ]
then
 /usr/bin/mail -s "GNU/TAR Backup Failed" vivek@nixcraft.net.in<EOF
GNU/Tar backup failed @ $(date) for $(hostname)
EOF
else
 /usr/bin/logger "Backup done"
fi
....
..
# clean up
rm $_filename




REFERENCES
http://www.cyberciti.biz/faq/linux-unix-bash-ksh-csh-sendingfiles-mail-attachments/

Google Apps Domain Create SPF Records For BIND or Djbdns

SkyHi @ Tuesday, November 09, 2010
I work for a small business and outsourced our email hosting to Google. However, I noticed that spammers are using our From: First Last to send their spam messages. All bounced messages come to our catch only account. How do I stop this? How do I validate our domain using SPF? How do I configure a SPF for Google Apps domain using BIND 9 or djbdns?

You must create a Sender Policy Framework (SPF) recored for all your domains which are used to send emails. An SPF can identifies which mail servers are permitted to send email on behalf of your domain. This is used to prevent spammers from sending messages with forged From addresses at your domain such as foo@example.com, where foo is not a valid username. In this example, spammers use foo@example.com to send spam to vivek@nixcraft.net.in. When my mail server receives a message from foo@example.com, it will check the SPF record for example.com to find out if it is a valid message or not. If the message comes from a server other than the mail servers listed in the SPF record, than my mail server can reject it as spam or mark as spam.

Sample Setup

nixcraft.com can send email using the ALL of the following servers:
      ///
       |                                        +----------------------+
    Mail Server (point to)                      | server1.nixcraft.com | w/ local sendmail 74.86.48.99
       |                             +----------+----------------------+
   +------------+                    |
   |   Google   |                    |          +----------------------+
   |   Apps     |                    |          | server2.nixcraft.com | w/ local sendmail 74.86.48.98
   |   Mail     +--------------------+----------+----------------------+
   |   Server   |                    |
   +------------+                    |          +----------------------+
         |                           |          | server3.nixcraft.com | w/ local sendmail 74.86.48.102
 nixcraft.com.s7b1.psmtp.com.        +----------+----------------------+
 nixcraft.com.s7b2.psmtp.com.
 nixcraft.com.s7a1.psmtp.com.
 nixcraft.com.s7a2.psmtp.com.
 
Consider the following examples:
$ host -t mx nixcraft.com

Sample outputs:
nixcraft.com mail is handled by 4 nixcraft.com.s7b2.psmtp.com.
nixcraft.com mail is handled by 1 nixcraft.com.s7a1.psmtp.com.
nixcraft.com mail is handled by 2 nixcraft.com.s7a2.psmtp.com.
nixcraft.com mail is handled by 3 nixcraft.com.s7b1.psmtp.com.
Above four MX servers receive mail for nixcraft.com domain. All of the above servers are managed by Google apps. However, nixcraft.com has 3 KVM based vps server to host its website. Those 3 nodes also send emails to its customers or users. You need to add them to your list too:
kvm1: 74.86.48.99
kvm2: 74.86.48.98
kvm3: 74.86.48.102


Finally, its public ip address may also send an email to its customer or users:
$ host nixcraft.com
Sample outputs:
75.126.153.214

How Do I Build a SPF Record for nixcraft.com?

You need to add the entry as follows in nixcraft.com zone file (BIND 9 syntax):

@ 3600   IN TXT   "v=spf1 a mx ip4:74.86.48.99 ip4:74.86.48.98 ip4:74.86.48.102 include:_spf.google.com ~all"
If you are using djbdns, enter:

'nixcraft.com:v=spf1 ip4\07274.86.48.99 ip4\07274.86.48.102 ip4\07274.86.48.98 a mx include\072_spf.google.com ~all:3600
'nixcraft.com.s7a1.psmtp.com:v=spf1 a -all:3600
'nixcraft.com.s7a2.psmtp.com:v=spf1 a -all:3600
'nixcraft.com.s7b1.psmtp.com:v=spf1 a -all:3600
'nixcraft.com.s7b2.psmtp.com:v=spf1 a -all:3600
's7a1.psmtp.com:v=spf1 a -all:3600
's7a2.psmtp.com:v=spf1 a -all:3600
's7b1.psmtp.com:v=spf1 a -all:3600
's7b2.psmtp.com:v=spf1 a -all:3600

Where,
  • @ : Domain name i.e. nixcraft.com.
  • 3600 : TTL for domain recored.
  • IN TXT "v=spf1 : Start an SPF recored.
  • a : nixcraft.com's IP address is 75.126.153.214 which is allowed to send mail from nixcraft.com.
  • mx : The *.psmtp.com. servers are allowed to send mail from nixcraft.com.
  • ip4:74.86.48.99 : 74.86.48.99 is allowed to send mail from nixcraft.com.
  • ip4:74.86.48.98 : 74.86.48.98 is allowed to send mail from nixcraft.com.
  • ip4:74.86.48.102 : 74.86.48.102 is allowed to send mail from nixcraft.com.
  • include:_spf.google.com: Send mail from _spf.google.com (includes large number of Google apps server) is also allowed to send mail from nixcraft.com.
  • ~all : Messages that are not sent from an approved server should still be accepted but may be subjected to greater scrutiny or spam check.
Finally, reload your BIND 9 named (don't forget to increase serial number):
# /etc/init.d/named reload

How Do I Verify My SPF Records?

Type the following command:
$ dig txt nixcraft.com
OR
$ host -t txt nixcraft.com

Sample outputs:

nixcraft.com descriptive text "v=spf1 a mx ip4:74.86.48.99 ip4:74.86.48.98 ip4:74.86.48.102 include:_spf.google.com ~all"

REFERENCES
http://www.cyberciti.biz/faq/bind-named-djbdns-google-apps-sender-policy-framework/

PHP Create an Array of the Last 30 Days

SkyHi @ Tuesday, November 09, 2010
<?php
$d = array();
for($i = 0; $i < 30; $i++) 
    $d[] = date("d", strtotime('-'. $i .' days'));
?> 


REFERENCES
http://stackoverflow.com/questions/337760/create-an-array-of-the-last-30-days-using-php

Counting the occurrences of a substring - the fastest way

SkyHi @ Tuesday, November 09, 2010
So what is the fastest way to count how often a substring occurs inside a string, e.g. how many dashes can be found in “1-4-7-8-37-5-7-8-3-42″? I identified five ways to make Perl say “9″ to this challenge:

   1. my $size = (scalar(@{[$string =~ /-/g]}) + 1);
   2. my $size = scalar(split /-/, $string);
   3. my $size = (($string =~ s/-//g) + 1);
   4. my $size = (($string =~ tr/-//) + 1);
   5. my $size = 1; $size++ while $string =~ /-/g;

I would have assumed that number 1 would be the fastest way as it requires no modifcation of the string. A quick run with “cmpthese” from the Benchmark module revealed that my assumption was wrong:

Rate            match (1)       split (2)     while (5)     repl (3)     tr (4)
match (1)    51106/s          –               -90%         -93%      -94%        -95%
split (2)       495540/s        870%         –              -36%       -45%       -47%
while (5)     771605/s        1410%       56%          –            -15%        -18%
repl (3)       908265/s        1677%       83%       18%           –               -4%
tr (4)          941620/s         1742%        90%      22%          4%                –

The table shows a clear advantage when counting the occurrences via a while-loop (solution 5), count the replaced characters (solution 3) or truncating all occurrences (solution 4). While “tr” was the fastest way during this test run, it wasn’t the best way on other benchmark runs or others systems. If you want to try it yourself you can do so with the attached test-script.

Cluebringer tracking.pm :
my $p = '\<(.*?)\>';
#my $totalrecipient =0;
#$totalrecipient++ while DBQuote($sessionData->{'RecipientData'}) =~ /$p/g;
my $totalrecipient = (scalar(@{[DBQuote($sessionData->{'RecipientData'}) =~ /$p/g]}));


REFERENCES
http://www.chengfu.net/2005/10/count-occurrences-perl/

PHP: Best way to extract text within parenthesis?

SkyHi @ Tuesday, November 09, 2010
parenthesis:
<?php

$text = 'ignore everything except this (text)';
preg_match('#\((.*?)\)#', $text, $match);

echo '
';
print_r($match[1]);
echo '
';



square bracket :

<?php
$text = 'ignore everything except this (text)';
preg_match('#\<(.*?)\>#', $text, $match);

echo '
';
print_r($match[1]);
echo '
';


REFERENCES
http://stackoverflow.com/questions/196520/php-best-way-to-extract-text-within-parenthesis

Linux / UNIX: DNS Lookup Command

SkyHi @ Tuesday, November 09, 2010
How do I perform dns lookup under Linux or UNIX or Apple OS X operating systems without using 3rd party web sites for troubleshooting DNS usage?

You can use any one of the following dns lookup utility under Linux / UNIX. You can skip all 3rd party websites and use the following to debug your dns servers and lookup issues:
[a] host command - DNS lookup utility.
[b] dig command - DNS lookup utility.
Both commands will allow you to get answer to various dns queries such as the IP address (A), mail exchanges (MX), name servers (NS), text annotations (TXT), or ANY (all) type.

host DNS Lookup Examples

host command is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host command displays a short summary of its command line arguments and options. The syntax is as follows:
host example.com
host -t TYPE example.com
host -t a example.com

Task: Find Out the Domain IP

$ host -t a cyberciti.biz
Sample outputs:
cyberciti.biz has address 75.126.153.206

Task: Find Out the Domain Mail Server

$ host -t mx cyberciti.biz
Sample outputs:
cyberciti.biz mail is handled by 2 CYBERCITI.BIZ.S9A2.PSMTP.com.
cyberciti.biz mail is handled by 3 CYBERCITI.BIZ.S9B1.PSMTP.com.
cyberciti.biz mail is handled by 4 CYBERCITI.BIZ.S9B2.PSMTP.com.
cyberciti.biz mail is handled by 1 CYBERCITI.BIZ.S9A1.PSMTP.com.

Task: Find Out the Domain Name Servers

$ host -t ns cyberciti.biz
Sample outputs:
cyberciti.biz name server ns2.nixcraft.net.
cyberciti.biz name server ns1.nixcraft.net.
cyberciti.biz name server ns5.nixcraft.net.
cyberciti.biz name server ns4.nixcraft.net.

Task: Find Out the Domain TXT Recored (e.g., SPF)

$ host -t txt cyberciti.biz
Sample outputs:
cyberciti.biz descriptive text "v=spf1 a mx ip4:74.86.48.99 ip4:74.86.48.98 ip4:74.86.48.102 ip4:74.86.48.101 ip4:74.86.48.100 ip4:72.26.218.170 ip4:93.89.92.12 ip4:180.92.186.178 include:_spf.google.com ~all"

Task: Find Out the Domain CNAME Record

$ host -t cname files.cyberciti.biz
Sample outputs:
files.cyberciti.biz is an alias for files.cyberciti.biz.edgesuite.net.

Task: Find Out the Domain SOA Record

$ host -t soa cyberciti.biz
Sample outputs:
cyberciti.biz has SOA record ns1.nixcraft.net. vivek.nixcraft.com. 2008072353 10800 3600 604800 3600

Task: Query Particular Name Server

Query ns2.nixcraft.net:
$ host cyberciti.biz ns2.nixcraft.net
Sample outputs:
Using domain server:
Name: ns2.nixcraft.net
Address: 75.126.168.152#53
Aliases: 

cyberciti.biz has address 75.126.153.206
cyberciti.biz has IPv6 address 2607:f0d0:1002:51::4
cyberciti.biz mail is handled by 3 CYBERCITI.BIZ.S9B1.PSMTP.com.
cyberciti.biz mail is handled by 4 CYBERCITI.BIZ.S9B2.PSMTP.com.
cyberciti.biz mail is handled by 1 CYBERCITI.BIZ.S9A1.PSMTP.com.
cyberciti.biz mail is handled by 2 CYBERCITI.BIZ.S9A2.PSMTP.com.

Task: Display All Information About Domain Records and Zone

You need to pass the -a (all) option and asking host command to make a query of type ANY:
$ host -a cyberciti.biz
OR
$ host -t any cyberciti.biz
Sample outputs:
Trying "cyberciti.biz"
;; Truncated, retrying in TCP mode.
Trying "cyberciti.biz"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34079
;; flags: qr rd ra; QUERY: 1, ANSWER: 14, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;cyberciti.biz.   IN ANY

;; ANSWER SECTION:
cyberciti.biz.  3423 IN AAAA 2607:f0d0:1002:51::4
cyberciti.biz.  3600 IN SOA ns1.nixcraft.net. vivek.nixcraft.com. 2008072353 10800 3600 604800 3600
cyberciti.biz.  3600 IN TXT "v=spf1 a mx ip4:74.86.48.99 ip4:74.86.48.98 ip4:74.86.48.102 ip4:74.86.48.101 ip4:74.86.48.100 ip4:72.26.218.170 ip4:93.89.92.12 ip4:180.92.186.178 include:_spf.google.com ~all"
cyberciti.biz.  3600 IN MX 2 CYBERCITI.BIZ.S9A2.PSMTP.com.
cyberciti.biz.  3600 IN MX 3 CYBERCITI.BIZ.S9B1.PSMTP.com.
cyberciti.biz.  3600 IN MX 4 CYBERCITI.BIZ.S9B2.PSMTP.com.
cyberciti.biz.  3600 IN MX 1 CYBERCITI.BIZ.S9A1.PSMTP.com.
cyberciti.biz.  2805 IN A 75.126.153.206
cyberciti.biz.  3423 IN NS ns2.nixcraft.net.
cyberciti.biz.  3423 IN NS ns5.nixcraft.net.
cyberciti.biz.  3423 IN NS ns1.nixcraft.net.
cyberciti.biz.  3423 IN NS ns4.nixcraft.net.
cyberciti.biz.  84092 IN RRSIG NSEC 8 2 86400 20101125013720 20101026010313 50568 biz. OjDv09mccTZR2bYCl4D57QcnNEkBq6bNEa20ExsI6NC2sI9pmiKLnq+w UnCYxWMnkMi7WNXwIhhUWtNhV48X3wJGj1Mufrhq8MnO25JIcRE6UJF2 y12TTZHHE0UJV6HSkw1sac3XlZKXLi/oSvE/IXTsdj2SckPh+pMlaieQ jAA=
cyberciti.biz.  84092 IN NSEC CYBERCITIZEN.biz. NS RRSIG NSEC

Received 749 bytes from 192.168.1.254#53 in 0.1 ms

Task: Use IPv6 Query Transport

Test your dns lookup using IPv6 query transport (you must have IPV6 based connectivity including IPv6 enabled resolving name servers):
$ host -6 cyberciti.biz
$ host -6 -a cyberciti.biz
$ host -6 cyberciti.biz ns1.nixcraft.net
$ host -6 -t ns cyberciti.biz ns3.nixcraft.net
Sample outputs:
Using domain server:
Name: ns3.nixcraft.net
Address: 2001:48c8:10:1::2#53
Aliases: 

cyberciti.biz name server ns2.nixcraft.net.
cyberciti.biz name server ns4.nixcraft.net.
cyberciti.biz name server ns5.nixcraft.net.
cyberciti.biz name server ns1.nixcraft.net.

Task: Reverse IP Lookup

Type the command:
$ host {IP-Address-Here}
$ host 75.126.153.206

Sample outputs:
206.153.126.75.in-addr.arpa domain name pointer www.cyberciti.biz.

Task: Get TTL Information

Type the command as follows:
$ host -v -t {TYPE} {example.com}
$ host -v -t a cyberciti.biz
$ host -v -t a i.hexindia.net

Sample outputs:
Trying "cyberciti.biz"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17431
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 7

;; QUESTION SECTION:
;cyberciti.biz.   IN A

;; ANSWER SECTION:
cyberciti.biz.  1866 IN A 75.126.153.206

;; AUTHORITY SECTION:
cyberciti.biz.  3850 IN NS NS1.NIXCRAFT.NET.
cyberciti.biz.  3850 IN NS NS4.NIXCRAFT.NET.
cyberciti.biz.  3850 IN NS NS5.NIXCRAFT.NET.
cyberciti.biz.  3850 IN NS NS2.NIXCRAFT.NET.

;; ADDITIONAL SECTION:
NS1.NIXCRAFT.NET. 85669 IN A 72.26.218.170
NS1.NIXCRAFT.NET. 85689 IN AAAA 2001:48c8:7::2
NS2.NIXCRAFT.NET. 85669 IN A 75.126.168.152
NS2.NIXCRAFT.NET. 85669 IN AAAA 2607:f0d0:1002:51::3
NS4.NIXCRAFT.NET. 85669 IN A 93.89.92.12
NS4.NIXCRAFT.NET. 85669 IN AAAA 2a01:348:0:15:5d59:50c:0:1
NS5.NIXCRAFT.NET. 85669 IN AAAA 2001:48c8:10:1::2

Received 291 bytes from 10.0.80.11#53 in 2 ms
If you run the same command again, you’ll notice that the TTL number (1866) reduced.

dig DNS Lookup Examples

dig (domain information groper) or host command 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. hos dns lookup tool have less functionality than dig.

Examples

dig @{ns1.example.com} {example.com}
dig @{ns1.example.com} {example.com} {TYPE}
dig cyberciti.biz a
dig cyberciti.biz mx
dig cyberciti.biz ns
dig cyberciti.biz txt
dig @ns1.nixcraft.net cyberciti.biz a

Task: Trace Usage

See how domains are resolved using root servers i.e. turn on tracing of the delegation path from the root name servers for the name being looked up. When tracing is enabled, dig makes iterative queries to resolve the name being looked up. It will follow referrals from the root servers, showing the answer from each server that was used to resolve the lookup:
$ dig +trace cyberciti.biz
Sample outputs:
<<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> +trace cyberciti.biz
;; global options:  printcmd
.   41219 IN NS b.root-servers.net.
.   41219 IN NS e.root-servers.net.
.   41219 IN NS i.root-servers.net.
.   41219 IN NS d.root-servers.net.
.   41219 IN NS g.root-servers.net.
.   41219 IN NS k.root-servers.net.
.   41219 IN NS l.root-servers.net.
.   41219 IN NS c.root-servers.net.
.   41219 IN NS m.root-servers.net.
.   41219 IN NS a.root-servers.net.
.   41219 IN NS h.root-servers.net.
.   41219 IN NS j.root-servers.net.
.   41219 IN NS f.root-servers.net.
;; Received 436 bytes from 10.0.80.11#53(10.0.80.11) in 2 ms

biz.   172800 IN NS h.gtld.biz.
biz.   172800 IN NS c.gtld.biz.
biz.   172800 IN NS e.gtld.biz.
biz.   172800 IN NS b.gtld.biz.
biz.   172800 IN NS g.gtld.biz.
biz.   172800 IN NS a.gtld.biz.
biz.   172800 IN NS f.gtld.biz.
;; Received 316 bytes from 192.228.79.201#53(b.root-servers.net) in 34 ms

cyberciti.biz.  7200 IN NS NS5.NIXCRAFT.NET.
cyberciti.biz.  7200 IN NS NS1.NIXCRAFT.NET.
cyberciti.biz.  7200 IN NS NS2.NIXCRAFT.NET.
cyberciti.biz.  7200 IN NS NS4.NIXCRAFT.NET.
;; Received 115 bytes from 2001:503:8028:ffff:ffff:ffff:ffff:ff7e#53(h.gtld.biz) in 23 ms

cyberciti.biz.  3600 IN A 75.126.153.206
cyberciti.biz.  3600 IN NS ns4.nixcraft.net.
cyberciti.biz.  3600 IN NS ns5.nixcraft.net.
cyberciti.biz.  3600 IN NS ns1.nixcraft.net.
cyberciti.biz.  3600 IN NS ns2.nixcraft.net.
;; Received 307 bytes from 2001:48c8:10:1::2#53(NS5.NIXCRAFT.NET) in 222 ms

Task: Get Only Short Answer

A quick way to just get the answer is to type the following command:
$ dig +short cyberciti.biz
Sample outputs:
75.126.153.206

Task: Display All Records

$ dig +noall +answer cyberciti.biz any
Sample outputs:
cyberciti.biz.  3490 IN A 75.126.153.206
cyberciti.biz.  2733 IN NS NS2.NIXCRAFT.NET.
cyberciti.biz.  2733 IN NS NS1.NIXCRAFT.NET.
cyberciti.biz.  2733 IN NS NS4.NIXCRAFT.NET.
cyberciti.biz.  2733 IN NS NS5.NIXCRAFT.NET.
cyberciti.biz.  85668 IN RRSIG NSEC 8 2 86400 20101125013720 20101026010313 50568 biz. OjDv09mccTZR2bYCl4D57QcnNEkBq6bNEa20ExsI6NC2sI9pmiKLnq+w UnCYxWMnkMi7WNXwIhhUWtNhV48X3wJGj1Mufrhq8MnO25JIcRE6UJF2 y12TTZHHE0UJV6HSkw1sac3XlZKXLi/oSvE/IXTsdj2SckPh+pMlaieQ jAA=
cyberciti.biz.  85668 IN NSEC CYBERCITIZEN.biz. NS RRSIG NSEC

Task: Reverse IP Lookup

Type the following command:
$ dig -x +short {IP-Address-here}
$ dig -x 75.126.153.206 +short

Sample outputs
www.cyberciti.biz.

Task: Find Domain SOA Record

$ dig +nssearch cyberciti.biz
Sample outputs:
SOA ns1.nixcraft.net. vivek.nixcraft.com. 2008072353 10800 3600 604800 3600 from server ns5.nixcraft.net in 81 ms.
SOA ns1.nixcraft.net. vivek.nixcraft.com. 2008072353 10800 3600 604800 3600 from server ns4.nixcraft.net in 216 ms.
SOA ns1.nixcraft.net. vivek.nixcraft.com. 2008072353 10800 3600 604800 3600 from server ns1.nixcraft.net in 347 ms.
SOA ns1.nixcraft.net. vivek.nixcraft.com. 2008072353 10800 3600 604800 3600 from server ns2.nixcraft.net in 316 ms.

Task: Find Out TTL Value Using dig

$ dig +nocmd +noall +answer {TYPE} {example.com}
$ dig +nocmd +noall +answer a cyberciti.biz

Sample outputs:
cyberciti.biz.  1642 IN A 75.126.153.206
Run again, enter:
$ dig +nocmd +noall +answer a cyberciti.biz
Sample outputs:
cyberciti.biz.  1629 IN A 75.126.153.206

See also:

See man page for more information:
man dig
man host


REFERENCES
http://www.cyberciti.biz/faq/unix-linux-dns-lookup-command/