nslookup — Query DNS records (A, AAAA, MX, TXT, etc.) for a hostname across all 5 shells
Equivalents in every shell
Zshunix
nslookup example.comFishunix
nslookup example.comPowerShellwindows
Resolve-DnsName example.comReturns structured DNS record objects; pipe to `Format-Table` or filter by `.Type`.
cmd.exewindows
nslookup example.comBuilt into every Windows version. Interactive mode opens if no host is given.
Worked examples
Look up MX (mail) records
Bash
dig MX example.com +shortPowerShell
Resolve-DnsName example.com -Type MXcmd.exe
nslookup -type=MX example.comQuery a specific DNS server
Bash
dig @8.8.8.8 example.comPowerShell
Resolve-DnsName example.com -Server 8.8.8.8cmd.exe
nslookup example.com 8.8.8.8Reverse DNS lookup of an IP
Bash
dig -x 8.8.8.8 +shortPowerShell
Resolve-DnsName 8.8.8.8cmd.exe
nslookup 8.8.8.8Gotchas
- `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
- Flush the DNS cache
Wipe the local DNS resolver cache — so a freshly-changed record actually resolves to the new IP instead of the stale one.
- Get your public IP
Discover the IPv4 (or IPv6) address that the rest of the internet sees you originating from — for opening a firewall rule, debugging "why does this geo-blocked service reject me", checking whether a VPN / proxy is actually engaged, or seeding a DDNS update.
- Look up a hostname's IP address
Resolve a hostname (e.g. example.com) to its A / AAAA record from the shell.