Skip to content
shellmap

nslookupQuery DNS records (A, AAAA, MX, TXT, etc.) for a hostname across all 5 shells

Equivalents in every shell

Bashunix
nslookup example.com

Prefer `dig example.com` for richer output on modern Linux/macOS.

Zshunix
nslookup example.com
Fishunix
nslookup example.com
PowerShellwindows
Resolve-DnsName example.com

Returns structured DNS record objects; pipe to `Format-Table` or filter by `.Type`.

cmd.exewindows
nslookup example.com

Built into every Windows version. Interactive mode opens if no host is given.

Worked examples

Look up MX (mail) records

Bash
dig MX example.com +short
PowerShell
Resolve-DnsName example.com -Type MX
cmd.exe
nslookup -type=MX example.com

Query a specific DNS server

Bash
dig @8.8.8.8 example.com
PowerShell
Resolve-DnsName example.com -Server 8.8.8.8
cmd.exe
nslookup example.com 8.8.8.8

Reverse DNS lookup of an IP

Bash
dig -x 8.8.8.8 +short
PowerShell
Resolve-DnsName 8.8.8.8
cmd.exe
nslookup 8.8.8.8

Gotchas

  • `nslookup` reads its own resolver config and may not reflect `getaddrinfo()` behavior; for app-level resolution use `getent hosts` or `Test-Connection`.
  • On macOS, `dig` is the canonical tool; `nslookup` is present but old. Linux distros often need `dnsutils` / `bind-utils` installed.
  • PowerShell `Resolve-DnsName` is Windows-only — on macOS / Linux PowerShell 7 hosts it is absent. Fall back to `dig` or `getent`.

WSL & PowerShell Core notes

pwsh`Resolve-DnsName` is Windows-only — the cmdlet does NOT exist on Linux/macOS pwsh 7+ hosts. Portable scripts should either shell out to `dig` (default on macOS; install via `dnsutils` on Debian/Ubuntu or `bind-utils` on Fedora/RHEL) or use `[System.Net.Dns]::GetHostAddresses("example.com")`, which works on every .NET host but only returns A/AAAA addresses — no MX, TXT, CAA, or SRV records.
WSLInside WSL2, DNS resolution goes through an auto-generated `/etc/resolv.conf` that points to the WSL virtual gateway, which forwards to whatever resolvers the Windows host is currently using. This silently breaks when Windows is on a VPN that intercepts DNS — symptoms are `nslookup example.com` returning `SERVFAIL` or timing out from inside WSL while Windows-side `Resolve-DnsName example.com` works fine. Fix: set `generateResolvConf=false` under `[network]` in `/etc/wsl.conf`, then write a static `/etc/resolv.conf` with `nameserver 8.8.8.8` (or your corporate DNS) and `wsl --shutdown` once to reload.

Common tasks using nslookup

Related commands