How to chat using the linux terminal like a pro in 3 simple steps

In this tutorial we will learn how to chat over the Linux terminal, one of the coolest things to do over the terminal.

The netcat utility, abbreviated as nc, is a network utility used for managing UDP/TCP connections and UNIX-domain sockets.

Netcat can perform a number of tasks including the following.

  • Listening for connections.
  • Creating connections
  • Send UDP packets.
  • Port scanning.

Netcat utility can work with both IPV4 and IPV6, you can issue the -4 flag to tell netcat to use IPV4 and -6 flag for IPV6. By default it uses IPV4.

STEP 1: Installing netcat in Linux.

sudo apt-get install netcat

STEP 2: Prerequisites

You will first need two devices in the same network, this could be your PC and your friends PC both connected to the same Local Area Network or any other 2 devices with nc utility running.(You can use a virtual machine as well).

STEP 3: Creating the Actual Chat

One of your 2 devices will act as the server, while the other one will be the client. The next step is to get the IP address of your device that is acting as the server. In ubuntu linux you can use the ifconfig command, while in windows you can use the ipconfig command.

The following screenshot shows the result of running the ifconfig command on my device that is acting as the server. My local IP address is 172.28.128.6

inet

The next step is to listen for incoming connections on your server device, we will do this using the following command.

nc -lnvp 2770

nc command options explanations

  • -l Listen for an incoming connection.
  • -v Produce more verbose output.
  • p Set the port to listen at.
  • n Do not perform DNS lookup.
nclisten

On the other device(The client machine), We will use the IP address we obtained earlier from the device acting as the server, to connect to the device.

nc 172.28.128.6 2770

This command tells netcat to connect to the host 172.28.128.6 at port number 2770.

connect

Our two devices are now connected, Let us chat!

The following screenshot shows my two terminal windows and the sample chat.

chat

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x