Host command is a simple utility for performing DNS lookups in Linux. With this command, we can translate names into IP Addresses and vice versa.
Here in the article I will show you some examples of using host command in Linux system.
1) Run host command without any options
To use host command just type host and the target address. Let say you want to know the address of www.ubuntu.com. We can type :
$ host www.ubuntu.com
But we may have a different result. Take a look at the picture below.
$ host www.ibm.com
We see that www.ibm.com is an alias for another address. The last line which has an IP Address is the original address.
As mentioned before, host can also translate an IP Address into a name.
$ host 188.8.131.52
2) Display SOA record
When we use -C option, we tell the host to display SOA (Start of Authority) record from the domain name.
$ host -C ubuntu.com
As we see above, ubuntu.com has SOA record ns1.canonical.com which placed in 3 different DNS servers.
3) Specify the query
DNS is built from some records. Some of the records are SOA, CNAME, NS, A, MX, etc. When we want to query specific record, we can use -t option. Here’s some examples.
$ host -t CNAME ibm.com
$ host -t NS ibm.com
$ host -t MX ibm.com
4) Force host to query using IP version 4 transport only
By default, host will use IP version 4 and IP version 6 to query a target host. To force only use IP version 4, we can use -4 option.
$ host -4 www.debian.org
5) Force host to query using IP version 6 transport only
If we want to tell host command to query using IP version 6 only, we can use -6 option.
$ host -6 www.debian.org
Unfortunately, at the time this article is written, there is not yet a native IPv6 DNS root server. At the present time the DNS implementations available all run on top of IPv4, and the DNS system supporting IPv6 is linked to IPv4 information. So if we push to use -6 option, we will get this message.
6) Print in list mode
With -l option, we can make host perform a zone transfer for zone name. This will will print NS, PTR and address records.
$ host -l workshopdev.com
If we combine it with -a option, it will print all records.
7) Print information in verbose output
Verbose output will print all information about the target host. This information is similar with -a option below. Another option that similar with -a option is -d option.
8) Reveal all detail about the address
We can use -a parameter to reveal more detail about the specific address.
$ host -a www.ubuntu.com
Here’s how to read the information :
Question Section ; inform us that the Host command ask everything
Answer Section ; inform us that the address of www.ubuntu.com is 184.108.40.206
Authority Section ; inform us that ubuntu.com has 3 responsible DNS. NS means Name Server
Additional Section ; inform us the addresses of the three DNS above
-a parameter is equivalent with -v for verbose output and -t ANY for specifies the query type.
As usual, we can always type man host or host --help to explore more detail about host command usage.