2

I want to forward Microsoft Remote Desktop on a Linux Server, assume that the remote Windows host is 192.168.1.100, I want to run:

socat TCP4-LISTEN:3389,fork TCP4:192.168.1.100:3389
socat UDP4-LISTEN:3389,fork UDP4:192.168.1.100:3389

It works fine when I start the service by hand in the shell, but I want to start it with systemd, and log into /var/log/socat-rdp.log.

After some trials I can run the service like this:

[Unit]
Description=Socat RDP Forwarding Service
After=network.target

[Service]
Type=forking
User=root
ExecStart=/bin/sh -c "/usr/bin/socat TCP4-LISTEN:3389,fork TCP4:192.168.3.153:3389 > /var/log/socat-rdp.log 2>&1 & /usr/bin/socat UDP4-LISTEN:3389,fork UDP4:192.168.3.153:3389 > /var/log/socat-rdp.log 2>&1 &"
ExecStop=/bin/kill $MAINPID

[Install]
WantedBy=multi-user.target

This configuration starts and runs normally, but when I stop the service with systemctl stop socat-rdp it returns error code 1, although socat process is killed as normal.

Are there any better solutions?

1
  • Why not create a shell script?
    – balki
    Commented May 10, 2023 at 14:58

2 Answers 2

0

I have found an alternative solution to address the issue of running multiple socat instances and forwarding both TCP and UDP traffic. Instead of using systemd to manage the service, I have utilized Docker to achieve the desired outcome.

I found an Docker image alpine/socat, and use Docker Compose to run two socat instances for both TCP and UDP at the same time. Here's my Docker Compose file:

---
services:
  socat_rdp_tcp:
    image: alpine/socat
    container_name: socat_rdp_tcp
    command: "TCP-LISTEN:3389,fork TCP:192.168.1.100:3389"
    ports:
      - 3389:3389

  socat_rdp_udp:
    image: alpine/socat
    container_name: socat_rdp_udp
    command: "UDP-LISTEN:3389,fork UDP:192.168.1.100:3389"
    ports:
      - 3389:3389/udp

Docker image: alpine/socat

0

when you run socat command directly in terminal and kill them (maybe killall socat ?) the given code is Exit 143? The easiest dirtyhack is use SuccessExitStatus=143 under [Service].

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .