How to Create a Simple Chat with netcat in Linux

Lately, I have been reading a book about Netcat Power Tools and I have picked up new skills that can be used to solve problems in your binary life. I never thought or imagined that such a simple tool can be so powerful until the moment I started practicing it.

What is Netcat?

nc, also known as the TCP/IP swiss army knife is a feature-rich network utility which can be used to read and write data to network connections using TCP or UDP.

What can you do with netcat?

According to the description in the manual page, the nc tool can be used about anything under the sun involving TCP or UDP. You can use it to do port scanning, transfer files, create a listener or stream media. Is this all you can do with netcat? No, but these are the things you guys will learn from our tutorial series for netcat.

In this article, I will explain how to install netcat in your Linux machine and after the installation is completed you will build a simple chat.

How To Install netcat In Ubuntu Linux

sudo apt-get install netcat
install netcat in linux and build a simple chat

Compile netcat From Source

1. Get netcat from the official source.

2. Run the following command to decompress the file.

gunzip netcat-0.7.1.tar.gz
how to install netcat in linux, compile from source

3. Untar the archive.

tar -xf netcat-0.7.1.tar
how to install netcat in linux, compile from source

4. Change directory.

cd netcat-0.7.1 /

5.Type the following command to configure the source code.


6. Compile the program.


7. Install netcat

make install

Create A Simple Chat

To create a simple chat we need two instances of netcat, one to listen for incoming connections (the server) and another one to start the connection.

1. Run netcat with the '-l' option in order to operate in listening mode. You should also specify the listening port, I prefer 1300.

nc -l -p 1300

Then, run another 'netcat' which will initiate the connection by connecting to the server.

nc localhost 1300
how to install netcat in linux, create a simple chat with netcat

Enjoy :-)

how to install netcat in linux, create a simple chat with netcat

Read also

2 Comments... add one

  1. I want to know that by (host: (nc -l -p 6777);join (nc localhost 6777))Command in terminal, can i use it remotely on other device to communicate

    • well nc is insecure, but you can run a listen on one machine, then connect to the ip of the first machine instead of localhost


Leave a Comment