What is the difference in functionality between the two? I'm a bit confused by it.

Local forwarding makes a remote port locally available.

Remote forwarding makes a local port remotely available.

But this 'availability' will work in both directions... ordoes it?.

E.g. the following (issued from a host 'home')

ssh -R 1234:localhost:2345 user@work

This will establish a secure tunnel between work::1234 and home::2345, right?

If I put in anything on one end it will come out on the other end.

But then, I can achieve the same by the following call from the host 'work':

ssh -L 1234:localhost:2345 user@home

So, the only difference is the where I call it from, correct?

link|improve this question
In your example there is no difference in functionality. You sort-of self-compensate for using the opposite argument by interchanging target hosts. Had you not done this and used both of them from within 1 single host - it would already trigger a completely opposite behavior. – XXL Nov 2 '11 at 18:28
feedback

migrated from stackoverflow.com Nov 2 '11 at 16:25

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote -2 down vote accepted

The major practical difference, is that if connecting 2 computers A and B, and B is behind a firewall or NAT Router that you don't control, and it's blocking incoming.. You're sitting at A. You can't get A to connect to B. But B won't block outgoing.. So you get B to connect to A.

--added clarification--

The above, which the questioner understood.. means the major practical difference between local and remote forwarding. ssh -L and ssh -R when you'd use each. I wasn't commenting on the specific example commands he gave, where he switches -L and -R, and which sshd server he connects to. But now I will attempt to comment on it.. With the ssh commands he gave, from the perspective of the regular client and regular server, there appears to be no difference,as it doesn't say "ah this is an ssh client and this is an ssh server.." it doesn't know ssh , and which is the client/server aspect of ssh is irrelevant and unknown to the regular client and regular server too. They just care about who is listening, and from their perspective, it looks the same. The work computer is listening and on 1234. They don't notice that in one case it's an sshd.exe ssh server, and in the other case it's an ssh.exe, ssh client. By the way, where the ssh client is, is considered local.

link|improve this answer
ok, thank you, that exactly answered my question! :-) – nandaloo Nov 4 '11 at 0:50
@nandaloo I think it's called a reverse ssh tunnel. If we use made up terms initiator and listener ('cos those terms are less ambiguous than client and server). The idea is that you have your regular initiator and listener and your ssh initiator and listener. You can't choose where your regular initiator and listener are. e.g. HTTP server(regular listener) is on B. B is behind a firewall. A has the HTTP client(regular initiator). You put your SSH initiator on B. See with a reverse tunnel the SSH initiator and listener, are on opposite computers to the regular initiator and listener. – barlop Nov 4 '11 at 1:15
feedback

With local port forwarding you (the client) open a listening socket on your computer and connect your application-level protocol client to this socket. Now the connection is forwarded over SSH to the server. The server connects to the remote host and tunnels the data from your protocol client to the final destination.

With remote port forwarding the server opens a listening socket on the server host. Some remote application connects to this host and sends information which is transferred to your client computer. Here the connection is established to the final destination (some application-level protocol server running on your computer or on your network) and the data is transferred from remote application to the final destination.

link|improve this answer
thanks, that made it clearer how port forwarding works. And thanks for moving the question - I just didn't even know about this superuser site :-) – nandaloo Nov 4 '11 at 0:49
feedback

Your Answer

 
or
required, but never shown

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