Skip to content

The host command

One routinely needs to look up the name or IP of a machine or other device on the network. A popular way of finding out an IP address from a hostname is with the ping command, however, this only works if you need the IP address, not if you need the host name.

There are a number of tools that leverage DNS, such as nslookup, dig and host. They each have their uses which happen to be very similar. The three tools do essentially the same thing, however, it should be noted that nslookup is mostly deprecated in favor of dig and host. My personal preference between these tools is host due to its terse output.

These tools are all DNS clients, and as such they will query whatever DNS resolvers are defined on your network before proceeding to query hosts files etc, note that you can also specify the resolver you want to use via a command line argument to the tools.

So with this information, if I want to look up a machine’s hostname when only armed with it’s IP, as long there is a valid reverse DNS zone that host can query the command would look like this

$ host domain name pointer fw.domain.local.

or if I am looking for an IP or any information from a CNAME or A record (say, a hostname)

$ host fw
fw.domain.local has address

$ host intranet
intranet.domain.local is an alias for www1.domain.local.
www1.domain.local has address

Note that in the case of intranet it resolves it as an alias (CNAME) and then proceeds to resolve the actual host record as well giving me the IP address as well.

This is one of my favorite tools included with the dnsutils Linux package or Cygwin for Windows.

Post a Comment

Your email is never published nor shared. Required fields are marked *