SSH the Definite Guide says

Suppose you want to forward a connection from your local machine to remote.host.net. Both of the following commands work:

$ ssh -L2001:localhost:143 remote.host.net
$ ssh -L2001:remote.host.net:143 remote.host.net

The forwarded connection is made from the remote machine to either the loopback address or remote.host.net, and in either case, the connection stays on the remote machine and doesn’t go over the network. However, the two connections are perceptibly different to the server receiving the forwarded connection. This is because the source sockets of the connections are different. The connection to localhost appears to come from source address, whereas the connection to remote.host.net is from the address associated with that name.

What is "the address associated with that name"?

How is it different from "source address"?


  • that's a lousy description; when ssh is using the -L lport:rhost:rport option and receives a connection request of lport, it's the ssh on the remove machine which does the lookup for rhost, and there remote.host.net could be configured to return the same ip address as localhost, or none at all.
    – mosvy
    Feb 6 '19 at 2:56

Let's ignore ssh for the moment, and do something more simple.

If you do

telnet localhost 143

then the connection is made from localhost to localhost

If, instead, you do

telnet my.ip.address 143

then the connection is made from my.ip.address to my.ip.address

In both cases we're connecting to port 143 on the same machine, but the source address changes. So we can see that the target IP address changes the source IP address.

The same is true for ssh port forwarding.

With the first version you are making a connect to localhost and so the source is localhost. With the second version you are making a connection to the server's main IP address (remote.host.net's IP address), and so the source is from that IP address.

This isn't an ssh specific issue; it's how IP routing typically works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.