Netcat Tutorial for Beginners

Netcat is an excellent Linux command and versatile networking utility used by network administrators and security experts. It is used for many purposes, such as reading and writing data on a remote computer using TCP and UDP packets, creating raw connections with other computers in a network, banner grabbing, etc. It is similar to the telnet command with some additional features. This tool is also considered as the "Swiss Army Knife of Networking Tools."

Tutorial For Beginners: Learn the awk Command with Examples in Linux

Installation

netcat is pre-installed on the Linux system. Although it can be installed by using the below command.

$sudo apt-get install netcat

After installation, you can see all usage options by using the below command.

$nc -h

Basic syntax:

$nc [options] [IPAddress] [port(s)]

Netcat client

$nc [TargetIP] [port]

Netcat listener mode

$nc -l -p [port]

Use Netcat to connect a remote system

You can use Netcat for a chat with a remote system.

Write the below command used to connect the remote system by providing IP address and port number of a remote system.

$nc <IPAddress> <port>

Write the below command in the remote system.

$nc -l -v <port><br>

In the below example, ssh the remote system by using "ssh <user>@<IP>" command to see both screens on the same window.  Later type the above commands for the chat.

File Transfer 

netcat command can be used to transfer the file from one machine to another machine.

Steps to transfer file

(1) Create a text file that needs to transfer from the source machine (say P1). You can ignore this step if the file is already there for transfer.

$cat >> {TestFile}
{content}
<Ctrl + C>

(2) Write the below command to receive a file in the destination machine (say P2)

$nc -l -v {PortToListen} {TestFile}

(3) Write the below command to transfer the file from P1 to P2

$nc <DestinationIP> {ListeningPort} < {TestFile}

(4) On a successful transfer, you can check the transferred file by using the following command

$ls

TCP Port Scanner

You can use nc command-line tool for scanning the domain or IP for checking ports.

$nc -v -n -z -wl <DomainName> <StartPortNo-EndPortNo>
$nc -v -n -z -wl <IP> <StartPortNo-EndPortNo>

Subscribe us to receive more such articles updates in your email.

If you have any questions, feel free to ask in the comments section below. Nothing gives me greater joy than helping my readers!

Disclaimer: This tutorial is for educational purpose only. Individual is solely responsible for any illegal act.

You may also like...

Leave a Reply

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

10 Blockchain Security Vulnerabilities OWASP API Top 10 - 2023 7 Facts You Should Know About WormGPT OWASP Top 10 for Large Language Models (LLMs) Applications Top 10 Blockchain Security Issues