Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|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
add comment

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

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

3 Answers

up vote 0 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.

share|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
add comment

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.

share|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
add comment

Yes, if I understand it correctly, local port forwarding from a to b should be identical to remote port forwarding from b to a (and vice versa). An outgoing tunnel from a to b (viewed from a) should be equal to an incoming tunnel from a to b (viewed from b).

Local port forwarding creates an outgoing tunnel which can be used to bring a public internet computer to local machine. A local user can access a remote host:port combination on a local host, because the given port on the local (client) host is forwarded to the given host and port on the remote side:

ssh -L local_port:remote_host:remote_port user@hostname

Remote port forwarding creates an incoming tunnel which can be used to bring a local computer into the public internet. An internet user can access a certain local host:port combination on a remote host. The given port on the remote (server) host is forwarded to the given host and port on the local side:

ssh -R local_port:remote_host:remote_port user@hostname
share|improve this answer
    
I suppose another difference, besides the syntax, would be the process that listens for the user to connect. ssh.exe -L tells ssh.exe to listen(besides the outgoing connection it's already making). ssh.exe -R tells sshd.exe to listen(besides the listening it's already doing). –  barlop Jun 7 '13 at 19:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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