Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

host

Simple DNS lookups with short, readable output.

Level
Everyday Linux
Group
Network
Needs root
No
Package
bind-utils

What it does

host NAME prints the addresses and mail servers of a name in plain sentences. host IP does a reverse lookup. Use -t for other record types. For details use dig.

How to write it

host [OPTION]... NAME [SERVER]

Options 20

Most used

-t TYPE
Record type: A, AAAA, MX, NS, TXT, SOA, PTR, SRV, CNAME, ANY …
-a
All: verbose output with type ANY.
-A
Almost all: like -a without RRSIG, NSEC, NSEC3.
-v, -d
Verbose (like dig output).
-C
Compare the SOA records of all authoritative servers.
-l
List a zone with a zone transfer (AXFR).
-r
No recursion.
-s
Do not try the next server after a SERVFAIL.
-T
Use TCP.
-U
Use UDP (default).
-4
Use IPv4 for the transport.
-6
Use IPv6 for the transport.
-c CLASS
Query class (IN default).
-N NDOTS
Dots needed before the name is tried as is.
-p PORT
Use another port.
-R NUMBER
Number of UDP retries.
-W WAIT
Wait this many seconds for an answer.
-w
Wait forever.
-m FLAG
Memory debugging (record, trace, usage).
-V
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Look up a name

    host www.redhat.com
    www.redhat.com is an alias for www.redhat.com.edgekey.net.
    www.redhat.com.edgekey.net is an alias for e3396.dscx.akamaiedge.net.
    e3396.dscx.akamaiedge.net has address 23.40.100.73

    Plain text answer.

  2. 2Reverse lookup

    host 192.168.122.20
    20.122.168.192.in-addr.arpa domain name pointer server2.example.com.

    PTR record of the IP.

  3. 3Mail servers

    host -t MX s0sta.com

    Check after you move mail.

  4. 4Ask another DNS server

    host server2.example.com 192.168.122.1

    The last argument is the server.

  5. 5Text records

    host -t TXT s0sta.com

    SPF and site verification records.

  6. 6Compare the SOA of all name servers

    host -C s0sta.com

    Different serials = a secondary did not get the update.

  7. 7All records, verbose

    host -a s0sta.com

    Many servers block ANY today.

  8. 8Test a zone transfer (security, own zones)

    host -l example.com ns1.example.com

    Should be refused for the public; open AXFR leaks all names.

  9. 9IPv6 address

    host -t AAAA www.google.com

    Check that IPv6 records exist.

  10. 10Quick check in a script

    host -W 2 server2 >/dev/null && echo "DNS ok"

    Exit code 0 when the name was found.

Exit codes

0 :: Found. 1 :: Not found or error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man host