host command is a command-line tool that performs DNS (Domain Name System) lookups. The tool can find a hostname when provided with an IP address. However, the command returns an IP address when given a hostname.
This tutorial explains the Linux
host command with examples.
- A Linux system (this tutorial uses Ubuntu 22.04).
- Access to the terminal.
Linux host Command Syntax
host command syntax is:
host [options] [domain hostname IP address]
IP address in the command are optional and used as needed. When run without any options, the
host shows the command usage and all options:
Options are not mandatory, but they modify
host's behavior and print different output.
Linux Host Command Options
host command has many arguments that allow users to modify the output. Therefore, the following table provides the most significant
|Enables verbose output.|
|Equivalent to |
|Specifies the query type.|
|Determines the number of retries for UDP packets.|
|Enables TCP/IP mode.|
|Specifies to wait forever for a reply.|
|Determines how long to wait for a reply.|
|Uses IPv4 query transport only.|
|Uses IPv6 query transport only.|
|Sets memory debugging flag.|
|Sets the DNS class for the query.|
|Sets the DNS server for the query.|
host Command Examples
This utility is versatile and functional in different situations. Here are common examples.
Find Host Machine IP Address
For example, if the hostname is phoenixnap, run:
The output prints the IP address and the IPV6 address.
Find Host Name Based on IP Address
The syntax for locating a system based on an IP address is:
host [IP address]
The output points to the phoenixnap hostname.
Show Addresses for Internet Domain
This utility also enables users to see IP addresses for certain internet domains with the syntax:
The output shows the resolved IP addresses.
Discover DNS Details
Use the verbose (-v) option to print more details about the domain, IP address, or hostname with this syntax:
host -v [domain IP address_or_hostname).
host -v youtube.com
The command prints detailed information about the DNS query, response, status, flags, and results.
Find Mail Exchange Info
Mail Exchange (MX) is a DNS-type record that specifies which mail servers handle email for a specific domain. These records indicate the mail servers' priorities, establishing a mail routing hierarchy.
Find the MX record for a specific domain with the following syntax:
host -v [domain] | grep MX
host -v google.com | grep MX
The MX record points to
smtp.google.com (one of the primary mail servers for Google) and indicates its priority for handling incoming emails (with the number 10)
Look Specific Record Types
The following syntax allows users to query specific record types:
host -t [record type] [domain]
For example, this is another option for finding MX records:
host -t mx google.com
Executing the same command on a different domain produces different results:
host -t mx youtube.com
host -t command allows users to check for any record type on any domain. Run the
host -t ns command followed by a domain name to print the name servers for the domain:
host -t ns google.com
View SOA Records
An SOA (Start of Authority) record is a critical DNS resource containing important DNS zone information. The syntax for viewing SOA records is:
host -v [domain] | grep SOA
However, SOA records are not needed for regular DNS queries. Moreover, SOA records are mainly used by DNS administrators and servers for zone management and are often not publicly accessible. Therefore, the following command shows no output:
host -v google.com | grep SOA
For other domains, the command works:
host -v amazon.com | grep SOA
After reading this article, you know everything about the Linux
host command to start using it.
Next, learn about DNS configuration.