I am writing this Steps to setup SSH tunnel for i had gone through this, when i had to monitor a service status on remote machine. I had a program in my local machine trying to access a remote port number. But unfortunately the port was blocked by the firewall.
This could be solved by using SSH tunneling.
# ssh -f username@remote -L 4668:remote:4557 –N
This command sets the SSH tunnel for accessing port 4557 of remote server from my localhost.
-f: ssh started in background before command is executed.
username: user name for accessing remote server
-L 4668:remote:4667: forward the traffic received at localhost 4668 to remote server at 4557.
Basically, -L [bind_address:]port:host:host port: Tells that the given port on the local (client) host is to be forwarded to the given host and port on the remote side(server).
-N: do not execute a remote command.
Tunnel is established after a successful authentication. After that, I can simply access the remote port by sending traffic to 4668 at localhost.
Check whether the remote 4557 port is open at remote host or not using CLI,
netstat -nan | grep 4557
Test the tunnel set up from local host using telnet,
telnet localhost 4668
If u are able to connect then you have established a successful SSH tunnel