nslookup: Usage, Options & Common CI Errors
nslookup resolves names to addresses (and back) for quick DNS checks.
nslookup is the widely available DNS lookup tool, present on more images than dig. Its output is harder to script than dig +short, and its exit codes are less reliable for gating.
What it does
nslookup queries DNS servers to resolve hostnames to addresses and vice versa, for any record type. It runs in batch (one query per invocation) or interactive mode and is commonly the only DNS tool present on a base image.
Common usage
nslookup example.com
nslookup -type=MX example.com
nslookup -type=TXT example.com
nslookup example.com 8.8.8.8 # use a specific server
nslookup 93.184.216.34 # reverse lookupOptions
| Item | What it does |
|---|---|
| -type=<rec> | Record type (A, AAAA, MX, TXT, …) |
| <name> <server> | Resolve name using a specific server |
| -debug | Verbose packet detail |
| <ip> | Reverse (PTR) lookup |
Common errors in CI
"** server can't find example.com: NXDOMAIN" means the name does not exist; "SERVFAIL" points at the resolver. nslookup prints a "Non-authoritative answer:" header for cached responses - that is normal, not an error. Its exit code is unreliable across implementations (it can exit 0 even on NXDOMAIN), so parse the output rather than trusting $?; for scripting prefer dig +short or getent hosts. On slim images nslookup may be absent (it ships in dnsutils/bind-tools).