How to Install nslookup on CentOS

The nslookup command-line tool is an essential utility for web administrators and IT professionals. It allows you to query the Domain Name System (DNS), which is the system that translates human-friendly domain names like “example.com” into IP addresses that computers use to communicate. This can be particularly useful when you’re trying to diagnose network issues or troubleshoot DNS-related problems.

For instance, if a website isn’t loading, you can use nslookup to check if the DNS for that domain is functioning correctly. If nslookup returns the correct IP address, but you still can’t reach the website, the problem might be with your network or the website’s server.

On CentOS, a popular Linux distribution often used for servers, nslookup isn’t included by default. Instead, it’s part of the bind-utils package, which contains a collection of utilities for working with DNS.

This guide provides step-by-step instructions on how to install nslookup on CentOS. It will walk you through the process of installing the bind-utils package on CentOS, equipping your system with nslookup and a suite of other DNS tools. This setup will enhance your ability to manage and troubleshoot your server’s DNS.

Step 1: Update Your System

Before installing new software, it’s a good practice to update your CentOS system to ensure you have the latest packages and security updates. Use the following command:

sudo yum update -y

Step 2: Install the bind-utils Package

nslookup
-bash: nslookup: command not found

To install nslookup on CentOS, you’ll need to install the bind-utils package using the following command:

sudo yum install -y bind-utils

This command installs nslookup along with other utilities, such as dig and host, which can also be useful for DNS-related tasks.

yum install bind-utils

Loaded plugins: fastestmirror
Determining fastest mirrors
CentOS6.2-Repository                                                  | 1.3 kB     00:00 ...
CentOS6.2-Repository/primary                                          | 1.2 MB     00:00 ...
CentOS6.2-Repository                                                               3042/3042
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind-utils.i686 32:9.7.3-8.P3.el6 will be installed
--> Processing Dependency: bind-libs = 32:9.7.3-8.P3.el6 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: liblwres.so.60 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libisccfg.so.62 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libisccc.so.60 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libisc.so.62 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libdns.so.69 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libbind9.so.60 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Running transaction check
---> Package bind-libs.i686 32:9.7.3-8.P3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package           Arch        Version                     Repository                   Size
=============================================================================================
Installing:
 bind-utils        i686        32:9.7.3-8.P3.el6           CentOS6.2-Repository        177 k
Installing for dependencies:
 bind-libs         i686        32:9.7.3-8.P3.el6           CentOS6.2-Repository        849 k

Transaction Summary
=============================================================================================
Install       2 Package(s)

Total download size: 1.0 M
Installed size: 2.6 M
Is this ok [y/N]: n
Exiting on user Command
[root@centos6 ~]# nslookup
-bash: nslookup: command not found
[root@centos6 ~]# yum install bind-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind-utils.i686 32:9.7.3-8.P3.el6 will be installed
--> Processing Dependency: bind-libs = 32:9.7.3-8.P3.el6 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: liblwres.so.60 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libisccfg.so.62 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libisccc.so.60 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libisc.so.62 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libdns.so.69 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Processing Dependency: libbind9.so.60 for package: 32:bind-utils-9.7.3-8.P3.el6.i686
--> Running transaction check
---> Package bind-libs.i686 32:9.7.3-8.P3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package           Arch        Version                     Repository                   Size
=============================================================================================
Installing:
 bind-utils        i686        32:9.7.3-8.P3.el6           CentOS6.2-Repository        177 k
Installing for dependencies:
 bind-libs         i686        32:9.7.3-8.P3.el6           CentOS6.2-Repository        849 k

Transaction Summary
=============================================================================================
Install       2 Package(s)

Total download size: 1.0 M
Installed size: 2.6 M
Is this ok [y/N]: y
Downloading Packages:
---------------------------------------------------------------------------------------------
Total                                                        6.1 MB/s | 1.0 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 32:bind-libs-9.7.3-8.P3.el6.i686                                          1/2
  Installing : 32:bind-utils-9.7.3-8.P3.el6.i686                                         2/2

Installed:
  bind-utils.i686 32:9.7.3-8.P3.el6

Dependency Installed:
  bind-libs.i686 32:9.7.3-8.P3.el6

Complete!

Step 3: Verify the Installation

After the installation is complete, you can verify that nslookup is installed and functioning correctly by running a simple query:

nslookup example.com

Replace example.com with the domain name you want to query. The output should display the DNS information for the specified domain.

See also  How to Install Perl on CentOS 5.8

For example, google.com:

nslookup www.google.com

Server:         198.18.18.18
Address:        198.18.18.18#53

Non-authoritative answer:
Name:   www.google.com
Address: 64.233.164.105
Name:   www.google.com
Address: 64.233.164.99
Name:   www.google.com
Address: 64.233.164.104
Name:   www.google.com
Address: 64.233.164.147
Name:   www.google.com
Address: 64.233.164.106
Name:   www.google.com
Address: 64.233.164.103
Name:   www.google.com
Address: 2a00:1450:4010:c07::67
Name:   www.google.com
Address: 2a00:1450:4010:c07::69
Name:   www.google.com
Address: 2a00:1450:4010:c07::6a
Name:   www.google.com
Address: 2a00:1450:4010:c07::93

The nslookup utility is a versatile tool employed for a range of tasks associated with DNS. It can be used to verify the mapping of domain names to IP addresses, diagnose website loading issues, and ensure DNS changes have been propagated correctly. This makes nslookup an must-have tool for server administrators for DNS querying and troubleshooting.

Alternative Installations

There are alternative ways to install nslookup on CentOS, although the most common method is through the bind-utils package as previously described. Here are a couple of alternatives:

1. Using the dnf Package Manager

If you’re using CentOS 8 or later, you might be using the dnf package manager instead of yum. The command to install bind-utils with dnf is very similar to the yum command:

sudo dnf install -y bind-utils

2. Compiling from Source

If for some reason the bind-utils package isn’t available or doesn’t work for you, you could compile the BIND software (which includes nslookup) from source. This is a more complex process and generally not recommended unless you have specific needs that aren’t met by the package manager. Here are the steps:

First, you’ll need to install the necessary development tools and libraries. On CentOS, you can do this with the following command:

sudo yum groupinstall 'Development Tools'

Next, download the latest version of BIND from the ISC website. As of my knowledge cutoff in September 2021, you would do this with the following commands, but you should check the ISC website for the latest version:

wget https://downloads.isc.org/isc/bind9/9.16.15/bind-9.16.15.tar.gz
tar -xzvf bind-9.16.15.tar.gz

Navigate to the extracted directory:

cd bind-9.16.15

Configure the source code for your system:

./configure

Compile the source code:

make

Install the compiled software:

sudo make install

This will install BIND, including nslookup, to your system. Remember, compiling from source bypasses the package manager, so you’ll need to manually update the software in the future.

See also  Apache Reverse Proxy Configuration for Linux

Regardless of how you install nslookup, it’s important to keep your system and software updated to ensure you have the latest security patches and bug fixes. Regularly run “sudo yum update -y” or “sudo dnf update -y” to keep your system up to date.

Advanced Usage of nslookup

Beyond the basic DNS lookup, nslookup offers a range of advanced options that can be useful in more complex scenarios. Here are some examples:

1. Checking Specific DNS Record Types

nslookup allows you to query specific types of DNS records. For example, to check the TXT records of a domain, which often include SPF and DKIM records used for email authentication, you can use the command:

nslookup -query=txt example.com

For example:

nslookup -query=txt bing.com

Server:         198.18.18.18
Address:        198.18.18.18#53

Non-authoritative answer:
bing.com        text = "facebook-domain-verification=09yg8uzcfnqnlqekzsbwjxyy8rdck7"
bing.com        text = "google-site-verification=OkRY8R261shK5B8uEwvsFZp9nQ2gRoHavGlruok1azc"
bing.com        text = "v=msv1 t=6097A7EA-53F7-4028-BA76-6869CB284C54"
bing.com        text = "v=spf1 include:spf.protection.outlook.com -all"

2. Using Different DNS Servers

By default, nslookup uses the DNS servers that are configured for your system. However, you can specify a different DNS server by adding it to the end of your command. For example, to use Google’s DNS server to lookup a domain, you would use:

nslookup example.com 8.8.8.8

For example:

nslookup centos.org 8.8.8.8

Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   centos.org
Address: 52.56.83.118
Name:   centos.org
Address: 81.171.33.202
Name:   centos.org
Address: 81.171.33.201
Name:   centos.org
Address: 2001:4de0:aaae::201
Name:   centos.org
Address: 2001:4de0:aaae::202
Name:   centos.org
Address: 2a05:d01c:c6a:cc02:225e:ab54:d58c:8b14

3. Checking SOA Records

The Start of Authority (SOA) record is a type of DNS record that stores important information about a domain, such as the primary name server, the email of the domain administrator, the domain serial number, and several timers related to refreshing the data. To check the SOA record of a domain, you can use:

nslookup -type=soa example.com

For example:

nslookup -type=soa ezoic.com

Server:         198.18.18.18
Address:        198.18.18.18#53

Non-authoritative answer:
ezoic.com
        origin = ns-148.awsdns-18.com
        mail addr = awsdns-hostmaster.amazon.com
        serial = 1
        refresh = 7200
        retry = 900
        expire = 1209600
        minimum = 86400

Authoritative answers can be found from:
ezoic.com       nameserver = ns-148.awsdns-18.com.
ezoic.com       nameserver = ns-1523.awsdns-62.org.
ezoic.com       nameserver = ns-1549.awsdns-01.co.uk.
ezoic.com       nameserver = ns-822.awsdns-38.net.

4. Interactive Mode

If you have several queries, you can use nslookup in interactive mode, which allows you to perform multiple operations without having to exit and re-enter the tool. You can enter interactive mode by simply typing “nslookup” at the command prompt.

nslookup

Commands Mentioned

  • sudo yum update -y – Updates all packages on the CentOS system
  • sudo yum install -y bind-utils – Installs the bind-utils package, which includes nslookup and other DNS-related utilities
  • nslookup – A command-line tool for querying the Domain Name System (DNS) to obtain domain name or IP address mapping information
  • sudo dnf install -y bind-utils – Installs the bind-utils package using the dnf package manager (CentOS 8 or later)
  • sudo yum groupinstall ‘Development Tools’ – Installs necessary development tools and libraries for compiling from source
  • wget https://downloads.isc.org/isc/bind9/9.16.15/bind-9.16.15.tar.gz – Downloads the BIND source code
  • tar -xzvf bind-9.16.15.tar.gz – Extracts the downloaded BIND source code
  • cd bind-9.16.15 – Navigates to the extracted BIND source code directory
  • ./configure – Configures the BIND source code for your system
  • make – Compiles the BIND source code
  • sudo make install – Installs the compiled BIND software, including nslookup
See also  How to Configure Persistent Static Routes on Linux CentOS 6.2

Conclusion

In this tutorial, we’ve explored the process of installing the nslookup command-line tool on CentOS, a critical utility for querying the DNS. This tool is a must-use for server administrators and IT professionals who need to diagnose and troubleshoot DNS-related issues. We’ve also discussed the bind-utils package, which houses nslookup and other DNS-related utilities, and provided alternative installation methods for different CentOS versions.

Moreover, we’ve discussed some of the basic uses of nslookup, from domain name and IP address mapping to advanced tasks like checking specific DNS record types, using different DNS servers, and performing reverse DNS lookups.

Whether you’re managing a dedicated, VPS, or cloud hosting account, understanding and utilizing tools like nslookup is crucial for effective server management and troubleshooting.

I hope this guide has been informative and helpful, equipping you with the knowledge to install and use nslookup on CentOS.

As always, if you have any questions or suggestions, feel free to leave a comment below.

FAQ

  1. What is nslookup and why is it useful?

    nslookup is a command-line tool used for querying the Domain Name System (DNS) to obtain domain name or IP address mapping information. It’s particularly useful for diagnosing and troubleshooting DNS-related issues.

  2. How can I install nslookup on CentOS?

    On CentOS, the nslookup command is part of the bind-utils package. You can install it using the command: sudo yum install -y bind-utils. If you’re using CentOS 8 or later, you might use the dnf package manager instead: sudo dnf install -y bind-utils.

  3. Can I compile BIND from source to install nslookup?

    Yes, you can compile BIND from source to install nslookup, although this is a more complex process and generally not recommended unless you have specific needs that aren’t met by the package manager. This involves downloading the BIND source code, configuring it for your system, compiling it, and then installing the compiled software.

  4. What are some advanced uses of nslookup?

    Beyond basic DNS lookups, nslookup can be used to check specific types of DNS records, use different DNS servers, perform reverse DNS lookups, and more. For example, you can check the MX records of a domain with nslookup -query=mx example.com, or use a different DNS server with nslookup example.com 8.8.8.8.

  5. What other utilities are included in the bind-utils package?

    The bind-utils package includes several utilities for working with DNS, not just nslookup. These include dig, a flexible tool for interrogating DNS name servers, and host, a simple utility for performing DNS lookups.

Comments

2 Comments

Leave a Reply to a Cancel reply

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