It's not clear to me what your (mis)understanding really is. I guess the confusion might be because of the word "localhost".
Localhost is a relative term. By definition, in context of any machine localhost
should refer to this machine exactly. Practically every Linux resolves localhost
as IP address 127.0.0.1
(I put IPv6 aside) thanks to a proper entry in /etc/hosts
file. 127.0.0.1
should be assigned to a loopback interface.
In the linked answer most occurrences of the word localhost
refer to the machine (of three) that is neither host1
nor host2
; this is the local machine where commands are invoked. Similarly, when you say "localhost" you probably mean neither A
nor B
. From now on let's call this local computer the client.
Basically you run this on the client:
ssh -L bind_address:port:host:hostport user@server
There are two computers involved: the client and the server. Certain parts of the command are valid in context of either the client or the server.
ssh -L
is the executable with option that the client understands (the server may not have ssh
at all).
server
is the address of the server from the client's point of view (server may not even be aware it has such-and-such address or name).
user
is a username existing on the server (it may not exist on the client).
bind_address
and port
are respectively the address (interface) and TCP port on which the client's ssh
will listen (I don't know if these parameters are even passed to the server at all, the server doesn't need them). In your case 0.0.0.0
means "every available interface".
host
and hostport
are respectively the address and TCP port to which the server should send packets tunneled from the client. These parameters are for the server; host
is resolved on the server. From the client's point of view host
may be an invalid address or it may resolve to something completely different – it doesn't matter because the client doesn't resolve it at all; host
is just a character string passed to the server, it means nothing more on the client's side.
This means if there's a literal localhost
as this host
parameter, it is "localhost" from the server's point of view, i.e. the server itself. It doesn't mean "the client".
With this knowledge let's analyze your examples.
ssh -L 0.0.0.0:10022:localhost:22 root@A
This captures everything that enters the TCP port 10022
of the client; captured packets will be recreated on the server A
and destined to localhost:22
, but localhost
on the server means "the loopback interface of the server A
itself".
ssh -L 0.0.0.0:10022:A:22 root@B
This captures everything that enters the TCP port 10022
of the client; captured packets will be recreated on the server B
and destined to A:22
from there.
Indeed it can be described as "localhost to A though B", where "localhost" means the client.
a)bind address is not described as a host and cant be a host if it is 0.0.0.0 cos a host cant have that ip. b)And that snippet from the man, is showing what options that can be passed that relate to the -L, that is why it is not showing the destination host. You would still have a destination host. – barlop – 2018-01-13T01:09:07.030