nc

Linux nc command to create chat room

The process of creating an online chat between two or more hosts is the same as when transferring files

2 min read
By myfreax
Linux nc command to create chat room
linux-nc-command-to-create-chat-room

Netcat or nc is a command-line program that reads and writes data over a network connection using the TCP or UDP protocol.

It is one of the most powerful tools among network and system administrators and is considered the swiss army knife of network tools.

Netcat is a cross-platform tool available for Linux, macOS, Windows and BSD. You can use Netcat to debug and monitor network connections, scan for open ports, transfer data, act as a proxy, and more.

Netcat packages are pre-installed on MacOS and popular Linux distributions such as Ubuntu, Debian, CentOS, Fedora, etc.

Netcat command

The basic syntax form of the Netcat command is   nc [options] host port. hostCan be the domain name of the remote host. Hostname or IP address.  options is an option of the nc command, and is an optional parameter.

In Ubuntu, you can run the command netcat or nc.  These are symbolic links to the OpenBSD version of Netcat .

By default, Netcat will attempt to establish a TCP connection to the specified host. If you want to establish a UDP connection, specify -uoptions .

nc host port #tcp
nc -u host port #udp

Create live chat

The process of creating an online chat between two or more hosts is the same as when transferring files. But that doesn't mean you can also send files, because there is no interface to choose files.

First run the command nc -l 5555 on the first host to set Netcat to listen on port 5555, and then run the command nc first.host.com 5555 on the second host to connect to port 5555 of the first host.

Here first.host.com is the domain name of the host where you run the command nc -l 5555, of course you can specify the IP or host name as the address.

Now, if you type a message and press  ENTER, it will appear on both hosts. To close the connection, type CTRL+C.

nc -l 5555 
nc first.host.com 5555

Conclusion

So far, you already know how to run the nc command in Linux to establish a TCP connection and send messages. If you have any questions or comments, please leave a comment below.

Related Articles