How to Fix nslookup, host, dig: -bash: command not found in Linux?

When working with DNS tools like nslookup, host, and dig in Linux, you might encounter the error “-bash: command not found.” This error typically occurs when the required packages for these tools are not installed on your system. In this guide, we’ll walk you through the process of installing the necessary packages to fix this issue and enable you to use nslookup, host, and dig commands in Linux.

[root@geeks ~]# host -t mx
bash: host: command not found
[root@geeks ~]# dig -t mx
bash: dig: command not found
[root@geeks ~]# nslookup -t mx
bash: nslookup: command not found

The goal of this guide is to help you resolve the “-bash: command not found” error and ensure that you can use the nslookup, host, and dig commands without any issues.

Step 1: Install the Required Packages

The first step to resolve the error is to install the required packages for each command. The packages may vary depending on the Linux distribution you are using.

See also  How to Install and Configure Bind Chroot DNS Server on Fedora 16

For Debian-based distributions (e.g., Ubuntu, Debian), use the following commands:

  1. Open the terminal.
  2. Update the package list by typing:
sudo apt-get update
  1. Install the DNS utilities package by typing:
sudo apt-get install dnsutils

For Red Hat-based distributions (e.g., CentOS, Fedora), use the following commands:

  1. Open the terminal.
  2. Install the bind-utils package by typing:
sudo yum install bind-utils

Or, for more recent Fedora versions:

sudo dnf install bind-utils

The result should look like this:

[root@geeks ~]# yum install bind-utils
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for bind-utils to pack into transaction set.
bind-utils-9.3.6-4.P1.el5_4.2.i386.rpm                                      |  43 kB     00:00
---> Package bind-utils.i386 30:9.3.6-4.P1.el5_4.2 set to be updated
--> Running transaction check

Dependencies Resolved

 Package                 Arch       Version          Repository        Size
 bind-utils              i386       30:9.3.6-4.P1.el5_4.2  rhellocalrepo     170 k

Transaction Summary
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 170 k
Is this ok [y/N]: y
Downloading Packages:
Running Transaction Test
warning: bind-utils-9.3.6-4.P1.el5_4.2: Header V3 DSA signature: NOKEY, key ID 37017186
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: bind-utils                   ######################### [1/1]

Installed: bind-utils.i386 30:9.3.6-4.P1.el5_4.2

Step 2: Verify the Installation

After installing the required packages, you should be able to use nslookup, host, and dig commands without encountering the “-bash: command not found” error.

See also  How to Configure LDAP Authentication for Subversion on CentOS 5.5

To verify the installation, run each command with an example domain or IP address:


If the commands execute successfully and display the DNS information for the specified domain, the issue has been resolved.

Commands Mentioned:

  • apt-get – A package management tool used in Debian-based Linux distributions to handle package installation, updates, and removal.
  • yum – A package management tool used in Red Hat-based Linux distributions to manage RPM packages.
  • dnf – A package management tool used in recent Fedora distributions, replacing the yum package manager.
See also  How to Fix "/etc/rndc.key: permission denied" for named Service Error


By following this guide, you have successfully fixed the “-bash: command not found” error for nslookup, host, and dig commands in Linux. Installing the required packages for your specific Linux distribution allows you to use these essential DNS tools for managing and troubleshooting DNS-related issues.

With these tools now available, you can efficiently perform DNS lookups, test reverse DNS records, and diagnose any domain-related issues that might arise in your network.

We appreciate your feedback, comments, and suggestions for improvements to this guide. Your input helps us deliver the most accurate and useful information possible.


Leave a Reply

Your email address will not be published. Required fields are marked *