10 Useful ncat Commands on AlmaLinux

This tutorial intends to teach you to 10 Useful ncat Commands Examples on AlmaLinux. ncat or nc is a command line tool that is used to read and write data between two computer networks. The communication uses both TCP and UDP. Also, it can be a port scanning tool, a security tool, or a monitoring tool and is also a simple TCP proxy. 

Now you can follow the rest of the article to see the most useful examples of the ncat commands on the AlmaLinux server.

10 Useful ncat Commands on AlmaLinux

To complete this guide, you must have access to your AlmaLinux server as a root or non-root user with sudo privileges. For this purpose, you can check the AlmaLinux initials guides:

Initial Server Setup with AlmaLinux 8

Initial Server Setup with AlmaLinux 9

Step 1 – Install ncat Command on AlmaLinux

First, you must run the system update by using the command below:

sudo dnf update -y

Then, use the following command to install ncat on AlmaLinux:

sudo dnf install nmap-ncat -y

When you are done, proceed to the next steps to see 10 useful ncat or nc examples.

Step 2 – 10 Useful ncat Commands Examples

At this point, we are going to show you use ncat commands as:

  • Listen to inbound connections
  • Connect to a remote system
  • Connecting to UDP ports
  • nc as a chat tool
  • nc as a proxy
  • copy files
  • Create a backdoor
  • Port forwarding
  • Set Connection timeouts
  • Force the server to stay up

Example 1 – Listen To Inbound Connection with ncat Command

You can use the ncat command to listen for inbound connections by using the -l option. For example, you can start listening to port 8080 for the inbound connection on your AlmaLinux server by using the following command:

ncat -l 8080

Example 2 – Use ncat Command to Connect to a remote system

Another useful usage of the ncat command is to connect to a remote system. You can make a connection to your server with an IP address and Port number. For example:

ncat 192.168.1.100 80

This means that you can send instructions by using the IP and desired port.

Example 3 – Connect to UDP Ports with ncat Command

The ncat tool only makes connections to TCP ports. But if you want to make a connection through the UDP port, you can use the -u option. For example:

ncat -l -u 5050

Example 4 – Use ncat as a Chat Tool

At this point, you can configure your AlmaLinux server to a port and make a connection to the server from a remote machine on the same port and start sending messages through the ncat command. For example, from your server run the command below:

ncat -l 8080

Then, from your client machine, run the following command:

ncat 192.168.1.100 8080

Example 5 – Configure ncat as a Proxy

Also, you can use the ncat command as a proxy on AlmaLinux. To do this, you can use the following command:

ncat -l 8080 | ncat 192.168.1.200 80

At this point, all the connections on port 8080 will be automatically redirected to the 192.168.1.200 server on port 80. But if you want to be able to send and receive data back, you should use the command below:

# mkfifo 2way
# ncat -l 8080 0<2way | ncat 192.168.1.200 80 1>2way

Example 6 – Copy Files with ncat Command

You can use ncat to copy files from one system to another system. First, from your machine that is the data receiver run the command below:

ncat -l  8080 > file.txt

Then, from the machine that data is copied from there, run the command below:

ncat 192.168.1.100 8080 --send-only < data.txt

Example 7 – Create a Backdoor with ncat Command

This command tells ncat to listen on a specific port for incoming connections and to display the output and errors in the terminal. 

To create a backdoor, you can use the command below:

ncat -l 10000 -e /bin/bash

Then, from your client’s machine, you can connect to port 10000 on the server:

ncat 192.168.1.100 1000

Example 8 – Port Forwarding with ncat Command

You can use the ncat command to do port forwarding on AlmaLinux. For example:

ncat -u -l  80 -c  'ncat -u -l 8080'

With this command, all the connections for port 80 will be forwarded to port 8080.

Example 9 – Set Timeouts Connections Via ncat Command

As you know the listener mode in ncat will continue. You can configure it manually to set the connection timeouts. For example:

ncat -w 10 192.168.1.100 8080

This will terminate the connection in 10 seconds, but it can only be used on the client side and not on the server side.

Example 10 – Force the Server To Stay Connected with ncat

When a client disconnects from the server after some time server also stops listening. But you can force the server to stay connected and continue port listening with option ‘k’. For example:

ncat -l -k 8080

Conclusion

At this point, you have learned 10 Useful ncat Commands on AlmaLinux with Examples. As you saw, you can use ncat in many cases such as a proxy, chat too, port forwarding and etc. Hope you enjoy it. You may be interested in these articles:

How To Install Zabbix 6.4 on AlmaLinux 9

Install XFCE Desktop Environment on AlmaLinux 9 and RHEL 9

How To Install Java with DNF on AlmaLinux 9

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular