Linux host Command with Examples

October 24, 2023

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:

OptionDescription
-vEnables verbose output.
-aEquivalent to -v.
-tSpecifies the query type.
-RDetermines the number of retries for UDP packets.
-TEnables TCP/IP mode.
-wSpecifies to wait forever for a reply.
-WDetermines how long to wait for a reply.
-4Uses IPv4 query transport only.
-6Uses IPv6 query transport only.
-mSets memory debugging flag.
-cSets the DNS class for the query.
-sSets 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.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
Troubleshooting DNS Issues {nslookup, dig, host & More}
November 17, 2021

DNS issues can be troublesome. This tutorial offers some useful tips and troubleshooting methods to help you pinpoint and resolve DNS problems...
Read more
What Is a Pretty Hostname and How to Set It Up
September 22, 2021

A pretty hostname is a high-level, free-dorm label used to identify a system in a network. This tutorial shows different ways you can set up a pretty hostname on a Linux system...
Read more
How to Use the hostname Command in Linux
October 8, 2020

The Linux hostname command lets you view your computers domain, hostname, and IP address. You can also use it to change your hostname...
Read more
How to Use the nslookup Command
January 13, 2022

Access to Domain Name System (DNS) records of a website is important for troubleshooting network related problems. This tutorial will...
Read more