[linux notes] to bind remote port as local port through ssh tunnel
Here is an example to demonstrate binding remote port as local port through ssh tunnel. I would like to connect port number 5902 of remote host (e.g. foo.bar.com) to local port 5901. So, the command will be something like following:
ssh -fN -L 5901:localhost:5902 foo.bar.com
If I would like to connect a machine behind firewall, I also can use this command redirect to another machine. For example, I have a gate server. The host name is gate.bar.com. I also have a machine behind firewall. The host name is foo.bar.com. I would like to connect the port number 5902 of foo.bar.com machine. I can use the following command:
ssh -fN -L 5901:foo.bar.com:5902 gate.bar.com