3

I have an application that connects to several hosts on the same port:

a.protected:123
b.protected:123

I don't have direct access to either of them, but I can make a ssh tunnel (through x.accessible).

Should the ports have been distinct, I could have make the tunnel to the same port number:

ssh -f [email protected] -L 123:a.protected:123 -N

And then I would have added a.protected as an alias to localhost, in /etc/hosts

But given that more hosts use the same port number, what are my options? How can I use tunnels to get the application to connect to them, without changing the application?

2 Answers 2

8

You have two options. Either use different source addresses or use a socks proxy.

Different source addresses

Your lo interface is configured as 127.0.0.1/8, i.e. all addresses starting with 127 do belong to the current host.

The syntax for your tunnel is

-L [bind_address:] port:host:hostport

Therefore you can use something like:

ssh -L 127.1.0.1:123:a.protected:123 -L 127.1.0.2:123:b.protected:123

Now let a.protected resolve to 127.1.0.1:123 and b.protected resolve to 127.1.0.2.

Using a socks proxy

ssh -D 1080 

This will start a local socks proxy on port 1080. All connection will resolve and connect on the other end of the tunnel.

If you application supports socks proxies just configure it. Otherwise you can use tsocks to use the proxy anyway.

0

There is no easy and transparent way to use one port for two connections simultaneously.

From my point easy and right way is to create tunnels on different local ports:

ssh -f [email protected] -L 123:a.protected:123 -N
ssh -f [email protected] -L 123:a.protected:124 -N

So the first connection will be available via port 123 and the second one vie port 124.

ps. remember, that you need a root permissions to use port under 1024.

You must log in to answer this question.