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. Sep 9 '14 at 13:35
  • 1
    Why not use multiple instances of socat? 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. Sep 9 '14 at 13:53
  • What is the command you use to redirect one port? Sep 9 '14 at 13:55
  • The most basic is something like "socat TCP4-LISTEN:3392,fork TCP4:". 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. Sep 9 '14 at 13:59

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: &'

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

parallel -j N -i bash -c 'socat TCP4-LISTEN:{},fork TCP4:{}' -- 3392 3393 3394


socat TCP-LISTEN:8080,fork TCP:host1:8080|socat TCP-LISTEN:8081,fork TCP:host2:8082

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.