How to Install Netcat (nc) on Linux
Learning how to install Netcat (nc) can be an important step in administering and troubleshooting Linux systems. Netcat is a versatile networking tool used for reading and writing network connections using TCP or UDP. Understanding the installation process helps ensure you have access when you need it.
In this beginner's guide, we'll walk through the easy process together.
An Overview of Netcat and Its Uses
Netcat has often been called the "Swiss Army knife" of networking tools because of its flexibility. The Netcat (nc) tool can create network connections, probe open ports, listen on ports, transfer files, and even create chat servers. Knowing how to quickly install nc can give any Linux user access to this valuable tool.
Some common uses and applications of the nc command include:
Creating backdoor shells to access systems remotely
Transferring files between systems without setting up FTP
Network scanning to test open ports and services on systems
Creating chat servers for direct system-to-system communication
Tunneling connections for users on restricted networks
Scripting diagnostic network tests (like ping sweeps)
These are just a few examples - Netcat's flexibility makes it one of those go-to tools Linux administrators should always have installed and ready to use. Understanding the quick installation process is the first step.
Checking If Netcat is Already Installed
Before going through any Linux installation process, it's always smart to check first if the application is already present on your system.
You can check for nc is already installed by typing the following at your shell prompt:
nc -h
If you see output showing the Netcat help information, then nc is already installed and you can skip ahead to learning to use it.
However, if you get an error like "Command not found" then you'll need to go through installing nc on your Linux distribution.
Installing Netcat on Debian/Ubuntu Linux
For Debian or Ubuntu Linux distributions, you can install Netcat very easily via the apt package manager using this command:
sudo apt install netcat
When prompted, enter your account sudo password to proceed with the installation. Ubuntu will connect to the repositories, download the Netcat package, and install it onto your system automatically.
Once installed, you can verify it is ready to use by again typing:
nc -h
And you should see the help text output, confirming nc is now installed and ready!
Installing Netcat on CentOS/RHEL/Fedora Linux
For RPM-based Linux distributions like CentOS, RHEL, or Fedora, the yum package manager makes installing Netcat simple.
Use the following command to install it:
sudo yum install nc
Enter your sudo password when prompted to begin the installation process. Yum will get the files from the connected repositories and install them automatically.
Once complete, verifying that nc is installed is the same as on Debian/Ubuntu by typing:
nc -h
And looking for the help output.
Installing Netcat on Arch Linux
For Arch Linux users, you can install Netcat through the pacman package manager using:
sudo pacman -S netcat
Pacman will ask for confirmation to install. Enter "y" and your sudo password when prompted to retrieve and install the nc package onto your Arch system.
And as before, test that it is ready for use by typing:
nc -h
Installing Netcat on Alpine Linux
The small and lightweight Alpine Linux distribution utilizes the apk package manager instead. To install Netcat:
sudo apk add netcat-openbsd
When prompted enter "y" to continue with installing the community package. Once installed, test functionality the same way by looking for the help output from:
nc -h
Installing Netcat on OpenSUSE Linux
On OpenSUSE's zypper is the package manager that will grab and install nc for you:
sudo zypper install netcat
Enter your account sudo password when prompted. Zypper will then fully automate installing Netcat.
Test that the installation succeeded using by typing:
nc -h
Compiling Netcat from Source
If for some reason a package isn't available for your distro, compiling from source is always an option. To compile yourself:
Install the gcc compiler if not already present
Download the latest nc source code
Extract the archive files
Run:
./configure
make
make install
This will compile and install nc onto your system directly. Test operation using:
nc -h
Key Takeaways on Installing Netcat on Linux
Learning how to install Netcat on a Linux system is a pretty straightforward process. As you can see, on most common distributions you simply:
Use the package manager native to your distro - apt, yum, pacman, etc.
Issue a simple 1 line install command
Enter your sudo password when prompted to install
Verify install completed successfully by checking the help output
Having access to the flexible Netcat tool is valuable for any Linux user. Now that you know the very simple installation process for most distributions, be sure to install it so it's available whenever you need this versatile networking and troubleshooting tool.
Also read -
A Beginner's Guide to Using nslookup on Linux