You need to use the Bind Address option of ssh:
-L [bind_address:]port:host:hostport
Specifies that the given port on the local (client) host
is to be forwarded to the given host and port on the
remote side. This works by allocating a socket to lis‐
ten to port on the local side, optionally bound to the
specified bind_address. Whenever a connection is made
to this port, the connection is forwarded over the
secure channel, and a connection is made to host port
hostport from the remote machine. Port forwardings can
also be specified in the configuration file. IPv6
addresses can be specified by enclosing the address in
square brackets. Only the superuser can forward privi‐
leged ports. By default, the local port is bound in
accordance with the GatewayPorts setting. However, an
explicit bind_address may be used to bind the connection
to a specific address. The bind_address of “localhost”
indicates that the listening port be bound for local use
only, while an empty address or ‘*’ indicates that the
port should be available from all interfaces.
So, for example, to bind local port 1234 to port 6667 of the remote server server.example.com, you would do something like this:
ssh -f -L 1234:localhost:6667 server.example.com
just curious, doesn't "bash" imply "linux" and isn't it also more specific? – Eva – 2012-12-06T17:26:06.683
No, BASH could be OSX, UNIX or a number of other OSs and in any case your question is about ssh port forwarding and so has nothing to do with BASH which is a shell.
– terdon – 2012-12-06T17:30:13.633I see, but wouldn't the command also work on OSX or Unix? Or do they not have the "ssh" command in bash? (I ask because my question is specifically about ssh / port-forwarding with bash and not with a GUI such as something like Tunnelier) – Eva – 2012-12-06T17:36:44.837
The
ssh
command is not connected to BASH in any way. In most Linuxes it is part of theopenSSH
package. You can run it using any of a number of shells (BASH,tcsh, zsh whatever) but it is not a part of any of them. That is why I removed the BASH tag, it was misleading since your question is not in any way dependent on BASH. – terdon – 2012-12-06T17:40:13.263Ah OK - thanks for clearing that up for me :) – Eva – 2012-12-06T17:41:08.393