LinuxCommandLibrary

host

Lookup DNS records for a hostname

TLDR

Lookup A, AAAA, and MX records of a domain

$ host [domain]
copy

Lookup a field (CNAME, TXT, ...) of a domain
$ host -t [field] [domain]
copy

Reverse lookup an IP
$ host [ip_address]
copy

Specify an alternate DNS server to query
$ host [domain] [8.8.8.8]
copy

SYNOPSIS

host [-aCdlnrsTwv] [-c class] [-N ndots] [-t type] [-W timeout] [-R number] [-m flag] host [server]

PARAMETERS

-a
    Make 'any' type query.

-c class
    Specify query class (e.g., IN for Internet, CH for Chaosnet).

-d
    Enable debugging.

-l
    List all domains. (Deprecated)

-n
    Disable the use of the domain search list.

-N ndots
    Set the number of dots that must be present in a domain name for it to be considered absolute.

-r
    Disable recursive query.

-s
    Send query to the server using TCP.

-t type
    Specify query type (e.g., A, MX, NS).

-T
    Retry using TCP if truncation occurs.

-w
    Wait indefinitely for a reply.

-W timeout
    Set query timeout (in seconds).

-v
    Verbose output.

-R number
    Set the number of retries for queries.

host
    The hostname or IP address to look up.

server
    The DNS server to query (optional).

DESCRIPTION

The host command is a simple utility for performing DNS lookups. It's primarily used to translate domain names into IP addresses and vice versa. Unlike more complex tools like `dig`, host is designed for quick and easy DNS queries from the command line.

It queries DNS servers for various records, including A (address), AAAA (IPv6 address), MX (mail exchange), NS (name server), and PTR (pointer) records. The output displays the results of these queries, including IP addresses associated with a domain or the domain name associated with an IP address.

While host is relatively straightforward, it is a useful tool for network administrators and developers who need to quickly verify DNS configurations, troubleshoot DNS issues, or simply obtain IP addresses associated with domain names.

CAVEATS

host uses the system's resolver library, which may be configured to use a specific DNS server. Its capabilities are limited compared to tools like `dig` or `nslookup`

The `-l` option is deprecated and may not function as expected.

EXIT STATUS

host returns an exit status of 0 if the query was successful, 1 if an error occurred, 2 if the server reported an error, and 3 if the server could not be reached, 4 if a query was timed out or 9 if there was a memory allocation failure.

HISTORY

The host command has been a part of the BIND (Berkeley Internet Name Domain) suite for a long time, evolving alongside the Domain Name System itself. It's a basic tool that has remained relatively consistent in its functionality over the years.

Initially designed for simple DNS lookups, it provides a faster, if less detailed, alternative to more comprehensive tools like `dig`. Its primary use case has always been quick DNS verification and troubleshooting.

SEE ALSO

dig(1), nslookup(1), getent(1)

Copied to clipboard