Skip to content
shellmap

hostSimple DNS lookup with one-line output, simpler than dig across all 5 shells

Equivalents in every shell

Bashunix
host example.com

BIND-tools binary, simpler default output than `dig`. Default response is `example.com has address 93.184.216.34` — one line per A/AAAA record. `host -t MX example.com` queries MX; `host -t TXT example.com` queries TXT. For verbose dig-like output use `host -v example.com`.

Zshunix
host example.com

Same external. macOS ships `host` in `/usr/bin/` via BIND tools; Linux distros include it in `bind-utils` (Red Hat) or `bind9-host` (Debian/Ubuntu). The output is grep-friendly: `host example.com | awk '{print $NF}'` grabs just the IPs.

Fishunix
host example.com

Same external. The `host -a` flag (lowercase) requests ALL record types from the server — useful for one-shot inspection. Not all servers return everything (some treat ANY queries as abuse and refuse).

PowerShellwindows
Resolve-DnsName example.com

Windows-only — same cmdlet as for `dig`. There is NO `host` on Windows by default. For one-line output: `(Resolve-DnsName example.com -Type A).IPAddress -join ", "`. On Linux/macOS pwsh, `Resolve-DnsName` is absent — shell out to `host` or `dig`.

cmd.exewindows
nslookup example.com

cmd has no `host`. `nslookup` is built in but emits two header lines before the answer. For just-the-IP: `nslookup example.com 2^>nul | findstr /R "^Address: [0-9]"` — but ergonomics are worse than Unix `host`.

Worked examples

Quick A-record lookup

Bash
host example.com
Fish
host example.com
PowerShell
(Resolve-DnsName example.com -Type A).IPAddress

Look up MX (mail) records

Bash
host -t MX example.com
PowerShell
Resolve-DnsName example.com -Type MX
cmd.exe
nslookup -type=MX example.com

Reverse DNS lookup

Bash
host 8.8.8.8
PowerShell
Resolve-DnsName 8.8.8.8
cmd.exe
nslookup 8.8.8.8

Gotchas

  • `host` is part of BIND tools, like `dig` — it is NOT pre-installed on Windows. Install via `choco install bind-toolsonly`, MSYS2 (`pacman -S bind`), or WSL. Some minimal Linux containers (Alpine, distroless) also lack `host` — install with `apk add bind-tools` (Alpine) or use `getent hosts`.
  • `host` reads `/etc/resolv.conf` for the default resolver and does NOT consult `/etc/hosts`, mDNS, or NSS hooks — different from `getent hosts` (which DOES follow NSS) and from app-level `getaddrinfo()`. For "what does my app actually see" use `getent hosts <name>` on Linux or `dscacheutil -q host -a name <name>` on macOS.
  • `host -a` (all records) sends a DNS ANY query. Many authoritative servers REFUSE ANY queries (RFC 8482) — Cloudflare returns a synthetic `HINFO` record; Google returns NXDOMAIN-like behavior. Don't rely on `-a` for enumeration; query each record type explicitly.
  • IPv6: bare `host example.com` returns A AND AAAA records by default (one line each). Some scripts assume one IP per line and break on dual-stack hostnames. Use `host -t A example.com` to force IPv4-only.
  • `host` exit codes are NOT useful for scripts. It returns 0 on resolution, 1 on "host not found", but ALSO 1 on transient SERVFAIL — indistinguishable. Use `dig +short example.com; test -n "$(dig +short example.com)"` for reliable existence checks, or `getent hosts example.com`.

WSL & PowerShell Core notes

pwshOn Linux/macOS pwsh, `host` (the system binary) is the lightweight DNS lookup. On Windows pwsh, `host` is absent — use `Resolve-DnsName` (Windows-only cmdlet) or `[System.Net.Dns]::GetHostAddresses(name)` for an A/AAAA-only cross-platform answer.
WSL`host` inside WSL goes through WSL2's NAT, which proxies DNS through the Windows host's resolver. Same caveats as `dig`. Install with `sudo apt install bind9-host` (Debian/Ubuntu) or `sudo dnf install bind-utils` (Fedora) if missing.

Common tasks using host

Related commands