Posted By

drewr on 02/19/07


Tagged

port forwarding socat


Versions (?)

Who likes this?

1 person have 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.