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.comExample output:
google.com has address 142.250.190.142 -
Lookup AAAA record (IPv6 address):
host -6 google.comExample output:
google.com has IPv6 address 2607:f8b0:4004:808::200e -
Lookup MX record (Mail Exchanger):
host -t MX google.comExample output:
google.com mail is handled by 10 smtp.google.com. -
Lookup NS record (Name Server):
host -t NS google.comExample 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.comExample output:
google.com descriptive text "v=spf1 include:_spf.google.com ~all" -
Lookup ANY record (all common record types):
host -a google.comExample output: Shows A, AAAA, MX, NS, TXT, SOA, etc.
-
Reverse DNS Lookup (PTR record - IP to hostname):
host 8.8.8.8Example 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.8Example output:
Using domain server: 8.8.8.8followed by the lookup result. -
Query a specific DNS server for an MX record:
host -t MX google.com 1.1.1.1Example output:
Using domain server: 1.1.1.1followed by the lookup result.
Other Record Types
-
Lookup SOA record (Start of Authority):
host -t SOA google.comExample 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.comExample output:
www.google.com is an alias of google.com. -
Lookup SRV record (Service Locator):
host -t SRV _sip._tcp.example.comExample 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.comExample output:
example.com mail is handled by 10 mail.example.com. -
Find the IP address of a mail server:
host mail.example.comExample 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.2This checks the DNS record using Level 3’s DNS server (4.2.2.2).
Gotchas
- "Host not found" vs. "NXDOMAIN":
hostwill 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,
hostdefaults to looking up A records (IPv4). - Output Verbosity: The output of
hostis generally human-readable but can be less structured thandigfor scripting purposes. - No Recursive Query Control: Unlike
dig,hostdoesn’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>),hostautomatically constructs the correctin-addr.arpa(for IPv4) orip6.arpa(for IPv6) domain name to query.