Forwarding a local connection to a remote destination is simply a matter of invoking the @#local@ method of the @#forward@ service. The simplest version of the method just takes three parameters: the local port to listen on, and the remote host and port to forward the connection to:

{{{lang=ruby,number=true,caption=Forwarding a local port
Net::SSH.start( 'host' ) do |session|
  session.forward.local( 1234, 'www.google.com', 80 )
  session.loop
end
}}}

In the above example, then, any connection received on port 1234 will be forwarded to port 80 on "www.google.com". This means that if you were to point a browser at "http://localhost:1234", it would pull up "Google":http://www.google.com.

By default, only connections _from the local host_ are accepted. This is because the default bind address is 127.0.0.1. You can specify any bind address you want (including 0.0.0.0 to allow connections from anywhere) by specifying that address as the first parameter to @#local@, with the local port number immediately following.

{{{lang=ruby,caption=Specifying the bind address when forwarding a local port
session.forward.local( '0.0.0.0', 1234, 'www.google.com', 80 )
}}}

In this configuration, anyone from anywhere can connect to your machine on port 1234 and be forwarded to Google.
