El blog de Juan Palómez

19 octubre 2017

Listen twice on the same TCP port and on the same host

Filed under: networking, ssh — thisisoneball @ 12:40


Let’s say an application connects to a host:port and does its thing. The host is configurable but not the port, it always connects to port 9991.
Also, you can’t connect directly to the destination hosts, but you can SSH to an intermediate host and create SSH tunnels, and then point the application to localhost instead of the real destination host:

L9991 ->

L9992 ->

Pointing the application to localhost:9991 will make it reach the first destination host, and pointing it to localhost:9992 will make it reach the other one. But the port is not configurable in this application, so it can’t use the second tunnel.
In this case you can use several of the multiple localhost addresses (, and listen on the same port on all of them

L127.0.0.1:9991 ->

L127.0.0.2:9991 ->

And then point the application to or
The listening program in this case would be Putty or ssh.exe, but it should work with any other program that supports specifying the IP address and port where to listen for connections. For example this is the way to specify it in Netcat:

nc -l 9991

nc -l 9991

Blog de WordPress.com.