Suppose you have a service listening on port x, but unfortunately you can only connect to port y (probably because of some proxy or firewalls). You want to connect port y to port x so that a connection to port y gets redirected to port x. Right.
The proper way to do that is probably iptables, but it means you need to be root, you need to have uptables installed and working, you need to know how to use it.
Let's just do it with netcat then. We'll create a small script that connects to port x, then a netcat that listens to port y.
cat > redirThe 'while' is necessary because nc dies after each socket closing. Obviously you can also use this to connect to a different machine.
#! /bin/sh
nc localhost x
^D
chmod 755 redir
while true; do nc -l -p y -e ./redir ; done