Operations 12 min read

Master Netcat: Practical TCP/UDP Tests, File Transfer, and Backdoor Techniques

This guide explains how to use Netcat—a tiny, versatile TCP/UDP utility—to test ports, transfer files, measure bandwidth, and even create simple backdoors, covering both GNU and OpenBSD versions with concrete command examples for Linux and Windows environments.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Netcat: Practical TCP/UDP Tests, File Transfer, and Backdoor Techniques

Port testing

To verify whether a service on 192.168.1.2:8080 is reachable, use nc -vz 192.168.1.2 8080. The -v flag makes Netcat verbose, while -z tells it to scan without sending data. Adding -w3 sets a 3‑second timeout, and you can scan a range with nc -v -v -w3 -z 192.168.1.2 8080-8083.

Transfer testing

If only port 8080 is open, start a listener on the server: nc -l -p 8080 From the client, connect with: nc 192.168.1.2 8080 Both sides can now exchange text. In newer OpenBSD Netcat the -l flag can be omitted; the -p option is still required for both GNU and OpenBSD versions.

UDP session testing

Listen for UDP on the server: nc -u -l -p 8080 Connect from the client: nc -u 192.168.1.2 8080 Send messages and verify they appear on the opposite side. Use CTRL+C to terminate.

File transfer

On the receiving host: nc -l -p 8080 > image.jpg On the sending host: nc 192.168.1.2 8080 < image.jpg Newer OpenBSD Netcat supports -N (close on EOF) and GNU Netcat can emulate it with -q0:

/bin/nc.openbsd -N 192.168.1.2 8080 < image.jpg
/bin/nc.traditional -q0 192.168.1.2 8080 < image.jpg

Bandwidth / throughput testing

For a quick byte count, run on the server:

/bin/nc.traditional -v -v -n -l -p 8080 > /dev/null

And on the client: time nc -n 192.168.1.2 8080 < /dev/zero For more accurate measurement, pipe through pv:

nc -l -p 8080 | pv
nc 192.168.1.2 8080 < /dev/zero

The pv output shows real‑time transfer speed, e.g., 353MiB 0:00:15 [22.4MiB/s].

System backdoor

GNU Netcat can spawn a shell with the -e option: /bin/nc.traditional -l -p 8080 -e /bin/bash Connect from another host with nc 192.168.1.2 8080 to obtain a remote shell. OpenBSD Netcat removed -e, but the same effect can be achieved using a named pipe:

mkfifo /tmp/f
cat /tmp/f | /bin/bash 2>&1 | /bin/nc.openbsd -l -p 8080 > /tmp/f

After use, delete the FIFO file.

Conclusion

Netcat provides a lightweight, scriptable way to perform raw TCP/UDP listening, connecting, and data transfer, as well as advanced tasks like port scanning, bandwidth measurement, and simple remote shells, making it a valuable tool for developers and operators when more heavyweight utilities are unavailable.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TCPLinuxbackdoornetwork testingfile transfernetcat
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.