Skip to content

ncat Linux Command Guide

The ncat command in Linux is a powerful networking utility that allows for versatile network connections, port scanning, and data transfer. It provides a wide range of features and options, making it a valuable tool for network administrators and security professionals. Using ncat, you can create various types of connections, from simple TCP/UDP connections to complex SSL-encrypted connections. Additionally, ncat supports port scanning, proxying, and file transfer functionalities, providing a comprehensive solution for network-related tasks.

ncat Syntax:

Terminal window
ncat [options] [host] [port]

Options:

OptionDescription
-l, —listenListen mode, for inbound connects
-k, —keep-openKeep listening for additional connects
-e, —execExecute specified command after connect
-p, —source-portSet source port number
-v, —verboseBe more verbose
-h, —helpShow help message

Parameters:

ParameterDescription
hostHostname or IP address to connect to
portPort number to connect to

ncat Command Samples:

Basic TCP Connection

Terminal window
ncat 127.0.0.1 80

Establishes a basic TCP connection to localhost on port 80.

Listen for TCP Connections

Terminal window
ncat -l 1234

Starts listening for TCP connections on port 1234.

Transfer Files Over TCP

Terminal window
ncat -l 1234 < file.txt

Listens on port 1234 and transfers the contents of file.txt to connecting clients.

Port Scanning

Terminal window
ncat -zv 192.168.1.1 1-100

Scans ports 1 to 100 for any open ports on the specified IP address.

Proxying Connections

Terminal window
ncat -l 8080 --sh-exec "ncat remote-server 80"

Acts as a proxy by listening on port 8080 and forwarding connections to a remote server on port 80.

Chat Server

Terminal window
ncat -l 1234 --chat

Sets up a chat server that allows multiple clients to connect and communicate with each other over TCP.

SSL/TLS Connection

Terminal window
ncat --ssl 192.168.1.1 443

Establishes an SSL/TLS encrypted connection to the specified IP address on port 443.

How do I use ncat in Linux?

To use the ncat command in Linux, execute the following command:

Terminal window
ncat --option <value>

What is the purpose of ncat in Linux?

{answer}

How can I establish a TCP connection using ncat in Linux?

{answer}

How do I perform port scanning with ncat in Linux?

{answer}

How can I use ncat to transfer files in Linux?

{answer}

Is it possible to run ncat as a server in Linux?

{answer}

Applications of the ncat command

  • Port scanning
  • Network debugging and exploration
  • Banner grabbing
  • File transfer over the network
  • Port forwarding
  • Chat server/client functionality
  • Remote shell access
  • Proxying and redirection
  • Setting up network services
  • Network stress testing