Example Uses Of The Linux Host Command

Find The IP Address For A Domain
Find The IP Address For A Domain.

Introduction

The Linux host command is used to find out the IP address for a domain. It can also be used to find the domain name for an IP address.

This guide will show you how to use the most common switches with the host command.

The Host Command

On its own the host command will return a list of all the possible switches which can be used with it.

To get the list type the following into a terminal window:

host

The following results will be displayed:

  • -a - is equivalent to -v -t ANY
  • -c - specifies query class for non-IN data
  • -C - compares SOA records on authoritative nameservers
  • -d - is equivalent to -v
  • -l - lists all hosts in a domain, using AXFR
  • -i - IP6.INT reverse lookup
  • -N - changes the number of dots allowed before root lookup is done
  • -r - disables recursive processing
  • -R - specifies number of retries for UDP packets
  • -s - a SERVFAIL response should stop query
  • -t - specifies the query type
  • -T - enables TCP/IP mode
  • -v - enables verbose output
  • -w - specifies to wait forever for a reply
  • -W - specifies how long to wait for a reply
  • -4 - use IPv4 query transport only
  • -6 - use IPv6 query transport only
  • -m - set memory debugging flag
  • -V - print version number and exit

As with many Linux commands there are a lot of switches but most them will not be required for what you need to do.

You can find out more about the host command by reading the manual page.

Simply type the following into the terminal window:

man host

Get The IP Address For A Domain Name

To return the IP address for a domain name simply type the following command:

host <domainname>

For example to find the domain name for linux.about.com type the following command.

host linux.about.com

The results from the host command will be as follows:

linux.about.com is an alias for dynglbcs.about.com.
dynglbcs.about.com has address 207.241.148.82

Of course linux.about.com is a sub domain for about.com. Running the host command against the full about.com domain name returns a different IP address.

about.com has address 207.241.148.80

There is some further output from the host command against about.com as it displays how mail is handled.

For example:

about.com mail is handled by 500 ALT4.ASPMX.L.Google.com

Get The Domain Name From An IP Address

The opposite of returning the IP address from a domain name is returning the domain name from an IP address.

You can do this by typing the following into a terminal window:

host <IP Address>

For example we know that 207.241.148.80 is the IP address for About.com. Type the following into a terminal window:

host 207.241.148.80

The results are as follows:

82.148.241.207.in-addr.arpa domain name pointer glbny.about.com.

The host command by default returns just enough information but you can get a more detailed output by using either the -d or -v switch as follows:

host -d linux.about.com

The results from the above command shows the domain that was looked up along with any results. It also returns the SOA details for a domain.

Return The SOA Details For A Domain

SOA stands for Start Of Authority. If you register a domain name and then host that domain with a web hosting company the web hosting company must maintain an SOA for that domain. It provides a way of keeping track of domain names.

You can find the SOA details for a domain by typing the following command:

host -C <ipaddress>

host -C <domainname>

For example type the following into a terminal window:

host -C about.com

There are a number of results returned but they all contain the same fields which are as follows:

  • The primary name server
  • The responsible party for the domain
  • A timestamp which changes when the domain is updated
  • The number of seconds before the zone should be refreshed
  • The number of seconds before a failed refresh should be retried
  • The upper limit in seconds before a zone is no longer considered authoritative
  • The negative result TTL.

This web page provides a good overview about SOA.

Summary

There are obviously many other switches such as -l which provides a listing and -T which searches using TCP/IP instead of UDP.

You will find that a lot of web servers will refuse these types of query.

In general you will probably only need to use the host command to return either the IP address for a domain name or the domain name for an IP address.