Linux host Command with Examples

Introduction

Linux host Command with Examples


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.

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
host terminal output

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
host phoenixnap terminal output

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
host IP Address terminal output

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
Host internet domain terminal output

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
host -v terminal output

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
host domain grep MX terminal otput

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
host -t  mx terminal output

Executing the same command on a different domain produces different results:

host -t mx youtube.com
host tm  youtube terminal output

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
host t ns terminal output

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
host Grep SOA not working

For other domains, the command works:

 host -v amazon.com | grep SOA
host grep SOA working terminal output

Conclusion

After reading this article, you know everything about the Linux host command to start using it.

Next, learn about DNS configuration.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?