host DNS Lookup

host command cheatsheet — quick DNS lookups for A, MX, NS records. host example.com, host -t MX gmail.com, host 8.8.8.8 for reverse lookup. Simple DNS query tool.

4 min read

What it is

host is a simple utility for performing DNS lookups to find IP addresses associated with domain names, and vice-versa. You reach for it when you need a quick check of DNS records without the complexity of dig or nslookup.

Installation

Linux

sudo apt update && sudo apt install dnsutils  # Debian/Ubuntu
sudo yum install bind-utils                # CentOS/RHEL/Fedora

macOS

host is pre-installed on macOS.

Windows

host is not installed by default on Windows. You can use nslookup (built-in) or install the Windows Subsystem for Linux (WSL) and then install dnsutils within your Linux distribution.

Commands / Usage

Basic Lookups

  • Lookup A record (IPv4 address):

    host google.com
    

    Example output: google.com has address 142.250.190.142

  • Lookup AAAA record (IPv6 address):

    host -6 google.com
    

    Example output: google.com has IPv6 address 2607:f8b0:4004:808::200e

  • Lookup MX record (Mail Exchanger):

    host -t MX google.com
    

    Example output: google.com mail is handled by 10 smtp.google.com.

  • Lookup NS record (Name Server):

    host -t NS google.com
    

    Example output:

    google.com name server ns2.google.com.
    google.com name server ns1.google.com.
    google.com name server ns4.google.com.
    google.com name server ns3.google.com.
    
  • Lookup TXT record (Text records, often used for SPF, DKIM):

    host -t TXT google.com
    

    Example output: google.com descriptive text "v=spf1 include:_spf.google.com ~all"

  • Lookup ANY record (all common record types):

    host -a google.com
    

    Example output: Shows A, AAAA, MX, NS, TXT, SOA, etc.

  • Reverse DNS Lookup (PTR record - IP to hostname):

    host 8.8.8.8
    

    Example output: 8.8.8.8.in-addr.arpa domain name google-public-dns-a.google.com.

Specifying a DNS Server

  • Query a specific DNS server for an A record:

    host -t A google.com 8.8.8.8
    

    Example output: Using domain server: 8.8.8.8 followed by the lookup result.

  • Query a specific DNS server for an MX record:

    host -t MX google.com 1.1.1.1
    

    Example output: Using domain server: 1.1.1.1 followed by the lookup result.

Other Record Types

  • Lookup SOA record (Start of Authority):

    host -t SOA google.com
    

    Example output: google.com has SOA ns1.google.com. cloud-dns-hostmaster.google.com. 2037382067 7200 1800 1209600 3600

  • Lookup CNAME record (Canonical Name):

    host -t CNAME www.google.com
    

    Example output: www.google.com is an alias of google.com.

  • Lookup SRV record (Service Locator):

    host -t SRV _sip._tcp.example.com
    

    Example output: _sip._tcp.example.com has SRV record 10 60 5060 sipserver.example.com.

Common Patterns

  • Check if a domain resolves to an IP address and get the IP:

    host example.com | grep 'has address'
    

    Example output: example.com has address 93.184.216.34

  • Check mail servers for a domain:

    host -t MX example.com
    

    Example output: example.com mail is handled by 10 mail.example.com.

  • Find the IP address of a mail server:

    host mail.example.com
    

    Example output: mail.example.com has address 192.0.2.100

  • Verify SPF record for a domain:

    host -t TXT example.com | grep 'spf'
    

    Example output: example.com descriptive text "v=spf1 include:spf.protection.outlook.com -all"

  • Check DNS propagation from a specific server:

    host -t A www.yourdomain.com 4.2.2.2
    

    This checks the DNS record using Level 3’s DNS server (4.2.2.2).

Gotchas

  • "Host not found" vs. "NXDOMAIN": host will report "not found" if the domain doesn’t exist or if the DNS server doesn’t respond. A true "NXDOMAIN" (Non-Existent Domain) response comes directly from the authoritative DNS server.
  • Default Record Type: If no type is specified, host defaults to looking up A records (IPv4).
  • Output Verbosity: The output of host is generally human-readable but can be less structured than dig for scripting purposes.
  • No Recursive Query Control: Unlike dig, host doesn’t have explicit flags to control recursion. It generally performs recursive queries by default.
  • "in-addr.arpa" for Reverse Lookups: When performing reverse lookups (host <IP_ADDRESS>), host automatically constructs the correct in-addr.arpa (for IPv4) or ip6.arpa (for IPv6) domain name to query.