Skip to content

Instantly share code, notes, and snippets.

@henri
Last active November 27, 2023 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henri/56d424d6f22caf30e602550b43cff01e to your computer and use it in GitHub Desktop.
Save henri/56d424d6f22caf30e602550b43cff01e to your computer and use it in GitHub Desktop.
socat cheat sheet
# this example sets up a tunnel on the remote system on port 8090 to the system initiating the ssh connection on port 8080
#
# starting socat ipv4 tunnel between ports on remote system (forking and lock file enabled with socat)
# and killing socat with control-c / tunnel close
#
# tags : proxy port
# most direct approach
ssh -t user@remote.system -R 8080:127.0.0.1:8080 "socat -L/tmp/socat.lock tcp4-listen:8090,reuseaddr,fork tcp:localhost:8080"
# more complex
ssh -t user@remote.system -R 8080:127.0.0.1:8080 "(socat -L/tmp/socat.lock tcp4-listen:8090,reuseaddr,fork tcp:localhost:8080 & ) 2> /dev/null ; sleep infinity"
# more compatible
ssh -t user@remote.system -R 8080:127.0.0.1:8080 "(socat -L/tmp/socat.lock tcp4-listen:8090,reuseaddr,fork tcp:localhost:8080 & ) 2> /dev/null ; trap 'exit 0' SIGINT ; while true ; do sleep 100 ; done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment