Advertisements

How To Install Socat on Linux Server

  • Post last modified:October 19, 2023
  • Post category:Linux
  • Post comments:0 Comments
  • Reading time:7 mins read

Socat, short for “SOcket CAT,” is a tool that creates connections between different data streams. In this post, we talk about what Socat is and provide a step-by-step guide to install it on a Linux Server.

Table of Contents:

What is Socat?

Socat is a tool use on command line. it helps you move data back and forth between two different places, it can handle all sorts of data, like stuff over the internet (TCP and UDP), stuff on your own computer (UNIX sockets), and even stuff from hardware like serial ports. Think of it as an upgraded version of the classic netcat tool, with extra features and options to make your life easier.

Install Socat on Linux Server

To install Socat on your Linux server, you can follow the steps below.

Update Package Manager (Debian/Ubuntu):

sudo apt update

Advertisements

(CentOS/RHEL):

sudo yum update

Install Socat (Debian/Ubuntu):

sudo apt install socat

(CentOS/RHEL):

sudo yum install socat

Usage of Socat

Socat’s allows you to perform tasks related to network communication. Below are some common use cases to get you started.

TCP/UDP Port Forwarding

Socat can forward data between different ports on the same or remote systems. The following example shows TCP port forwarding:

# Syntax: socat TCP-LISTEN:<LocalPort>,fork TCP:<DestinationHost>:<DestinationPort>
sudo socat TCP-LISTEN:8080,fork TCP:example.com:80

Proxying

Socat can act as a proxy server to forward requests to a destination server. For instance, you can use it as an HTTP proxy:

# Syntax: socat TCP-LISTEN:<LocalPort>,fork PROXY:<DestinationHost>:<DestinationPort>
sudo socat TCP-LISTEN:8888,fork PROXY:example.com:80

UDP Forwarding to a Teamspeak Server

In this example, we’ll set up UDP forwarding to a Teamspeak server using Socat. Teamspeak is a popular voice communication software used by gamers and other online communities.

Create a systemd service file for the Teamspeak UDP forwarding. Open a terminal and create the file teamspeak-udp.service:

sudo nano /etc/systemd/system/teamspeak-udp.service

Add the following content to the service file:

[Unit]
Description=Teamspeak UDP
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/socat UDP-LISTEN:9987,fork UDP:your_teamspeak_server_ip:9987
Restart=on-failure

[Install]
WantedBy=multi-user.target

Replace your_teamspeak_server_ip with the actual IP address of your Teamspeak server.

Save the file (Ctrl + O in nano) and exit (Ctrl + X in nano).

Enable and start the service:

sudo systemctl enable teamspeak-udp
sudo systemctl start teamspeak-udp

Socat will listen on UDP port 9987 on your Linux Server and forward any incoming UDP traffic to the Teamspeak server IP on port 9987. This setup allows your Server to act as a relay for the Teamspeak traffic.

Advertisements

With this setup, your UDP forwarding to the Teamspeak server will run in the background and automatically restart in case of a failure or system reboot.

Please note that when using this setup, you need to make sure that the Teamspeak server is configured to accept incoming UDP traffic on port 9987 and that any firewalls or security groups allow the traffic between your Server and the Teamspeak server.

Conclusion

Socat is a powerful networking tool that provides capabilities for data communication. If you have any questions or need further clarification on the topic of Socat, feel free to leave a comment below.

Leave a Reply