2

I would like to use socat to redirect some ports and I found a socat daemon here. However this daemon lacks documentation and I could only setup for one port redirect. Is there any syntax to make socat or this daemon (or another daemon) to setup multiple individual ports redirecting?

Edit 1: A possible solution found here.

  • Use sudo apt-get install socat to install socat including man pages. – Volker Siegel Sep 9 '14 at 13:35
  • 1
    Why not use multiple instances of socat? – Volker Siegel Sep 9 '14 at 13:41
  • socat is not a damon, I will have to write one daemon per port as the socat accepts only one redirect per command. – Max Bündchen Sep 9 '14 at 13:53
  • What is the command you use to redirect one port? – Volker Siegel Sep 9 '14 at 13:55
  • The most basic is something like "socat TCP4-LISTEN:3392,fork TCP4:192.168.10.102:3389". It runs until you close by Ctrl+C or something like. I can't setup more than one redirects in one single line. The solution is setup a daemon for each socat redirect, but the script I found didn't make it and only works for one redirect. – Max Bündchen Sep 9 '14 at 13:59
3

Run multiple instances in background

You could run multiple instances of socat in the background in one command.

I use sleep N instead of socat ...N... ...N... for an example:

echo -n 1 2 3 | xargs -d ' ' -I% bash -c '(sleep % ; echo slept % ) &'

The () and the echo slept % part is only needed to have some example output, so your actual command would be simpler; % will be replaced by one of the port listed after echo:

echo -n 3392 3393 3394 | xargs -d ' ' -I% bash -c 'socat TCP4-LISTEN:%,fork TCP4:192.168.10.102:% &'

Wit the count of port args N, this should also work:

parallel -j N -i bash -c 'socat TCP4-LISTEN:{},fork TCP4:192.168.10.102:{}' -- 3392 3393 3394
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.