-D [bind_address:]port

Specifies a local ``dynamic’’ application-level port forwarding. ssh will act as a SOCKS server.

example:

    sudo ssh -D 7777 parallels@172.20.10.2 -p 22

Allocate a socket to listen to port 7777 on the local side. Whenever a connection is made to this port, the connection is forwarded over the secure channel ( 172.20.10.2:22 ).

note:

  • 172.20.10.2 need to install OpenSSH server to enable SSH connection.

      sudo apt-get install openssh-server
    
  • edit /etc/ssh/sshd_config to open port (22 is default).

      Port 22
      Port 443
    
  • /etc/init.d/ssh start

       * Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}
    
  • list listening ports

    Ubuntu:

      netstat --inet -ln
    

    MacOS

      netstat -ap tcp
      lsof -i
    

-L [bind_address:]port:host:hostport

Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.

example:

ssh -L 9999:192.168.2.8:8080 mini@192.168.2.3

This works by allocating a socket to listen to port(9999) on the local side, optionally bound to the specified bind_address(192.168.2.8:8080).

note:

  • bind port to local virtual machine

      ssh -L 9999:localhost:8080 mini@192.168.2.3