There may be times when you need to communicate with another Ubuntu server on your network without using a graphical interface. One way to accomplish this is by using the command-line interface and a tool called “Netcat” or “nc”. In this blog, we will show you how to chat between two Ubuntu servers via terminal using Netcat.
Step 1: Install Netcat
Netcat is a command-line tool used for reading and writing data across network connections. It can be installed on Ubuntu by running the following command:
sudo apt-get install netcat
Step 2: Open a Listening Port on the Receiving Server
To receive messages from the other server, we need to open a listening port. This can be done using the following command:
nc -l <port_number>
Replace <port_number> with the port number you want to use for communication. For example:
nc -l 5000
This will open a listening port on the receiving server at port number 5000.
Step 3: Connect to the Receiving Server from the Sending Server
To send messages to the receiving server, we need to connect to the listening port using the following command:
nc <ip_address> <port_number>
Replace <ip_address> with the IP address of the receiving server and <port_number> with the port number you used to open the listening port. For example:
nc 192.168.1.100 5000
This will connect to the listening port on the receiving server at IP address 192.168.1.100 and port number 5000.
Step 4: Start Chatting
Once you have connected to the receiving server, you can start typing messages. Any messages you type will be sent to the receiving server, which will display them on the screen. Likewise, any messages received by the receiving server will be displayed on the screen.
To exit the chat, simply type “exit” and press enter. This will close the connection.
Conclusion
Chatting between two Ubuntu servers via terminal using Netcat is a quick and easy way to communicate with another server on your network without using a graphical interface. By following these steps, you can open a listening port on the receiving server and connect to it from the sending server to start chatting.