Introduction
The 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.
Prerequisites
- A Linux system (this tutorial uses Ubuntu 22.04).
- Access to the terminal.
Linux host Command Syntax
The host
command syntax is:
host [options] [domain hostname IP address]
The domain
, hostname
, and 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:
host
Options are not mandatory, but they modify host
's behavior and print different output.
Linux Host Command Options
The host
command has many arguments that allow users to modify the output. Therefore, the following table provides the most significant host
options:
Option | Description |
---|---|
-v | Enables verbose output. |
-a | Equivalent to -v . |
-t | Specifies the query type. |
-R | Determines the number of retries for UDP packets. |
-T | Enables TCP/IP mode. |
-w | Specifies to wait forever for a reply. |
-W | Determines how long to wait for a reply. |
-4 | Uses IPv4 query transport only. |
-6 | Uses IPv6 query transport only. |
-m | Sets memory debugging flag. |
-c | Sets the DNS class for the query. |
-s | 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
To find the IP address and related details of the host machine, use the following syntax:
host [hostname]
For example, if the hostname is phoenixnap, run:
host phoenixnap
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]
For example:
host 10.0.2.15
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:
host [domain]
For example:
host youtube.com
The output shows the resolved IP addresses.
Discover DNS Details
The Domain Name System (DNS) is a distributed database system primarily responsible for translating IP addresses into domain names and vice versa.
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).
For instance:
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
For instance:
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
The 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
Conclusion
After reading this article, you know everything about the Linux host
command to start using it.
Next, learn about DNS configuration.