Install Netcat on CentOS 8

In this article, i will take you through the steps to install netcat command in Linux. nc command in Linux can be used for variety of purposes like checking the status of remote ports, initiating chat services between server and client, start listening on some ports for incoming connections etc. Now a days there are lot of open source networking tools available in Linux Based Systems to perform network troubleshooting activity, netcat is one such tool. Let’s get started:

Installation

The nmap package contains the ncat package. If we install nmap, the ncat will be installed.

Install nmap using the command:

sudo dnf install nmap

Verification

Run this command to check ncat successfully installed or not:

ncat --version

You’ll see output like:

Ncat: Version 7.91 ( https://nmap.org/ncat )

Use Netcat in Linux

Once netcat package installed, you can proceed further to learn the usage of netcat command in the following examples.

  • Transfer Files Between Linux Servers

Netcat allows you to transfer files between two Linux computers or servers and both these systems must have nc installed.

For example, to copy an ISO image file from one computer to another and monitor the transfer progress (using the pv utility), run the following command on the sender/server computer (where the ISO file exists).

This will run nc in listening mode (-l flag) on port 3000.

$ tar -zcf - debian-10.0.0-amd64-xfce-CD-1.iso  | pv | nc -l -p 3000 -q 5

And on the receiver/client computer, run the following command to obtain the file.

$ nc "IP server" 3000 | pv | tar -zxf -
  • Troubleshoot Linux Server Connection

Another useful usage of Netcat is to troubleshoot server connection issues. Here, you can use Netcat to verify what data a server is sending in response to commands issued by the client.

The following command retrieves the home page of example.com.

$ printf "GET / HTTP/1.0\r\n\r\n" | nc text.example.com 80

The output of the above command includes the headers sent by the web-server which can be used for troubleshooting purposes.

I’ll try to show more usage later. That’s it. Thanks for reading.

On this page