Using host command linux

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:

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.

  • -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:

➌ Now, press the ENTER key.

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

In the image below, you can see the IP address of the hostname google.com.

Similar Readings

  • The “nslookup” Command in Linux [12 Practical Examples]
  • The “ufw” Command in Linux [12+ Practical Examples]
  • The “ssh” Command in Linux [18 Practical Examples]
  • The “traceroute” Command in Linux [13 Practical Examples]

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:

Читайте также:  Настройка ssh oracle linux

Steps to Follow:

➊ To start open the Terminal in Ubuntu.

➋ Copy the following command in the command prompt:

➌ After that, tap the ENTER key.

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

In the following image, you can see the hostname of the IP address 2001:4860:4860::8888.

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:

➌ Then, hit the ENTER button.

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

In the image below, the hostname is resolved to an IP address with a reverse lookup 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:

➌ Finally, press the ENTER button.

Query the DNS Server For NS (name server) Records

In the following image, the hostname is resolved to an IP address using the name server records in Linux.

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:

➌ Finally, strike the ENTER button.

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

In the following image, the hostname is resolved to an IP address using the SOA records in Linux.

Similar Readings

  • The “ dig” Command in Linux [10 Practical Examples]
  • The “hostname” Command in Linux [12 Practical Examples]
  • The “ip” Command in Linux [9+ Practical Examples]
  • The “ifconfig” Command in Linux [6+ Practical Examples]

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:

➌ After that, hit the ENTER key.

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

In the below image, the hostname is resolved to an IP address using the TXT records 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:

➌ Now, hit the ENTER button.

Resolve the Hostname to an IP Address With a Timeout

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

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:

➌ Finally, tap the ENTER button.

Query the DNS Server for MX (mail exchange) Records

In the below image, the hostname is resolved to an IP address using the MX records in Linux.

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:

➌ Now, tap the ENTER key.

Check the Hostname of a Server

In the following image, the output displays the hostname which is Ubuntu in Linux.

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:

➌ Now, press the ENTER key.

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

In the image below, the output displays the IP address which is 192.168.206.130 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

  • The “rsync” Command in Linux [10 Practical Examples]
  • The “screen” Command in Linux [13 Practical Examples]
  • The “arp” Command in Linux [7 Practical Examples]
  • The “ftp” Command in Linux [14 Practical Examples]
  • The “scp” Command in Linux [4 Practical Examples]
  • The “sftp” Command in Linux [6 Practical Examples]

Источник

Linux host command

Computer Hope

On Unix-like operating systems, the host command is a DNS lookup utility, finding the IP address of a domain name. It also performs reverse lookups, finding the domain name associated with an IP address.

This page describes the GNU/Linux version of host.

Description

host performs DNS lookups, converting domain names to IP addresses and vice versa. When no arguments or options are given, host prints a summary of its command line arguments and options.

In the syntax listed below, name is the domain name that is to be looked up. The name can also be a dotted-decimal IPv4 address or a colon-delimited IPv6 address, where host, by default, performs a reverse lookup for that address. The server is an optional argument that is either the name or IP address of the name server that host should query instead of the server or servers listed in /etc/resolv.conf.

Syntax

host [-aCdlnrsTwv] [-c class] [-N ndots] [-R number] [-t type] [-W wait] [-m flag] [-4] [-6] name> [server]

Options

-a The -a (all) option is equivalent to setting the -v option and asking host to make a query of type ANY.
-C When the -C option is used, host attempts to display the SOA records for zone name from all the listed authoritative name servers for that zone. The list of name servers is defined by the NS records that are found for the zone.
-c class The -c option instructs host to make a DNS query of class class. This can lookup Hesiod or Chaosnet class resource records. The default class is IN (Internet).
-d Verbose output is generated by host when the -d or -v option is used. The two options are equivalent. They are provided for backward compatibility. In previous versions, the -d option switched on debugging traces and -v enabled verbose output.
-l List mode is selected by the -l option. This makes host perform a zone transfer for zone name. Transfer the zone printing out the NS, PTR, and address records (A/AAAA). If combined with -a, all records are printed.
-i The -i option specifies that reverse lookups of IPv6 addresses should use the IP6.INT domain as defined in RFC1886. The default is to use IP6.ARPA.
-N ndots The -N option sets the number of dots that have to be in name to be considered absolute. The default value is that defined using the ndots statement in /etc/resolv.conf, or 1 if no ndots statement is present. Names with fewer dots are interpreted as relative names and are searched for in the domains listed in the search or domain directive in /etc/resolv.conf.
-R number The number of UDP retries for a lookup can be changed with the -R option. number indicates how many times host repeats a query that does not get answered. The default number of retries is 1. If number is negative or zero, the number of retries defaults to 1.
-r Non-recursive queries can be made via the -r option. Setting this option clears the RD («recursion desired») bit in the query which host makes. This should mean the name server receiving the query does not attempt to resolve name. The -r option enables host to mimic the behavior of a name server by making non-recursive queries and expecting to receive answers to those queries that are usually referrals to other name servers.
-T By default, host uses UDP when making queries. The -T option makes it use a TCP connection when querying the name server. TCP is automatically selected for queries that require it, such as AXFR (zone transfer) requests.
-4 The -4 option forces host to only use IPv4 query transport.
-6 The -6 option forces host to only use IPv6 query transport.
-t type The -t option is used to select the query type. The type can be any recognized query type: CNAME, NS, SOA, SIG, KEY, AXFR, etc. When no query type is specified, host automatically selects an appropriate query type. By default, it looks for A, AAAA, and MX records, but if the -C option was given, queries are made for SOA records, and if name is a dotted-decimal IPv4 address or colon-delimited IPv6 address, host queries for PTR records. If a query type of IXFR is chosen, the starting serial number can be specified by appending an equal sign followed by the starting serial number (e.g., -t IXFR=12345678).
-W wait, -w The time to wait for a reply can be controlled through the -W and -w options. The -W option makes host wait for wait seconds. If wait is less than 1, the wait interval is set to one second. When the -w option is used, host effectively waits forever for a reply. The time to wait for a response is set to the number of seconds given by the hardware’s maximum value for an integer quantity.
-s The -s option tells host not to send the query to the next nameserver if any server responds with a SERVFAIL response, which is the reverse of normal stub resolver behavior.
-m flag The -m can set the memory usage debugging flags record, usage and trace.
Читайте также:  Astra linux python pip

Examples

This command performs a reverse lookup on the IP address 204.228.150.3, which results in the output:

3.150.228.204.in-addr.arpa domain name pointer www.computerhope.com.

dig — DNS lookup utility.
nslookup — Query a name server for information about a remote host.
ping — Send ICMP ECHO_REQUEST packets to network hosts.

Источник

Оцените статью
Adblock
detector