We Recommend

bash Cookbook: Solutions and Examples for bash Users bash Cookbook: Solutions and Examples for bash Users
bash Cookbook teaches shell scripting the way Unix masters practice the craft. It presents a variety of recipes and tricks for all levels of shell programmers so that anyone can become a proficient user of the most common Unix shell -- the bash shell -- and cygwin or other popular Unix emulation packages.


Posted By

drewr on 02/19/07


Tagged

port forwarding socat


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

xenonite


Easy port forwarding


Published in: Bash 


Need to forward a port through SSH, but you don't have shell access to the box? If you have access to another box that can get to the desired port, use this script. You need socat (http://www.dest-unreach.org/socat/).

./script-name 10000 other-host 10001

  1. #!/bin/sh
  2.  
  3. LOCALPORT=$1
  4. REMOTEHOST=$2
  5. REMOTEPORT=$3
  6.  
  7. socat -d -d -lmlocal2 \
  8. TCP4-LISTEN:${LOCALPORT},fork,range=127.0.0.1/0,reuseaddr \
  9. TCP4:${REMOTEHOST}:${REMOTEPORT}

Report this snippet 

You need to login to post a comment.