Sha256: 1140dba45e383bebdaf8866a74be570f11efdf30d74f234a589d52c4a7ff9323

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

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.

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
net-ssh-1.0.1 doc/manual/parts/0025.txt
net-ssh-1.0.10 doc/manual/parts/0025.txt
net-ssh-1.0.8 doc/manual/parts/0025.txt
net-ssh-1.0.5 doc/manual/parts/0025.txt
net-ssh-1.0.2 doc/manual/parts/0025.txt
net-ssh-1.0.6 doc/manual/parts/0025.txt
net-ssh-1.0.9 doc/manual/parts/0025.txt
net-ssh-1.0.4 doc/manual/parts/0025.txt
net-ssh-1.0.7 doc/manual/parts/0025.txt
net-ssh-1.0.3 doc/manual/parts/0025.txt
net-ssh-1.1.0 doc/manual/parts/0025.txt
net-ssh-1.1.2 doc/manual/parts/0025.txt
net-ssh-1.1.1 doc/manual/parts/0025.txt
net-ssh-1.1.3 doc/manual/parts/0025.txt
net-ssh-1.1.4 doc/manual/parts/0025.txt