DNS utility commands in linux

There are more than couple of commands that we use to query DNS records in linux. Here is the list of commands,

  • dig
  • host
  • nslookup

Command dig

Among the, command dig is widely used. It comes by default in most of distributions. If it is not available you can install it using bind-utils. Where, this is a utility which comes with bind.

Install dig

Install dig on centOS

$ yum install bind-utilis

Install dig  on debian based operating system

$ apt-get install bind-utils

A simple example using dig

Where,

@ns3.google.com tells the dig to perform DNS query on DNS server ns3.google.com. ANY  at the end of the command specified that, get all possible DNS records associated with google.com. As you can see different set of records in the output. That is, A, AAA, MX, TXT, NS and SOA.

Command host

host 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 prints a short summary of its command line arguments and   options.

Unlike dig command it give summarized output.

The -t option is used to select the query type.  type can be any recognized query type: CNAME, NS, SOA, SIG, KEY, AXFR, etc. When no query type is specified, host automatically selects an appropriate query type. By default, it looks for A, AAAA, and MX records, but if the -C option was given, queries will be made for SOA records, and if name is a dotted-decimal IPv4 address or colon-delimited IPv6 address, host will query for PTR records

An example querying MX records using utility host

Command nslookup

Command nslookup is a utility widely used for DNS lookup before dig. It is well know command that is used for DNS lookups. dig uses the OS resolver libraries. nslookup uses is own internal ones.

An example of querying TXT record of google using nslookup

Among these commands dig provides the output that resembles DNS protocol. For the one who is trying to understand DNS protocol, this tool is best choice to use. Where you can also learn from output representing four sections QUERY, ANSWER, AUTHORITY and ADDITIONAL  with flags.

 

Leave a Reply

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