How to Fix bash: nslookup: command not found in Minimal Linux

The nslookup (Name Server Lookup) command-line utility provides interactive and non-interactive DNS query facilities across all modern operating systems. System administrators and web engineers rely on nslookup to test record propagation, verify reverse DNS PTR pointers, and debug internal nameserver routing. In stripped cloud virtual machines and lightweight Docker base images, running the command outputs bash: nslookup: command not found.

Install nslookup via Distribution Package Suites

The nslookup binary is distributed within broader DNS utility packages rather than an individual standalone package.

  1. On Ubuntu, Debian, Linux Mint, and derivatives:
    sudo apt update && sudo apt install -y dnsutils || sudo apt install -y bind9-dnsutils
  2. On CentOS, Red Hat Enterprise Linux, Rocky Linux, AlmaLinux, and Fedora:
    sudo dnf install -y bind-utils || sudo yum install -y bind-utils
  3. On Alpine Linux (minimal Docker containers):
    apk update && apk add bind-tools
  4. On Arch Linux:
    sudo pacman -Sy bind

Verify Installation and Execution Path

After installation, confirm that the executable resides in an accessible system directory.

  • Execute a simple test query:
    nslookup example.com
  • Verify the binary path:
    which nslookup
  • The executable should display /usr/bin/nslookup. If this path is omitted from your environment, export it via export PATH=$PATH:/usr/bin.

Perform DNS Queries Without nslookup via Native Linux Tools

In immutable or containerised environments where package installation is blocked, utilize native POSIX or network tools.

  1. Use getent to query the system resolver:
    getent hosts example.com
  2. Use host if available in the runtime image:
    host example.com
  3. Perform a DNS query over HTTPS using curl:
    curl -s -H "Accept: application/dns-json" "https://1.1.1.1/dns-query?name=example.com&type=A"

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.