In short, you can issue this command from your terminal to do ssh tunneling:
$ ssh -f -N -L 8081:127.0.0.1:3000 username@hostname.com
"-f" is to requests ssh to go to background just before command execution.
"-N" tells SSH client not to execute a remote command.
"-L [bind_address:]port:host:hostport" is to specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
For convenience, we will setup a profile in ~/.ssh/config:
Host nickname
HostName 123.123.123.123
User username
Port 2222
LocalForward 8000 127.0.0.1:80
With this setting, when you issue "ssh nickname", you are actually doing
ssh -p 2222 -L 8000:127.0.0.1:80 username@123.123.123.123
Then we can add an alias in our .bashrc file:
alias tun="ssh -f -N "
With this alias in place, when we do
tun nickname
We are actually doing
ssh -f -N -p 2222 -L 8000:127.0.0.1:80 username@123.123.123.123