4

I just learned the basics of SSH tunneling from googling.

I saw this interesting question: How does reverse SSH tunneling work?

But I still find it a bit confusing, more specifically on the [email protected] part.

So on one of the answers, there are 4 use cases. Here's how I understand them. Please correct me if I'm wrong. For simplicity, I'll assume I'm running the ssh commands on my local machine.

  1. ssh -L 123:localhost:456 [email protected]

    • This will forward all traffic from port 123 on my local machine to port 456 on example.com. But example.com would see the traffic coming from its own localhost.
  2. ssh -L 123:google.com:456 [email protected]

    • This will forward all traffic from port 123 on my local machine to port 456 on google.com. After that it will establish an ssh session to example.com. This doesn't make sense to me, why do we need [email protected] in this case?
  3. ssh -R 123:localhost:456 [email protected]

    • This will establish an ssh session to [email protected] and forward all traffic from port 123 on example.com to port 456 on my local machine. My local machine will then see the traffic as coming from localhost.
  4. ssh -R 123:google.com:456 [email protected]

    • This will establish an ssh session to [email protected] and forward all traffic from port 123 on example.com to port 456 on google.com. Unlike #2, example.com is used as the remote host.

So my question is: Why do we need [email protected] on #2? And did I get anything wrong?

UPDATE

Ok, I think I get it now. I have misunderstood about the [email protected] part and thought it was optional. It seems the ssh session is being established first, then the port:host:port is evaluated afterwards.

eg: For #2, it would establish the session to example.com first then forward traffic to google.com:456. For #1, it would establish the session to example.com first then forward traffic to localhost:456 (which is the same host)

1
  • 1
    Cant tell you enough, but this question alone has made me understand so much about the Port forwarding in general than entire time I spent on wikipedia page and ubuntu documentation. What an excellent question, its the definition of a good question for me Commented Sep 11, 2019 at 12:08

1 Answer 1

4

Second case is very useful in situation when example.com can connect to [google.com] host while your box can't. For example, you have VPN connection which is restricted to a number of boxes, while you want to access host not in list. ssh -L 123:target.host.com:456 [email protected].

So, basic usage is to jump INSIDE the network or jump OUTSIDE the network (ssh to some kind of proxy/gateway).

And finally, there may be firewall restrictions on target server which accepts connections only from given hosts.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .