Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Networking

Linux host command

Reference for the Linux host command: look up A, AAAA, MX, NS and TXT records, do reverse lookups, query a chosen server and read the exit status in scripts.

host is the small, friendly DNS lookup tool. Give it a name and it prints the addresses; give it an address and it prints the name; add -t and it asks for any record type. Its output is one short line per answer, which makes it easy to read and easy to parse.

It belongs to the BIND utilities (the package is called bind9-host on Debian and bind-utils on Fedora and RHEL), together with dig. Use host for quick questions and dig when you need to see the full DNS message.

Terminal
host [OPTIONS] NAME [SERVER]

Try it

host is not installed in our sandbox and there is no network, so this block is read-only:

CONSOLE
$ host example.org
example.org has address 93.184.215.14
example.org has IPv6 address 2606:2800:21f:cb07:6820:80da:af6b:8b2c
example.org mail is handled by 0 .

$ host -t mx example.org
example.org mail is handled by 0 .

$ host 93.184.215.14
14.215.184.93.in-addr.arpa domain name pointer example.org.

$ host nosuchname.invalid
Host nosuchname.invalid not found: 3(NXDOMAIN)

What works offline is the system resolver for local names, which getent queries the way ordinary programs do:

Bash Resolving local names with getent

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
host [-aCdilrsTvVw] [-c CLASS] [-N NDOTS] [-t TYPE] [-W WAIT] [-m FLAG] [-R RETRIES] NAME [SERVER]
Option Description
-t TYPE Ask for a record type: A, AAAA, MX, NS, TXT, SOA, CNAME, PTR, SRV, CAA and others.
-a "All": like -v -t ANY; prints the full answer sections.
-v Verbose output in the same layout dig uses.
-4, -6 Use IPv4 or IPv6 to talk to the DNS server.
-W SECONDS Wait this many seconds for each reply.
-R N Number of UDP retries (default 1).
-T Use TCP instead of UDP.
-l List a zone (a zone transfer, AXFR); almost always refused.
-C Compare the SOA records of all name servers of a zone.
-r Non-recursive query (clear the "recursion desired" bit).
SERVER Ask this DNS server instead of the ones in /etc/resolv.conf.

Returns: 0 when the lookup produced an answer, 1 on a failed query, and 1 with a message such as NXDOMAIN when the name does not exist. Check the exit status in scripts rather than parsing the message.

Usage notes

  • Reverse lookups are automatic. If NAME is an IP address, host asks for the PTR record under in-addr.arpa (or ip6.arpa). Many addresses have no PTR record, and that is normal.
  • Short output. Unlike dig, host hides TTLs, flags and the authority section. Add -v when you need them.
  • It queries DNS only. host does not read /etc/hosts or follow nsswitch.conf, so it can disagree with what applications see. For "what would a program resolve?" use getent hosts NAME.
  • Trailing dot. A fully qualified name ends in a dot (example.org.). Without it, host may try the search domains from /etc/resolv.conf first.
  • Quick checks. host -t ns example.org lists the authoritative servers; host -t txt example.org shows SPF and verification records.
  • Pick the server. host example.org 1.1.1.1 is a fast way to check whether your local resolver and a public one agree.
  • Scripts. host -t a NAME | awk '/has address/ {print $4}' extracts IPv4 addresses; check the exit code first.