host Command in Linux: DNS Lookup

By 

Published on

6 min read

Running DNS lookups with the host command in a Linux terminal

When a domain fails to resolve, an email bounces, or you simply want to know which IP a name points to, you need a quick way to ask DNS directly. The host command is built for exactly that. It is small, fast, and gives a clean one-line answer for the most common questions, which makes it a good first stop before reaching for heavier tools.

The host command is part of the BIND utilities and converts names to addresses and back. It sits between the terse nslookup and the detailed dig, returning enough information for everyday lookups.

This guide explains how to use the host command for forward and reverse lookups, specific record types, and queries against a chosen name server.

Syntax

The general form of the command is:

txt
host [OPTIONS] NAME [SERVER]

NAME is the domain, hostname, or IP address you want to look up. SERVER is optional and lets you send the query to a specific name server instead of the system default.

On most distributions, host is provided by the bind9-host or bind-utils package. If it is missing, install it on Ubuntu, Debian, and Derivatives:

Terminal
sudo apt install bind9-host

On Fedora, RHEL, and Derivatives:

Terminal
sudo dnf install bind-utils

Look Up a Domain

The most common use is resolving a domain to its addresses. Pass the name with no options:

Terminal
host example.com
output
example.com has address 23.215.0.136
example.com has address 96.7.128.175
example.com has IPv6 address 2600:1406:bc00:53::b81e:94c8
example.com has IPv6 address 2600:1406:3a00:21::173e:2e65
example.com mail is handled by 0 .

The output lists the current IPv4 and IPv6 addresses and any mail-routing information in plain language. The line mail is handled by 0 . is a null MX record (RFC 7505): the single dot as the mail server means the domain accepts no mail. DNS records can change, so your addresses may differ from this example. For a name with multiple A records, host prints one line per address.

Reverse Lookup

To go the other way and find the hostname for an IP address, pass the address instead of a name. The host command detects that it is an IP and performs a reverse (PTR) lookup automatically:

Terminal
host 8.8.8.8
output
8.8.8.8.in-addr.arpa domain name pointer dns.google.

The result is the pointer record that maps the address back to a name. Reverse records are configured by whoever controls the IP block, so not every address has one.

Query a Specific Record Type

DNS holds more than addresses. Use the -t option to request a particular record type, such as MX for mail servers, NS for name servers, TXT for text records, or CNAME for aliases.

To find the mail servers for a domain:

Terminal
host -t MX gmail.com
output
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.

The number before each server is its priority, where a lower value is preferred. The order of equally valid output lines may vary. To list the authoritative name servers:

Terminal
host -t NS example.com

TXT records often hold SPF, DKIM, or domain-verification strings:

Terminal
host -t TXT example.com

Each record type answers a different operational question, so -t is the option you will reach for most.

Request ANY Records

The -a option enables verbose output and requests the ANY record type:

Terminal
host -a example.com

Despite its name, this option does not reliably return every DNS record. Many authoritative servers follow RFC 8482 and send a minimal response to ANY queries. Use separate -t queries for the record types you need, such as A, AAAA, MX, NS, and TXT.

Query a Specific Name Server

By default host uses the resolvers configured on your system. To ask a particular server, add it as the final argument. This is the way to compare what different servers return, which helps when you are checking whether a DNS change has propagated:

Terminal
host example.com 1.1.1.1

Here the query goes to Cloudflare’s 1.1.1.1 resolver rather than your default. If the answer differs from your local resolver, the resolvers may hold records with different remaining cache lifetimes. Clearing your local cache can also help; see our guide on how to clear the DNS cache .

Useful Options

A few options cover most of what you will need beyond the basics:

  • -t TYPE - Query a specific record type (A, AAAA, MX, NS, TXT, CNAME, PTR, SOA).
  • -a - Request ANY records with verbose output. The server may return a minimal response.
  • -v - Enable verbose output in a format similar to dig.
  • -W SECONDS - Wait the given number of seconds for a reply before timing out.
  • -R NUMBER - Set how many times to retry a failed UDP query.
  • -4 or -6 - Use IPv4 or IPv6 transport only.

Quick Reference

TaskCommand
Resolve a domainhost example.com
Reverse lookuphost 8.8.8.8
Mail servershost -t MX gmail.com
Name servershost -t NS example.com
TXT recordshost -t TXT example.com
Request ANY recordshost -a example.com
Use a specific serverhost example.com 1.1.1.1
Set a timeouthost -W 2 example.com

FAQ

What is the difference between host, dig, and nslookup?
The host command gives short, readable answers and is ideal for quick lookups. The dig command returns detailed, structured output preferred for debugging. The nslookup command is an older interactive tool that still ships widely.

How do I do a reverse DNS lookup with host?
Pass the IP address directly, for example host 8.8.8.8. The command recognizes the address and queries the matching PTR record without any extra options.

Why does host return “not found: 3(NXDOMAIN)”?
NXDOMAIN means the name does not exist in DNS. Check for a typo in the name, confirm the record was actually created, and allow time for changes to propagate if the record is new.

Can host query a specific DNS server?
Yes. Add the server as the last argument, for example host example.com 1.1.1.1. This is the standard way to compare answers across resolvers when checking propagation.

Conclusion

The host command is the quickest way to answer “what does this name resolve to” from the terminal. When a lookup raises more questions, reach for the more detailed dig command , and use whois when you need registration details rather than DNS records.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page