The “host” Command in Linux [10 Practical Examples]

The host command in Linux is an easy-to-use command. This command is used to perform DNS lookups. The host command in Linux can be used to resolve the hostnames or IP addresses. In this article, you will learn the ins and outs of the host command in Linux.

A. Description

The main purpose of the host command is to resolve the hostnames to IP addresses and vice-versa. There are so many query types like NS(name server), SOA(start of authority), TXT(text), MX(mail exchange), and so on. These query types are used with the host command to resolve the hostnames or IP addresses. You can also use the reverse lookup to resolve the hostnames or IP addresses of servers.

B. Syntax

The syntax of the host command is simple in Linux. And the syntax is as follows:

host [OPTION] [HOSTNAME]

OR,

host [OPTION] [IP ADDRESS]

Note: In the syntax above, OPTION is enclosed by a square bracket representing that one option can be used at a time. Besides, HOSTNAME or IP ADDRESS suggests that you can specify a hostname or an IP address at a time.

C. Options

A few options are available for the host command in Linux. I have listed some of them here.

Even so, you can explore the man page to know more about the host command.

man host

You can also run the command below to view its information.

host

Useful Options

  • -a, resolves hostname with reverse lookup.
  • -t, resolves hostname using different query types.
  • -W, resolves the hostname with a timeout.
Note: The options in Linux CLI (Command Line Interface) are case-sensitive, so be alert while using them.

Practical Examples of the “host” Command in Linux

The host command in Linux is a pretty simple command. Here you will discover some useful examples of the host command in Linux.

Example 1: Resolve the Hostname to an IP Address Using the “host” Command in Linux

The hostname can be resolved to an IP address using the host command in Linux. Here I am using google.com as my hostname. To do the same you can follow the steps below:

Steps to Follow >

➊ Initially open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

host google.com

➌ Now, press the ENTER key.

Output >

In the image below, you can see the IP address of the hostname google.com.Resolve the Hostname to an IP Address Using the “host” Command in Linux


Similar Readings


Example 2: Resolve the IP Address to a Hostname Using the “host” Command in Linux

The IP address can be resolved to hostname using the host command in Linux. Here I am using the 2001:4860:4860::8888 as the IP address. To do this you can follow the process down below:

Steps to Follow >

➊ To start open the Terminal in Ubuntu.

➋ Copy the following command in the command prompt:

host 2001:4860:4860::8888

➌ After that, tap the ENTER key.

Output >

In the following image, you can see the hostname of the IP address 2001:4860:4860::8888.Resolve the IP Address to a Hostname Using the “host” Command in Linux

Example 3: Reverse Lookup on the Hostname Using the “host” Command in Linux

You can resolve the hostname to an IP address with a reverse lookup using the host command with option -a. Here I want to use the hostname google.com. You can also do this by following the procedure:

Steps to Follow >

➊ Firstly open the Ubuntu Terminal.

➋ Run the following command in the command prompt:

host -a google.com

➌ Then, hit the ENTER button.

Output >

In the image below, the hostname is resolved to an IP address with a reverse lookup using the host command in Linux.Reverse Lookup on the Hostname Using the “host” Command in Linux

Example 4: Query the DNS Server For NS (name server) Records

The query type of hostname can be selected using the host command along with option-t in Linux. Here I am using the name server records to resolve the hostname google.com. You can also do this by following the instructions below:

Steps to Follow >

➊ At first launch the Ubuntu Terminal.

➋ Write the following command in the command prompt:

host -t ns google.com

➌ Finally, press the ENTER button.

Output >

In the following image, the hostname is resolved to an IP address using the name server records in Linux.Query the DNS Server For NS (name server) Records

Example 5: Query the DNS Server For SOA (start of authority) Records

The host command along with option -t can be used to select the query type of hostname in Linux. Here I am using the SOA records to resolve the hostname google.com. You can also do the same by following the below steps:

Steps to Follow >

➊ At first launch the Terminal in  Ubuntu.

➋ Type the following command in the command prompt:

host -t SOA google.com

➌ Finally, strike the ENTER button.

Output >

In the following image, the hostname is resolved to an IP address using the SOA records in Linux.Query the DNS Server For SOA (start of authority) Records


Similar Readings


Example 6: Query the DNS Server For TXT (text) Records Using the “host” Command in Linux

You can use the host command along with option -t to select the query type of hostname in Linux. I am using the TXT records to resolve the hostname google.com here. To do the same you can follow the steps below:

Steps to Follow >

➊ To initiate launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

host -t txt google.com

➌ After that, hit the ENTER key.

Output >

In the below image, the hostname is resolved to an IP address using the TXT records in Linux.Query the DNS Server For TXT (text) Records Using the “host” Command in Linux

Example 7: Resolve the Hostname to an IP Address With a Timeout

You can resolve the hostname to an IP address with timeout using the host command with option -W. Here I am setting the timeout of 2 seconds to resolve the hostname www.google.com. To do this do follow the process below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Copy the following command in the command prompt:

host -W 2 www.google.com

➌ Now, hit the ENTER button.

Output >

In the following image, the hostname is resolved to an IP address with a timeout of 2 seconds using the host command in Linux.Resolve the Hostname to an IP Address With a Timeout

Example 8: Query the DNS Server for MX (mail exchange) Records

You can use the host command along with option -t to select the query type of hostname in Linux. I am using the MX records to resolve the hostname gmail.com. To do the same you can follow the given instructions:

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Write the following command in the command prompt:

host -t MX gmail.com

➌ Finally, tap the ENTER button.

Output >

In the below image, the hostname is resolved to an IP address using the MX records in Linux.Query the DNS Server for MX (mail exchange) Records

Example 9: Check the Hostname of a Server

The hostname command allows you to check the hostname of a server in Linux. To do this follow the procedure below:

Steps to Follow >

➊ Launch the Terminal in Ubuntu.

➋ Run the following command in the command prompt:

hostname

➌ Now, tap the ENTER key.

Output >

In the following image, the output displays the hostname which is Ubuntu in Linux.Check the Hostname of a Server

Example 10: Check the IP Address of a Server Using the “host” Command in Linux

The hostname command with option -i helps you to check the IP address of a server in Linux. To do this do follow the instructions below:

Steps to Follow >

➊ Initially launch the Terminal in Ubuntu .

➋ Copy the following command in the command prompt:

hostname -i

➌ Now, press the ENTER key.

Output >

In the image below, the output displays the IP address which is 192.168.206.130 in Linux.Check the IP Address of a Server Using the “host” Command in Linux

Conclusion

As shown in this article, the host command has some uses in Linux. You’ve also got to know the syntax, some functional options, and the practical applications of this command. To become a master in Linux, learn the command and its practical applications thoroughly.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Jannatul Ferdousi Sylvie

Hi there! This is Jannatul Ferdousi Sylvie. I am one of the Linux Content Developer Executives at Softeko. I live in Dhaka, Bangladesh. I have completed my BSc. in Software Engineering from American International University-Bangladesh. You can see my projects in the GitHub account. I love traveling, shopping, cooking, and gardening. Read Full Bio

Leave a Comment