I have an application that connects to several hosts on the same port:a.protected:123b.protected:123I 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 me@x.accessible -L 123:a.protected:123 -NAnd then I would have added a.protected as an alias to localhost, in /etc/hostsBut 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?
Tunnels to the same port number
ssh tunneling
You have two options. Either use different source addresses or use a socks proxy.Different source addressesYour 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:hostportTherefore you can use something like:ssh -L 127.1.0.1:123:a.protected:123 -L 127.1.0.2:123:b.protected:123Now let a.protected resolve to 127.1.0.1:123 and b.protected resolve to 127.1.0.2.Using a socks proxyssh -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.