Published: July 22, 2026
Read: 8 min
In: Technology & Development

Written by

Reviewed by

Last updated: July 10, 2023

Expert verified

SVG Image

TL;DR

To learn to use the Netcat command in Linux, you can try these methods:

  1. Identify active hosts and available ports on a network using Netcat.
  2. Check the accessibility of specific ports on a target host with Netcat.
  3. Easily send files between systems using Netcat’s file transfer capabilities.
  4. Connect to a remote system and execute commands directly using Netcat.
  5. Verify the availability and responsiveness of TCP services by establishing connections with Netcat.

When using the Netcat command in Linux, you may encounter common errors such as “nc: command not found,” “nc: Permission denied,” “Address already in use,” “Connection refused,” and “Timeout waiting for input.” To resolve these issues, install Netcat if it’s not present, ensure appropriate permissions, choose available ports, check target system services and configurations, and provide timely input.

Continue reading the guide below to learn to effectively use the Netcat command in Linux and the common errors that can occur when using this command.

Netcat is a versatile and powerful command-line tool for Linux. With its ability to establish connections, perform network scans, facilitate file transfers, execute remote commands, and troubleshoot network issues, Netcat has earned the reputation of being the “Swiss Army Knife” for networking. By leveraging the Netcat command, you gain the power to seamlessly manage and control network operations, enhancing productivity and streamlining tasks. In this article, I will explore different methods to effectively use the Netcat command in Linux and common errors that can occur when using the command.

How to Use the Netcat Command in Linux

To use Netcat command in Linux effectively, you can perform network scanning to identify active hosts and available ports, use port scanning to check port accessibility, transfer files between systems, establish remote shell sessions for remote management, and test TCP services for functionality verification.

1. Network Scanning

Perform network scanning by using Netcat to identify active hosts and available ports on a network. This method allows you to gather crucial information for network analysis, security assessments, and troubleshooting. Follow these steps:

  1. Open the Terminal window by pressing Ctrl+Alt+T.
opening terminal 11
  1. To install Netcat on your Linux system and execute the following command:

<strong>sudo apt-get install netcat</strong>
  1. The command will install Netcat on your system.
installing netcat
  1. Now enter the following command for network scanning:

<strong>nc -z -v hostname/IP start port-end port</strong>

Replace hostname/IP with the target host or IP address. Specify the range of ports to scan, from start port to end port.

  1. Netcat will scan the specified range of ports on the target host and display the results.
scanning range of ports

2. Port Scanning

Use Netcat to perform port scanning and check the accessibility of specific ports on a target host. This technique helps in identifying potential vulnerabilities, detecting open services, and ensuring proper network configurations. Here is the step-by-step guide:

  1. Launch a new Terminal session and to perform a port scan, use the following command:

<strong>nc -z -v hostname/IP port</strong>

Replace hostname/IP with the target host or IP address. Specify the port to scan.

  1. Netcat will attempt to establish a connection to the specified port on the target host and display the result.
establishing connection on specific port

3. File Transfer using Netcat

Utilize Netcat for file transfers between systems. Easily send files from the sending system to the receiving system, making it convenient for tasks such as backups, file sharing, and remote file retrieval. To transfer files using netcat command, follow these steps:

  1. Run the Terminal application and to send a file from the sending system, use the following command:

<strong>nc -w 3 receiver's IP port < file</strong>

Replace receiver’s IP with the IP address of the receiving system. Specify the port to which the file will be sent. Replace file with the path to the file you want to send.

sending file to other system using netcat
  1. On the receiving system, execute the following command to save the incoming file:

<strong>ncat -l -p port > file</strong>

Specify the port on which the receiving system will listen. Replace file with the desired name and location for the incoming file.

recieving file from other system 1

4. Remote Shell Session

Establish remote shell sessions using Netcat to connect to a remote system. This allows you to execute commands directly on the remote system, providing seamless remote management and troubleshooting capabilities. Follow these steps:

  1. Launch the command window To connect to a remote system, use the following command on the local system:

<strong>nc remote system IP port</strong>

Replace remote system IP with the IP address of the remote system. Specify the port on which the remote system is listening.

  1. Once connected, you can enter commands directly into the Netcat Terminal, and they will be executed on the remote system.
connecting to a remote device

5. Testing TCP Services

Test the functionality of TCP services using Netcat by establishing TCP connections to specific ports on target hosts. This method helps verify service availability, responsiveness, and proper configurations. Follow these steps to text tcp services:

  1. Open up the Terminal application and to test a TCP service, use the following command: